diff --git a/lib/http/api.dart b/lib/http/api.dart index d812d76c..516935d3 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -492,4 +492,8 @@ class Api { /// 表情 static const emojiList = '/x/emote/user/panel/web'; + + /// 已读标记 + static const String ackSessionMsg = + '${HttpString.tUrl}/session_svr/v1/session_svr/update_ack'; } diff --git a/lib/http/msg.dart b/lib/http/msg.dart index 70af5b55..be0bdd3a 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -86,4 +86,36 @@ class MsgHttp { }; } } + + // 消息标记已读 + static Future ackSessionMsg({ + int? talkerId, + int? ackSeqno, + }) async { + String csrf = await Request.getCsrf(); + Map params = await WbiSign().makSign({ + 'talker_id': talkerId, + 'session_type': 1, + 'ack_seqno': ackSeqno, + 'build': 0, + 'mobi_app': 'web', + 'csrf_token': csrf, + 'csrf': csrf + }); + var res = await Request().get(Api.ackSessionMsg, data: params); + if (res.data['code'] == 0) { + return { + 'status': true, + 'data': res.data['data'], + }; + } else { + return { + 'status': false, + 'date': [], + 'msg': "message: ${res.data['message']}," + " msg: ${res.data['msg']}," + " code: ${res.data['code']}", + }; + } + } } diff --git a/lib/pages/whisper/view.dart b/lib/pages/whisper/view.dart index f2779a17..f54efa58 100644 --- a/lib/pages/whisper/view.dart +++ b/lib/pages/whisper/view.dart @@ -110,7 +110,7 @@ class _WhisperPageState extends State { if (snapshot.connectionState == ConnectionState.done) { Map data = snapshot.data as Map; if (data['status']) { - List sessionList = _whisperController.sessionList; + RxList sessionList = _whisperController.sessionList; return Obx( () => sessionList.isEmpty ? const SizedBox() @@ -121,33 +121,35 @@ class _WhisperPageState extends State { const NeverScrollableScrollPhysics(), itemBuilder: (_, int i) { return ListTile( - onTap: () => Get.toNamed( - '/whisperDetail', - parameters: { - 'talkerId': sessionList[i] - .talkerId - .toString(), - 'name': sessionList[i] - .accountInfo - .name, - 'face': sessionList[i] - .accountInfo - .face, - 'mid': sessionList[i] - .accountInfo - .mid - .toString(), - }, - ), + onTap: () { + sessionList[i].unreadCount = 0; + sessionList.refresh(); + Get.toNamed( + '/whisperDetail', + parameters: { + 'talkerId': sessionList[i] + .talkerId + .toString(), + 'name': sessionList[i] + .accountInfo + .name, + 'face': sessionList[i] + .accountInfo + .face, + 'mid': sessionList[i] + .accountInfo + .mid + .toString(), + }, + ); + }, leading: Badge( - isLabelVisible: false, - backgroundColor: Theme.of(context) - .colorScheme - .primary, + isLabelVisible: + sessionList[i].unreadCount > 0, label: Text(sessionList[i] .unreadCount .toString()), - alignment: Alignment.bottomRight, + alignment: Alignment.topRight, child: NetworkImgLayer( width: 45, height: 45, diff --git a/lib/pages/whisper_detail/controller.dart b/lib/pages/whisper_detail/controller.dart index 71dd4c03..6e854712 100644 --- a/lib/pages/whisper_detail/controller.dart +++ b/lib/pages/whisper_detail/controller.dart @@ -25,10 +25,31 @@ class WhisperDetailController extends GetxController { var res = await MsgHttp.sessionMsg(talkerId: talkerId); if (res['status']) { messageList.value = res['data'].messages; - if (messageList.isNotEmpty && res['data'].eInfos != null) { - eInfos = res['data'].eInfos; + if (messageList.isNotEmpty) { + ackSessionMsg(); + if (res['data'].eInfos != null) { + eInfos = res['data'].eInfos; + } } + } else { + SmartDialog.showToast(res['msg']); } return res; } + + // 消息标记已读 + Future ackSessionMsg() async { + if (messageList.isEmpty) { + return; + } + var res = await MsgHttp.ackSessionMsg( + talkerId: talkerId, + ackSeqno: messageList.last.msgSeqno, + ); + if (res['status']) { + SmartDialog.showToast("已读成功"); + } else { + SmartDialog.showToast(res['msg']); + } + } }