diff --git a/lib/pages/whisper/controller.dart b/lib/pages/whisper/controller.dart index b4deb014..c2c790cb 100644 --- a/lib/pages/whisper/controller.dart +++ b/lib/pages/whisper/controller.dart @@ -45,36 +45,44 @@ class WhisperController extends GetxController { if (isLoading) return; var res = await MsgHttp.sessionList( endTs: type == 'onLoad' ? sessionList.last.sessionTs : null); - if (res['status'] && - res['data'].sessionList != null && - res['data'].sessionList.isNotEmpty) { - await queryAccountList(res['data'].sessionList); - // 将 accountList 转换为 Map 结构 - Map accountMap = {}; - for (var j in accountList) { - accountMap[j.mid!] = j; - } + try { + if (res['status'] && + res['data'].sessionList != null && + res['data'].sessionList.isNotEmpty) { + await queryAccountList(res['data'].sessionList); + // 将 accountList 转换为 Map 结构 + Map accountMap = {}; + for (var j in accountList) { + accountMap[j.mid!] = j; + } - // 遍历 sessionList,通过 mid 查找并赋值 accountInfo - for (var i in res['data'].sessionList) { - var accountInfo = accountMap[i.talkerId]; - if (accountInfo != null) { - i.accountInfo = accountInfo; + // 遍历 sessionList,通过 mid 查找并赋值 accountInfo + for (var i in res['data'].sessionList) { + var accountInfo = accountMap[i.talkerId]; + if (accountInfo != null) { + i.accountInfo = accountInfo; + } + if (i.talkerId == 844424930131966) { + i.accountInfo = AccountListModel( + name: 'UP主小助手', + face: + 'https://message.biliimg.com/bfs/im/489a63efadfb202366c2f88853d2217b5ddc7a13.png', + ); + } } - if (i.talkerId == 844424930131966) { - i.accountInfo = AccountListModel( - name: 'UP主小助手', - face: - 'https://message.biliimg.com/bfs/im/489a63efadfb202366c2f88853d2217b5ddc7a13.png', - ); + if (type == 'onLoad') { + sessionList.addAll(res['data'].sessionList); + } else { + sessionList.value = res['data'].sessionList; } } - if (type == 'onLoad') { - sessionList.addAll(res['data'].sessionList); - } else { - sessionList.value = res['data'].sessionList; - } + } catch (err) { + res = { + 'status': false, + 'message': err.toString(), + }; } + isLoading = false; return res; } diff --git a/lib/pages/whisper/view.dart b/lib/pages/whisper/view.dart index 75e6e1c2..ee8a8f66 100644 --- a/lib/pages/whisper/view.dart +++ b/lib/pages/whisper/view.dart @@ -44,7 +44,24 @@ class _WhisperPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('消息')), + appBar: AppBar( + title: const Text('消息'), + actions: [ + IconButton( + icon: Icon(Icons.open_in_browser_rounded, + color: Theme.of(context).colorScheme.primary), + tooltip: '用浏览器打开', + onPressed: () { + Get.toNamed('/webview', parameters: { + 'url': 'https://message.bilibili.com', + 'type': 'whisper', + 'pageTitle': '消息中心', + }); + }, + ), + const SizedBox(width: 12) + ], + ), body: RefreshIndicator( onRefresh: () async { _whisperController.unread();