mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-08-26 10:16:54 +08:00
desktop cm chat feat: disable auto jumpTo other page when current hasFocus & add unread message mark on tab
This commit is contained in:
@ -14,11 +14,11 @@ class MessageBody {
|
||||
MessageBody(this.chatUser, this.chatMessages);
|
||||
|
||||
void insert(ChatMessage cm) {
|
||||
this.chatMessages.insert(0, cm);
|
||||
chatMessages.insert(0, cm);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
this.chatMessages.clear();
|
||||
chatMessages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ class ChatModel with ChangeNotifier {
|
||||
|
||||
ChatModel(this.parent);
|
||||
|
||||
FocusNode inputNode = FocusNode();
|
||||
|
||||
ChatUser get currentUser {
|
||||
final user = messages[currentID]?.chatUser;
|
||||
if (user == null) {
|
||||
@ -199,6 +201,11 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
receive(int id, String text) async {
|
||||
final session = parent.target;
|
||||
if (session == null) {
|
||||
debugPrint("Failed to receive msg, session state is null");
|
||||
return;
|
||||
}
|
||||
if (text.isEmpty) return;
|
||||
// mobile: first message show overlay icon
|
||||
if (chatIconOverlayEntry == null) {
|
||||
@ -208,27 +215,32 @@ class ChatModel with ChangeNotifier {
|
||||
if (!_isShowChatPage) {
|
||||
toggleCMChatPage(id);
|
||||
}
|
||||
parent.target?.serverModel.jumpTo(id);
|
||||
|
||||
late final chatUser;
|
||||
int toId = currentID;
|
||||
|
||||
late final ChatUser chatUser;
|
||||
if (id == clientModeID) {
|
||||
chatUser = ChatUser(
|
||||
firstName: parent.target?.ffiModel.pi.username,
|
||||
id: await bind.mainGetLastRemoteId(),
|
||||
firstName: session.ffiModel.pi.username,
|
||||
id: session.id,
|
||||
);
|
||||
toId = id;
|
||||
} else {
|
||||
final client = parent.target?.serverModel.clients
|
||||
.firstWhere((client) => client.id == id);
|
||||
if (client == null) {
|
||||
return debugPrint("Failed to receive msg,user doesn't exist");
|
||||
}
|
||||
final client =
|
||||
session.serverModel.clients.firstWhere((client) => client.id == id);
|
||||
if (isDesktop) {
|
||||
window_on_top(null);
|
||||
var index = parent.target?.serverModel.clients
|
||||
.indexWhere((client) => client.id == id);
|
||||
if (index != null && index >= 0) {
|
||||
gFFI.serverModel.tabController.jumpTo(index);
|
||||
// disable auto jumpTo other tab when hasFocus, and mark unread message
|
||||
final currentSelectedTab =
|
||||
session.serverModel.tabController.state.value.selectedTabInfo;
|
||||
if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) {
|
||||
client.hasUnreadChatMessage.value = true;
|
||||
} else {
|
||||
parent.target?.serverModel.jumpTo(id);
|
||||
toId = id;
|
||||
}
|
||||
} else {
|
||||
toId = id;
|
||||
}
|
||||
chatUser = ChatUser(id: client.peerId, firstName: client.name);
|
||||
}
|
||||
@ -238,7 +250,7 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
_messages[id]!.insert(
|
||||
ChatMessage(text: text, user: chatUser, createdAt: DateTime.now()));
|
||||
_currentID = id;
|
||||
_currentID = toId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user