desktop cm chat page

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-11-04 21:43:51 +08:00
parent 4272f0194e
commit e7ac6eb0d2
3 changed files with 29 additions and 22 deletions

@ -101,6 +101,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
gFFI.serverModel.updateClientState(); gFFI.serverModel.updateClientState();
gFFI.serverModel.tabController.onSelected = (index, _) => gFFI.serverModel.tabController.onSelected = (index, _) =>
gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id); gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id);
gFFI.chatModel.isConnManager = true;
super.initState(); super.initState();
} }
@ -159,7 +160,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
pageViewBuilder: (pageView) => Row(children: [ pageViewBuilder: (pageView) => Row(children: [
Expanded(child: pageView), Expanded(child: pageView),
Consumer<ChatModel>( Consumer<ChatModel>(
builder: (_, model, child) => model.isShowChatPage builder: (_, model, child) => model.isShowCMChatPage
? Expanded(child: Scaffold(body: ChatPage())) ? Expanded(child: Scaffold(body: ChatPage()))
: Offstage()) : Offstage())
]))); ])));

@ -34,6 +34,7 @@ class ChatModel with ChangeNotifier {
OverlayEntry? chatWindowOverlayEntry; OverlayEntry? chatWindowOverlayEntry;
bool _showOnWindowRestore = false; bool _showOnWindowRestore = false;
bool _isWindowMinimized = false; bool _isWindowMinimized = false;
bool isConnManager = false;
final ChatUser me = ChatUser( final ChatUser me = ChatUser(
id: "", id: "",
@ -44,13 +45,13 @@ class ChatModel with ChangeNotifier {
MessageBody(me, []); MessageBody(me, []);
var _currentID = clientModeID; var _currentID = clientModeID;
late bool _isShowChatPage = false; late bool _isShowCMChatPage = false;
Map<int, MessageBody> get messages => _messages; Map<int, MessageBody> get messages => _messages;
int get currentID => _currentID; int get currentID => _currentID;
bool get isShowChatPage => _isShowChatPage; bool get isShowCMChatPage => _isShowCMChatPage;
final WeakReference<FFI> parent; final WeakReference<FFI> parent;
@ -71,7 +72,6 @@ class ChatModel with ChangeNotifier {
setWindowMinimized(bool v) { setWindowMinimized(bool v) {
_isWindowMinimized = v; _isWindowMinimized = v;
if (!_isWindowMinimized && _showOnWindowRestore) { if (!_isWindowMinimized && _showOnWindowRestore) {
showChatIconOverlay();
_showOnWindowRestore = false; _showOnWindowRestore = false;
} }
} }
@ -158,9 +158,11 @@ class ChatModel with ChangeNotifier {
} }
} }
_isChatOverlayHide() => ((!isDesktop && chatIconOverlayEntry == null) ||
chatWindowOverlayEntry == null);
toggleChatOverlay() { toggleChatOverlay() {
if ((!isDesktop && chatIconOverlayEntry == null) || if (_isChatOverlayHide()) {
chatWindowOverlayEntry == null) {
gFFI.invokeMethod("enable_soft_keyboard", true); gFFI.invokeMethod("enable_soft_keyboard", true);
if (!isDesktop) { if (!isDesktop) {
showChatIconOverlay(); showChatIconOverlay();
@ -172,12 +174,24 @@ class ChatModel with ChangeNotifier {
} }
} }
showChatPage(int id) async {
if (isConnManager) {
if (!_isShowCMChatPage) {
await toggleCMChatPage(id);
}
} else {
if (_isChatOverlayHide()) {
await toggleChatOverlay();
}
}
}
toggleCMChatPage(int id) async { toggleCMChatPage(int id) async {
if (gFFI.chatModel.currentID != id) { if (gFFI.chatModel.currentID != id) {
gFFI.chatModel.changeCurrentID(id); gFFI.chatModel.changeCurrentID(id);
} }
if (_isShowChatPage) { if (_isShowCMChatPage) {
_isShowChatPage = !_isShowChatPage; _isShowCMChatPage = !_isShowCMChatPage;
notifyListeners(); notifyListeners();
await windowManager.setSize(Size(300, 400)); await windowManager.setSize(Size(300, 400));
await windowManager.setAlignment(Alignment.topRight); await windowManager.setAlignment(Alignment.topRight);
@ -185,7 +199,7 @@ class ChatModel with ChangeNotifier {
await windowManager.setSize(Size(600, 400)); await windowManager.setSize(Size(600, 400));
await Future.delayed(Duration(milliseconds: 100)); await Future.delayed(Duration(milliseconds: 100));
await windowManager.setAlignment(Alignment.topRight); await windowManager.setAlignment(Alignment.topRight);
_isShowChatPage = !_isShowChatPage; _isShowCMChatPage = !_isShowCMChatPage;
notifyListeners(); notifyListeners();
} }
} }
@ -219,17 +233,11 @@ class ChatModel with ChangeNotifier {
} }
if (text.isEmpty) return; if (text.isEmpty) return;
// mobile: first message show overlay icon // mobile: first message show overlay icon
if (chatIconOverlayEntry == null) { if (!isDesktop && chatIconOverlayEntry == null) {
if (_isWindowMinimized) {
showChatIconOverlay(); showChatIconOverlay();
} else {
_showOnWindowRestore = true;
}
}
// desktop: show chat page
if (!_isShowChatPage) {
toggleCMChatPage(id);
} }
// show chat page
await showChatPage(id);
int toId = currentID; int toId = currentID;

@ -407,9 +407,7 @@ class ServerModel with ChangeNotifier {
if (client.hasUnreadChatMessage.value) { if (client.hasUnreadChatMessage.value) {
client.hasUnreadChatMessage.value = false; client.hasUnreadChatMessage.value = false;
final chatModel = parent.target!.chatModel; final chatModel = parent.target!.chatModel;
if (!chatModel.isShowChatPage) { chatModel.showChatPage(client.id);
chatModel.toggleCMChatPage(client.id);
}
} }
}, },
page: desktop.buildConnectionCard(client))); page: desktop.buildConnectionCard(client)));