Skip to content

Commit

Permalink
feat: 消息未读标记
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Feb 25, 2024
1 parent 078e471 commit bf071ea
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 26 deletions.
4 changes: 4 additions & 0 deletions lib/http/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,8 @@ class Api {

/// 我的订阅详情
static const userSubFolderDetail = '/x/space/fav/season/list';

/// 已读标记
static const String ackSessionMsg =
'${HttpString.tUrl}/session_svr/v1/session_svr/update_ack';
}
32 changes: 32 additions & 0 deletions lib/http/msg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']}",
};
}
}
}
50 changes: 26 additions & 24 deletions lib/pages/whisper/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _WhisperPageState extends State<WhisperPage> {
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()
Expand All @@ -121,33 +121,35 @@ class _WhisperPageState extends State<WhisperPage> {
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,
Expand Down
25 changes: 23 additions & 2 deletions lib/pages/whisper_detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
}

0 comments on commit bf071ea

Please sign in to comment.