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

View File

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

View File

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

View File

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