From 7c4c69aa75fd63a3fb176dc808bc0ae04396cc9f Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 5 Jul 2023 17:01:33 +0800 Subject: [PATCH] cm unread message count Signed-off-by: 21pages --- flutter/lib/desktop/pages/server_page.dart | 18 ++++++++++++++++-- flutter/lib/models/chat_model.dart | 2 +- flutter/lib/models/server_model.dart | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index 3ea735d25..62333456e 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -160,8 +160,22 @@ class ConnectionManagerState extends State { child: label), Obx(() => Offstage( offstage: - !(client?.hasUnreadChatMessage.value ?? false), - child: Icon(Icons.circle, color: Colors.red, size: 10))) + !((client?.unreadChatMessageCount.value ?? 0) > 0), + child: Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + shape: BoxShape.circle, + ), + child: Center( + child: Text( + "${client?.unreadChatMessageCount.value ?? 0}", + maxLines: 1, + style: TextStyle( + color: Colors.white, fontSize: 10)), + ), + ).marginOnly(left: 4))) ], ); }, diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index 8c1e0a9a4..81a240cba 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -318,7 +318,7 @@ class ChatModel with ChangeNotifier { final currentSelectedTab = session.serverModel.tabController.state.value.selectedTabInfo; if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) { - client.hasUnreadChatMessage.value = true; + client.unreadChatMessageCount.value += 1; } else { parent.target?.serverModel.jumpTo(id); toId = id; diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 9a6b52e7e..cd0f52f39 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -463,8 +463,8 @@ class ServerModel with ChangeNotifier { label: client.name, closable: false, onTap: () { - if (client.hasUnreadChatMessage.value) { - client.hasUnreadChatMessage.value = false; + if (client.unreadChatMessageCount.value > 0) { + client.unreadChatMessageCount.value = 0; final chatModel = parent.target!.chatModel; chatModel.showChatPage(client.id); } @@ -643,7 +643,7 @@ class Client { bool inVoiceCall = false; bool incomingVoiceCall = false; - RxBool hasUnreadChatMessage = false.obs; + RxInt unreadChatMessageCount = 0.obs; Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId, this.keyboard, this.clipboard, this.audio);