diff --git a/lib/http/api.dart b/lib/http/api.dart index 8902f1ed8..df18bffb5 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -805,4 +805,6 @@ class Api { static const String liveSecondList = '${HttpString.liveBaseUrl}/xlive/app-interface/v2/second/getList'; + + static const String msgSetNotice = '/x/msgfeed/notice'; } diff --git a/lib/http/msg.dart b/lib/http/msg.dart index f1b12779b..5b8e56246 100644 --- a/lib/http/msg.dart +++ b/lib/http/msg.dart @@ -566,4 +566,32 @@ class MsgHttp { static String getDevId() { return const Uuid().v4(); } + + static Future msgSetNotice({ + required dynamic id, + required int noticeState, + }) async { + final csrf = Accounts.main.csrf; + var res = await Request().post( + Api.msgSetNotice, + data: { + 'mobi_app': 'web', + 'platform': 'web', + 'tp': 0, + 'id': id, + 'notice_state': noticeState, + 'build': 0, + 'csrf_token': csrf, + 'csrf': csrf, + }, + options: Options( + contentType: Headers.formUrlEncodedContentType, + ), + ); + if (res.data['code'] == 0) { + return {'status': true}; + } else { + return {'status': false, 'msg': res.data['message']}; + } + } } diff --git a/lib/pages/msg_feed_top/like_me/controller.dart b/lib/pages/msg_feed_top/like_me/controller.dart index ec04983d3..8a19526f8 100644 --- a/lib/pages/msg_feed_top/like_me/controller.dart +++ b/lib/pages/msg_feed_top/like_me/controller.dart @@ -67,4 +67,23 @@ class LikeMeController extends CommonDataController { } } catch (_) {} } + + Future onSetNotice( + int? id, int index, bool isNotice, bool isLatest) async { + int noticeState = isNotice ? 1 : 0; + var res = await MsgHttp.msgSetNotice(id: id, noticeState: noticeState); + if (res['status']) { + Pair, List> pair = + (loadingState.value as Success).response; + if (isLatest) { + pair.first[index].noticeState = noticeState; + } else { + pair.second[index].noticeState = noticeState; + } + loadingState.refresh(); + SmartDialog.showToast('操作成功'); + } else { + SmartDialog.showToast(res['msg']); + } + } } diff --git a/lib/pages/msg_feed_top/like_me/view.dart b/lib/pages/msg_feed_top/like_me/view.dart index c71989f7a..4fd12963a 100644 --- a/lib/pages/msg_feed_top/like_me/view.dart +++ b/lib/pages/msg_feed_top/like_me/view.dart @@ -77,6 +77,10 @@ class _LikeMePageState extends State { (id) { _likeMeController.onRemove(id, index, true); }, + (isNotice, id) { + _likeMeController.onSetNotice( + id, index, isNotice, true); + }, ); }, itemCount: latest.length, @@ -103,6 +107,10 @@ class _LikeMePageState extends State { (id) { _likeMeController.onRemove(id, index, false); }, + (isNotice, id) { + _likeMeController.onSetNotice( + id, index, isNotice, false); + }, ); }, itemCount: total.length, @@ -146,7 +154,12 @@ class _LikeMePageState extends State { ); } - Widget _buildItem(ThemeData theme, LikeMeItems item, ValueChanged onRemove) { + Widget _buildItem( + ThemeData theme, + LikeMeItems item, + ValueChanged onRemove, + Function(bool isNotice, int? id) onSetNotice, + ) { return ListTile( onTap: () { String? nativeUri = item.item?.nativeUri; @@ -155,11 +168,59 @@ class _LikeMePageState extends State { } }, onLongPress: () { - showConfirmDialog( + showDialog( context: context, - title: '确定删除该通知?', - onConfirm: () { - onRemove(item.id); + builder: (context) { + final isNotice = item.noticeState == 0; + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + onTap: () { + Get.back(); + showConfirmDialog( + context: context, + title: '删除', + content: '该条通知删除后,当有新点赞时会重新出现在列表,是否继续?', + onConfirm: () { + onRemove(item.id); + }, + ); + }, + dense: true, + title: const Text( + '删除', + style: TextStyle(fontSize: 14), + ), + ), + ListTile( + onTap: () { + Get.back(); + if (isNotice) { + showConfirmDialog( + context: context, + title: '不再通知', + content: '这条内容的点赞将不再通知,但仍可在列表内查看,是否继续?', + onConfirm: () { + onSetNotice(isNotice, item.id); + }, + ); + } else { + onSetNotice(isNotice, item.id); + } + }, + dense: true, + title: Text( + isNotice ? '不再通知' : '接收通知', + style: const TextStyle(fontSize: 14), + ), + ), + ], + ), + ); }, ); }, @@ -238,14 +299,24 @@ class _LikeMePageState extends State { ), ], ), - trailing: item.item?.image != null && item.item?.image != "" - ? NetworkImgLayer( + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (item.item?.image?.isNotEmpty == true) + NetworkImgLayer( width: 45, height: 45, type: 'cover', - src: item.item?.image, - ) - : null, + src: item.item!.image, + ), + if (item.noticeState == 1) + Icon( + size: 18, + Icons.notifications_off, + color: theme.colorScheme.outline, + ), + ], + ), ); } } diff --git a/lib/utils/request_utils.dart b/lib/utils/request_utils.dart index cbb62af79..5d18ff20a 100644 --- a/lib/utils/request_utils.dart +++ b/lib/utils/request_utils.dart @@ -219,7 +219,7 @@ class RequestUtils { } static ReplyInfo replyCast(res) { - Map? emote = res['content']?['emote']; + Map? emote = res['content']['emote']; emote?.forEach((key, value) { value['size'] = value['meta']['size']; });