mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: danmaku (#1696)
* fix: post danmaku * mod: tap danmaku * mod: delete danmaku
This commit is contained in:
committed by
GitHub
parent
63030147ea
commit
08944241bb
@@ -1,11 +1,12 @@
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/danmaku/post.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
abstract final class DanmakuHttp {
|
||||
static Future shootDanmaku({
|
||||
static Future<LoadingState<DanmakuPost>> shootDanmaku({
|
||||
int type = 1, //弹幕类选择(1:视频弹幕 2:漫画弹幕)
|
||||
required int oid, // 视频cid
|
||||
required String msg, //弹幕文本(长度小于 100 字符)
|
||||
@@ -46,27 +47,16 @@ abstract final class DanmakuHttp {
|
||||
// 'access_key': access_key,
|
||||
};
|
||||
|
||||
var response = await Request().post(
|
||||
final res = await Request().post(
|
||||
Api.shootDanmaku,
|
||||
data: data,
|
||||
options: Options(contentType: Headers.formUrlEncodedContentType),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': '弹幕发送失败,状态码:${response.statusCode}',
|
||||
};
|
||||
}
|
||||
if (response.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': response.data['data'],
|
||||
};
|
||||
|
||||
if (res.data['code'] == 0) {
|
||||
return Success(DanmakuPost.fromJson(res.data['data']));
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': "${response.data['code']}: ${response.data['message']}",
|
||||
};
|
||||
return Error(res.data['message'], code: res.data['code']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
lib/models_new/danmaku/post.dart
Normal file
31
lib/models_new/danmaku/post.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
class DanmakuPost {
|
||||
DanmakuPost({
|
||||
required this.action,
|
||||
required this.animation,
|
||||
required this.colorfulSrc,
|
||||
required this.dmContent,
|
||||
required this.dmid,
|
||||
required this.dmidStr,
|
||||
required this.visible,
|
||||
});
|
||||
|
||||
final String? action;
|
||||
final String? animation;
|
||||
final dynamic colorfulSrc;
|
||||
final String? dmContent;
|
||||
final int? dmid;
|
||||
final String? dmidStr;
|
||||
final bool? visible;
|
||||
|
||||
factory DanmakuPost.fromJson(Map<String, dynamic> json) {
|
||||
return DanmakuPost(
|
||||
action: json["action"],
|
||||
animation: json["animation"],
|
||||
colorfulSrc: json["colorful_src"],
|
||||
dmContent: json["dm_content"],
|
||||
dmid: json["dmid"],
|
||||
dmidStr: json["dmid_str"],
|
||||
visible: json["visible"],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/view_safe_area.dart';
|
||||
import 'package:PiliPlus/http/danmaku.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/publish_panel_type.dart';
|
||||
import 'package:PiliPlus/pages/common/publish/common_text_pub_page.dart';
|
||||
@@ -454,12 +455,12 @@ class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
|
||||
colorful: isColorful,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (res['status']) {
|
||||
if (res case Success(:final response)) {
|
||||
hasPub = true;
|
||||
Get.back();
|
||||
SmartDialog.showToast('发送成功');
|
||||
VideoDanmaku? extra;
|
||||
if (res['dmid'] case int dmid) {
|
||||
if (response.dmid case final dmid?) {
|
||||
extra = VideoDanmaku(
|
||||
id: dmid,
|
||||
mid: PlPlayerController.instance!.midHash,
|
||||
@@ -480,7 +481,7 @@ class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast('发送失败: ${res['msg']}');
|
||||
res.toast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2102,7 +2102,7 @@ class HeaderControlState extends State<HeaderControl> {
|
||||
onPressed: () => HeaderControl.deleteDanmaku(
|
||||
extra.id,
|
||||
plPlayerController.cid!,
|
||||
),
|
||||
).then((_) => item.expired = true),
|
||||
icon: const Icon(CustomIcons.player_dm_tip_recall),
|
||||
)
|
||||
else
|
||||
|
||||
@@ -1140,8 +1140,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
default:
|
||||
if (_suspendedDm == null) {
|
||||
plPlayerController.controls = !plPlayerController.showControls.value;
|
||||
} else {
|
||||
} else if (_suspendedDm!.suspend) {
|
||||
_dmOffset.value = details.localPosition;
|
||||
} else {
|
||||
_suspendedDm = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1153,13 +1155,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
final pos = details.localPosition;
|
||||
final item = ctr.findSingleDanmaku(pos);
|
||||
if (item == null) {
|
||||
_removeDmAction();
|
||||
_suspendedDm?.suspend = false;
|
||||
_dmOffset.value = null;
|
||||
} else if (item != _suspendedDm) {
|
||||
_suspendedDm?.suspend = false;
|
||||
if (item.content.extra == null) {
|
||||
_removeDmAction();
|
||||
_dmOffset.value = null;
|
||||
return;
|
||||
}
|
||||
_suspendedDm?.suspend = false;
|
||||
_suspendedDm = item..suspend = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user