From 3a59b8bb60122fd5e76ee20797f366aeaa8eb9a2 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 29 Sep 2024 17:04:39 +0800 Subject: [PATCH] feat: pm: remove/setTop --- lib/http/api.dart | 4 ++ lib/http/msg.dart | 51 +++++++++++++++ .../detail/reply/widgets/reply_item.dart | 63 +++++++++---------- lib/pages/whisper/controller.dart | 54 +++++++++++++--- lib/pages/whisper/view.dart | 51 +++++++++++++++ 5 files changed, 182 insertions(+), 41 deletions(-) diff --git a/lib/http/api.dart b/lib/http/api.dart index 461c398a..1821c0cd 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -613,4 +613,8 @@ class Api { static const String videoTags = '/x/tag/archive/tags'; static const String reportMember = '/ajax/report/add'; + + static const String removeMsg = '/session_svr/v1/session_svr/remove_session'; + + static const String setTop = '/session_svr/v1/session_svr/set_top'; } diff --git a/lib/http/msg.dart b/lib/http/msg.dart index 6c8e4c16..bd9c6c58 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -1,4 +1,5 @@ import 'dart:math'; +import 'package:PiliPalaX/http/constants.dart'; import 'package:dio/dio.dart'; import '../models/msg/account.dart'; @@ -142,6 +143,56 @@ class MsgHttp { } } + static Future removeMsg( + dynamic talkerId, + ) async { + String csrf = await Request.getCsrf(); + Map data = await WbiSign().makSign({ + 'talker_id': talkerId, + 'session_type': 1, + 'build': 0, + 'mobi_app': 'web', + 'csrf_token': csrf, + 'csrf': csrf + }); + var res = await Request() + .post(HttpString.tUrl + Api.removeMsg, data: FormData.fromMap(data)); + if (res.data['code'] == 0) { + return {'status': true}; + } else { + return { + 'status': false, + 'msg': res.data['message'], + }; + } + } + + static Future setTop( + dynamic talkerId, + int opType, + ) async { + String csrf = await Request.getCsrf(); + Map data = await WbiSign().makSign({ + 'talker_id': talkerId, + 'session_type': 1, + 'op_type': opType, + 'build': 0, + 'mobi_app': 'web', + 'csrf_token': csrf, + 'csrf': csrf + }); + var res = await Request() + .post(HttpString.tUrl + Api.setTop, data: FormData.fromMap(data)); + if (res.data['code'] == 0) { + return {'status': true}; + } else { + return { + 'status': false, + 'msg': res.data['message'], + }; + } + } + // 会话列表 static Future sessionList({int? endTs}) async { Map params = { diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index f30104f0..4c82eb2d 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -264,41 +264,40 @@ class ReplyItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Semantics( - label: text, - child: Text.rich( - style: TextStyle( - height: 1.75, - fontSize: Theme.of(context) - .textTheme - .bodyMedium! - .fontSize), - TextSpan( - children: [ - if (replyItem!.isTop!) ...[ - const WidgetSpan( - alignment: PlaceholderAlignment.top, - child: PBadge( - text: 'TOP', - size: 'small', - stack: 'normal', - type: 'line', - fs: 9, - semanticsLabel: '置顶', - ), + label: text, + child: Text.rich( + style: TextStyle( + height: 1.75, + fontSize: + Theme.of(context).textTheme.bodyMedium!.fontSize), + TextSpan( + children: [ + if (replyItem!.isTop!) ...[ + const WidgetSpan( + alignment: PlaceholderAlignment.top, + child: PBadge( + text: 'TOP', + size: 'small', + stack: 'normal', + type: 'line', + fs: 9, + semanticsLabel: '置顶', ), - const TextSpan(text: ' '), - ], - buildContent( - context, - replyItem!, - replyReply, - null, - textPainter, - didExceedMaxLines, ), + const TextSpan(text: ' '), ], - ), - )), + buildContent( + context, + replyItem!, + replyReply, + null, + textPainter, + didExceedMaxLines, + ), + ], + ), + ), + ), if (didExceedMaxLines) Text( '查看更多', diff --git a/lib/pages/whisper/controller.dart b/lib/pages/whisper/controller.dart index 7f81e9a3..91a4ba98 100644 --- a/lib/pages/whisper/controller.dart +++ b/lib/pages/whisper/controller.dart @@ -15,29 +15,29 @@ class WhisperController extends GetxController { Rx msgFeedUnread = MsgFeedUnread().obs; RxList msgFeedTop = [ { - "name":"回复我的", - "icon":Icons.message_outlined, + "name": "回复我的", + "icon": Icons.message_outlined, "route": "/replyMe", "enabled": true, "value": 0 }, { - "name":"@我", - "icon":Icons.alternate_email_outlined, + "name": "@我", + "icon": Icons.alternate_email_outlined, "route": "/atMe", "enabled": true, "value": 0 }, { - "name":"收到的赞", - "icon":Icons.favorite_border_outlined, + "name": "收到的赞", + "icon": Icons.favorite_border_outlined, "route": "/likeMe", "enabled": true, "value": 0 }, { - "name":"系统通知", - "icon":Icons.notifications_none_outlined, + "name": "系统通知", + "icon": Icons.notifications_none_outlined, "route": "/sysMsg", "enabled": true, "value": 0 @@ -52,7 +52,8 @@ class WhisperController extends GetxController { msgFeedTop[1]["value"] = msgFeedUnread.value.at; msgFeedTop[2]["value"] = msgFeedUnread.value.like; msgFeedTop[3]["value"] = msgFeedUnread.value.sys_msg; - if (GStorage.setting.get(SettingBoxKey.disableLikeMsg, defaultValue: false)) { + if (GStorage.setting + .get(SettingBoxKey.disableLikeMsg, defaultValue: false)) { msgFeedTop[2]["value"] = -1; msgFeedTop[2]["enabled"] = false; } @@ -63,6 +64,41 @@ class WhisperController extends GetxController { } } + Future onRemove(int index) async { + var res = await MsgHttp.removeMsg(sessionList[index].talkerId); + if (res['status']) { + sessionList.removeAt(index); + SmartDialog.showToast('删除成功'); + } else { + SmartDialog.showToast(res['msg']); + } + } + + Future onSetTop(int index) async { + bool isTop = sessionList[index].topTs != 0; + var res = await MsgHttp.setTop( + sessionList[index].talkerId, + isTop ? 1 : 0, + ); + if (res['status']) { + List list = sessionList.map((item) { + if (item.talkerId == sessionList[index].talkerId) { + return item..topTs = isTop ? 0 : 1; + } else { + return item; + } + }).toList(); + if (!isTop) { + SessionList item = list.removeAt(index); + list.insert(0, item); + } + sessionList.value = list; + SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功'); + } else { + SmartDialog.showToast(res['msg']); + } + } + Future querySessionList(String? type) async { if (isLoading) return; var res = await MsgHttp.sessionList( diff --git a/lib/pages/whisper/view.dart b/lib/pages/whisper/view.dart index 3b10cb68..fb998fbf 100644 --- a/lib/pages/whisper/view.dart +++ b/lib/pages/whisper/view.dart @@ -172,6 +172,57 @@ class _WhisperPageState extends State { content.toString(); } return ListTile( + tileColor: sessionList[i].topTs == 0 + ? null + : Theme.of(context) + .colorScheme + .primaryContainer, + onLongPress: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: + const EdgeInsets.symmetric( + vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + dense: true, + onTap: () { + Get.back(); + _whisperController + .onSetTop(i); + }, + title: Text( + sessionList[i].topTs == 0 + ? '置顶' + : '移除置顶', + style: const TextStyle( + fontSize: 14), + ), + ), + ListTile( + dense: true, + onTap: () { + Get.back(); + _whisperController + .onRemove(i); + }, + title: const Text( + '删除', + style: + TextStyle(fontSize: 14), + ), + ), + ], + ), + ); + }, + ); + }, onTap: () { setState(() { sessionList[i].unreadCount = 0;