desktop cm chat feat: disable auto jumpTo other page when current hasFocus & add unread message mark on tab

This commit is contained in:
csf
2022-10-26 23:50:36 +09:00
parent 5a905174e7
commit c100505fa1
6 changed files with 71 additions and 46 deletions

View File

@@ -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();
}

View File

@@ -4,6 +4,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/models/platform_model.dart';
import 'package:get/get.dart';
import 'package:wakelock/wakelock.dart';
import 'package:window_manager/window_manager.dart';
@@ -402,6 +403,15 @@ class ServerModel with ChangeNotifier {
key: client.id.toString(),
label: client.name,
closable: false,
onTap: () {
if (client.hasUnreadChatMessage.value) {
client.hasUnreadChatMessage.value = false;
final chatModel = parent.target!.chatModel;
if (!chatModel.isShowChatPage) {
chatModel.toggleCMChatPage(client.id);
}
}
},
page: Desktop.buildConnectionCard(client)));
Future.delayed(Duration.zero, () async {
window_on_top(null);
@@ -538,6 +548,8 @@ class Client {
bool recording = false;
bool disconnected = false;
RxBool hasUnreadChatMessage = false.obs;
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
this.keyboard, this.clipboard, this.audio);
@@ -557,7 +569,7 @@ class Client {
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['is_start'] = authorized;
data['is_file_transfer'] = isFileTransfer;