mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-21 19:28:27 +08:00
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/dialog/report.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/controller.dart';
|
||||
import 'package:PiliPlus/http/constants.dart';
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
@@ -98,10 +99,11 @@ class LiveRoomController extends GetxController {
|
||||
// dm
|
||||
LiveDmInfoData? dmInfo;
|
||||
List<RichTextItem>? savedDanmaku;
|
||||
RxList<DanmakuMsg> messages = <DanmakuMsg>[].obs;
|
||||
RxList<dynamic> messages = <dynamic>[].obs;
|
||||
late final Rx<SuperChatItem?> fsSC = Rx<SuperChatItem?>(null);
|
||||
late final RxList<SuperChatItem> superChatMsg = <SuperChatItem>[].obs;
|
||||
RxBool disableAutoScroll = false.obs;
|
||||
bool autoScroll = true;
|
||||
LiveMessageStream? _msgStream;
|
||||
late final ScrollController scrollController;
|
||||
late final RxInt pageIndex = 0.obs;
|
||||
@@ -297,6 +299,16 @@ class LiveRoomController extends GetxController {
|
||||
}
|
||||
|
||||
void scrollToBottom([_]) {
|
||||
EasyThrottle.throttle(
|
||||
'liveDm',
|
||||
const Duration(milliseconds: 500),
|
||||
() => WidgetsBinding.instance.addPostFrameCallback(
|
||||
_scrollToBottom,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _scrollToBottom([_]) {
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.maxScrollExtent,
|
||||
@@ -326,7 +338,7 @@ class LiveRoomController extends GetxController {
|
||||
messages.addAll(
|
||||
list.cast<Map<String, dynamic>>().map(DanmakuMsg.fromPrefetch),
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback(scrollToBottom);
|
||||
scrollToBottom();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
@@ -424,6 +436,19 @@ class LiveRoomController extends GetxController {
|
||||
..init();
|
||||
}
|
||||
|
||||
void addDm(dynamic msg, [DanmakuContentItem<DanmakuExtra>? item]) {
|
||||
messages.add(msg);
|
||||
|
||||
if (plPlayerController.showDanmaku) {
|
||||
if (item != null) {
|
||||
danmakuController?.addDanmaku(item);
|
||||
}
|
||||
if (autoScroll && !disableAutoScroll.value) {
|
||||
scrollToBottom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void _danmakuListener(dynamic obj) {
|
||||
try {
|
||||
@@ -459,7 +484,7 @@ class LiveRoomController extends GetxController {
|
||||
name: extra['reply_uname'],
|
||||
);
|
||||
}
|
||||
messages.add(
|
||||
addDm(
|
||||
DanmakuMsg(
|
||||
name: name,
|
||||
uid: uid,
|
||||
@@ -471,31 +496,17 @@ class LiveRoomController extends GetxController {
|
||||
extra: liveExtra,
|
||||
reply: reply,
|
||||
),
|
||||
DanmakuContentItem(
|
||||
msg,
|
||||
color: DanmakuOptions.blockColorful
|
||||
? Colors.white
|
||||
: DmUtils.decimalToColor(extra['color']),
|
||||
type: DmUtils.getPosition(extra['mode']),
|
||||
// extra['send_from_me'] is invalid
|
||||
selfSend: isLogin && uid == mid,
|
||||
extra: liveExtra,
|
||||
),
|
||||
);
|
||||
|
||||
if (plPlayerController.showDanmaku) {
|
||||
danmakuController?.addDanmaku(
|
||||
DanmakuContentItem(
|
||||
msg,
|
||||
color: DanmakuOptions.blockColorful
|
||||
? Colors.white
|
||||
: DmUtils.decimalToColor(extra['color']),
|
||||
type: DmUtils.getPosition(extra['mode']),
|
||||
// extra['send_from_me'] is invalid
|
||||
selfSend: isLogin && uid == mid,
|
||||
extra: liveExtra,
|
||||
),
|
||||
);
|
||||
if (!disableAutoScroll.value) {
|
||||
EasyThrottle.throttle(
|
||||
'liveDm',
|
||||
const Duration(milliseconds: 500),
|
||||
() => WidgetsBinding.instance.addPostFrameCallback(
|
||||
scrollToBottom,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'SUPER_CHAT_MESSAGE' when showSuperChat:
|
||||
final item = SuperChatItem.fromJson(obj['data']);
|
||||
@@ -505,6 +516,7 @@ class LiveRoomController extends GetxController {
|
||||
endTime: DateTime.now().millisecondsSinceEpoch ~/ 1000 + 10,
|
||||
);
|
||||
}
|
||||
addDm(item);
|
||||
break;
|
||||
case 'WATCHED_CHANGE':
|
||||
watchedShow.value = obj['data']['text_large'];
|
||||
@@ -587,4 +599,26 @@ class LiveRoomController extends GetxController {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void reportSC(SuperChatItem item) {
|
||||
if (!Accounts.main.isLogin) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
autoWrapReportDialog(
|
||||
Get.context!,
|
||||
ReportOptions.liveDanmakuReport,
|
||||
(reasonType, reasonDesc, banUid) {
|
||||
return LiveHttp.superChatReport(
|
||||
id: item.id,
|
||||
roomId: roomId,
|
||||
uid: item.uid,
|
||||
msg: item.message,
|
||||
reason: ReportOptions.liveDanmakuReport['']![reasonType]!,
|
||||
ts: item.ts,
|
||||
token: item.token,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user