From cbb2810b375072d51db57a92d06e49b9f98c13e7 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 19 Aug 2025 22:43:41 +0900 Subject: [PATCH 1/7] fix: when user has multi counts,notification not works well add a queryParameters, to support switch the current active user --- lib/config/routes.dart | 2 ++ lib/pages/chat/chat.dart | 5 ++++ .../local_notifications_extension.dart | 8 ++++-- lib/widgets/matrix.dart | 26 +++++++++++++++---- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index 8f92d4c6d..b448097dc 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -346,6 +346,7 @@ abstract class AppRoutes { shareItems ??= []; shareItems.add(TextShareItem(body)); } + final userId = state.uri.queryParameters['userId']; return defaultPageBuilder( context, state, @@ -353,6 +354,7 @@ abstract class AppRoutes { roomId: state.pathParameters['roomid']!, shareItems: shareItems, eventId: state.uri.queryParameters['event'], + userId: userId, ), ); }, diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 54f6010cc..ef701797d 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -46,16 +46,21 @@ class ChatPage extends StatelessWidget { final String roomId; final List? shareItems; final String? eventId; + final String? userId; const ChatPage({ super.key, required this.roomId, this.eventId, this.shareItems, + this.userId, }); @override Widget build(BuildContext context) { + if (userId != null) { + Matrix.of(context).setActiveClientWithUserId(userId!); + } final room = Matrix.of(context).client.getRoomById(roomId); if (room == null) { return Scaffold( diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index 873fdfc1a..aa738e711 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -23,7 +23,7 @@ extension LocalNotificationsExtension on MatrixState { ..src = 'assets/assets/sounds/notification.ogg' ..load(); - void showLocalNotification(Event event) async { + void showLocalNotification(Event event, String? userId) async { final roomId = event.room.id; if (activeRoomId == roomId) { if (kIsWeb && webHasFocus) return; @@ -147,7 +147,11 @@ extension LocalNotificationsExtension on MatrixState { ); break; case DesktopNotificationActions.openChat: - FluffyChatApp.router.go('/rooms/${event.room.id}'); + if (userId != null) { + FluffyChatApp.router.go('/rooms/${event.room.id}?userId=$userId'); + } else { + FluffyChatApp.router.go('/rooms/${event.room.id}'); + } break; } }); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 55fd267ad..c5125870b 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -87,6 +87,19 @@ class MatrixState extends State with WidgetsBindingObserver { late String currentClientSecret; RequestTokenResponse? currentThreepidCreds; + void setActiveClientWithUserId(String userId) { + final i = widget.clients.indexWhere((c) => c.userID == userId); + if (i != -1) { + if (_activeClient == i) { + return; + } + _activeClient = i; + // TODO: Multi-client VoiP support + createVoipPlugin(); + } else { + Logs().w('Tried to set an unknown user $userId as active'); + } + } void setActiveClient(Client? cl) { final i = widget.clients.indexWhere((c) => c == cl); @@ -168,7 +181,10 @@ class MatrixState extends State with WidgetsBindingObserver { _loginClientCandidate!.clientName, store, ); - _registerSubs(_loginClientCandidate!.clientName); + _registerSubs( + _loginClientCandidate!.clientName, + _loginClientCandidate!.userID, + ); _loginClientCandidate = null; FluffyChatApp.router.go('/rooms'); }); @@ -221,7 +237,7 @@ class MatrixState extends State with WidgetsBindingObserver { initMatrix(); } - void _registerSubs(String name) { + void _registerSubs(String name, String? userId) { final c = getClientByName(name); if (c == null) { Logs().w( @@ -290,8 +306,8 @@ class MatrixState extends State with WidgetsBindingObserver { if (PlatformInfos.isWeb || PlatformInfos.isLinux) { c.onSync.stream.first.then((s) { html.Notification.requestPermission(); - onNotification[name] ??= - c.onNotification.stream.listen(showLocalNotification); + onNotification[name] ??= c.onNotification.stream + .listen((data) => showLocalNotification(data, userId)); }); } } @@ -309,7 +325,7 @@ class MatrixState extends State with WidgetsBindingObserver { void initMatrix() { for (final c in widget.clients) { - _registerSubs(c.clientName); + _registerSubs(c.clientName, c.userID); } if (kIsWeb) { From ccb2a23075c49753143fc9c8b5c05a88fafb722e Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Mon, 17 Nov 2025 18:14:47 +0900 Subject: [PATCH 2/7] chore: do as suggestion --- lib/config/routes.dart | 2 -- lib/pages/chat/chat.dart | 5 ----- lib/widgets/local_notifications_extension.dart | 6 +++--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/config/routes.dart b/lib/config/routes.dart index b448097dc..8f92d4c6d 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -346,7 +346,6 @@ abstract class AppRoutes { shareItems ??= []; shareItems.add(TextShareItem(body)); } - final userId = state.uri.queryParameters['userId']; return defaultPageBuilder( context, state, @@ -354,7 +353,6 @@ abstract class AppRoutes { roomId: state.pathParameters['roomid']!, shareItems: shareItems, eventId: state.uri.queryParameters['event'], - userId: userId, ), ); }, diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index ef701797d..54f6010cc 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -46,21 +46,16 @@ class ChatPage extends StatelessWidget { final String roomId; final List? shareItems; final String? eventId; - final String? userId; const ChatPage({ super.key, required this.roomId, this.eventId, this.shareItems, - this.userId, }); @override Widget build(BuildContext context) { - if (userId != null) { - Matrix.of(context).setActiveClientWithUserId(userId!); - } final room = Matrix.of(context).client.getRoomById(roomId); if (room == null) { return Scaffold( diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index aa738e711..4d2b09721 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -148,10 +148,10 @@ extension LocalNotificationsExtension on MatrixState { break; case DesktopNotificationActions.openChat: if (userId != null) { - FluffyChatApp.router.go('/rooms/${event.room.id}?userId=$userId'); - } else { - FluffyChatApp.router.go('/rooms/${event.room.id}'); + Matrix.of(context).setActiveClientWithUserId(userId); } + + FluffyChatApp.router.go('/rooms/${event.room.id}'); break; } }); From 940d3e62dbf1b8d872a66afc360bfee277f3f061 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 18 Nov 2025 23:59:36 +0900 Subject: [PATCH 3/7] fix: jump cannot work properly when there are multi users --- lib/pages/chat_list/chat_list.dart | 9 +++++++++ lib/widgets/local_notifications_extension.dart | 4 ++-- lib/widgets/matrix.dart | 5 +++++ linux/CMakeLists.txt | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 4f96aff6d..2e8e04e65 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -415,6 +415,7 @@ class ChatListController extends State ); }); + Matrix.of(context).setController(this); super.initState(); } @@ -815,6 +816,14 @@ class ChatListController extends State _clientStream.add(client); } + void setActiveClientWithUserId(String name) { + setState(() { + activeFilter = ActiveFilter.allChats; + _activeSpaceId = null; + Matrix.of(context).setActiveClientWithUserId(name); + }); + } + void setActiveBundle(String bundle) { context.go('/rooms'); setState(() { diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index 4d2b09721..ef7e9127c 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -147,8 +147,8 @@ extension LocalNotificationsExtension on MatrixState { ); break; case DesktopNotificationActions.openChat: - if (userId != null) { - Matrix.of(context).setActiveClientWithUserId(userId); + if (userId != null && controller != null) { + controller!.setActiveClientWithUserId(userId); } FluffyChatApp.router.go('/rooms/${event.room.id}'); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index c5125870b..ee04638b8 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -70,6 +71,7 @@ class MatrixState extends State with WidgetsBindingObserver { bool? loginRegistrationSupported; BackgroundPush? backgroundPush; + ChatListController? controller; Client get client { if (_activeClient < 0 || _activeClient >= widget.clients.length) { @@ -100,6 +102,9 @@ class MatrixState extends State with WidgetsBindingObserver { Logs().w('Tried to set an unknown user $userId as active'); } } + void setController(ChatListController controller) { + this.controller = controller; + } void setActiveClient(Client? cl) { final i = widget.clients.indexWhere((c) => c == cl); diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index ecb5b8764..ffff12596 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -42,6 +42,7 @@ endif() # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_options(${TARGET} PRIVATE -Wno-deprecated) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") From acce4a8d7befa525afe64f9158a4c8f0479dbcd2 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Wed, 19 Nov 2025 00:03:06 +0900 Subject: [PATCH 4/7] chore: do format --- lib/widgets/matrix.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index ee04638b8..23d81c244 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:convert'; -import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -18,6 +17,7 @@ import 'package:universal_html/html.dart' as html; import 'package:url_launcher/url_launcher_string.dart'; import 'package:fluffychat/l10n/l10n.dart'; +import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/utils/client_manager.dart'; import 'package:fluffychat/utils/init_with_restore.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; @@ -102,6 +102,7 @@ class MatrixState extends State with WidgetsBindingObserver { Logs().w('Tried to set an unknown user $userId as active'); } } + void setController(ChatListController controller) { this.controller = controller; } From 27b2eac7ed1c79312b30c3f9ee93792753bb8a34 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Wed, 19 Nov 2025 18:16:37 +0900 Subject: [PATCH 5/7] chore: do as suggested --- lib/pages/chat_list/chat_list.dart | 9 --------- .../local_notifications_extension.dart | 4 ++-- lib/widgets/matrix.dart | 19 ------------------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 2e8e04e65..4f96aff6d 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -415,7 +415,6 @@ class ChatListController extends State ); }); - Matrix.of(context).setController(this); super.initState(); } @@ -816,14 +815,6 @@ class ChatListController extends State _clientStream.add(client); } - void setActiveClientWithUserId(String name) { - setState(() { - activeFilter = ActiveFilter.allChats; - _activeSpaceId = null; - Matrix.of(context).setActiveClientWithUserId(name); - }); - } - void setActiveBundle(String bundle) { context.go('/rooms'); setState(() { diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index ef7e9127c..b61162e39 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -147,8 +147,8 @@ extension LocalNotificationsExtension on MatrixState { ); break; case DesktopNotificationActions.openChat: - if (userId != null && controller != null) { - controller!.setActiveClientWithUserId(userId); + if (userId != null) { + setActiveClient(event.room.client); } FluffyChatApp.router.go('/rooms/${event.room.id}'); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 23d81c244..77fa4b1c4 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -17,7 +17,6 @@ import 'package:universal_html/html.dart' as html; import 'package:url_launcher/url_launcher_string.dart'; import 'package:fluffychat/l10n/l10n.dart'; -import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/utils/client_manager.dart'; import 'package:fluffychat/utils/init_with_restore.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; @@ -71,7 +70,6 @@ class MatrixState extends State with WidgetsBindingObserver { bool? loginRegistrationSupported; BackgroundPush? backgroundPush; - ChatListController? controller; Client get client { if (_activeClient < 0 || _activeClient >= widget.clients.length) { @@ -89,23 +87,6 @@ class MatrixState extends State with WidgetsBindingObserver { late String currentClientSecret; RequestTokenResponse? currentThreepidCreds; - void setActiveClientWithUserId(String userId) { - final i = widget.clients.indexWhere((c) => c.userID == userId); - if (i != -1) { - if (_activeClient == i) { - return; - } - _activeClient = i; - // TODO: Multi-client VoiP support - createVoipPlugin(); - } else { - Logs().w('Tried to set an unknown user $userId as active'); - } - } - - void setController(ChatListController controller) { - this.controller = controller; - } void setActiveClient(Client? cl) { final i = widget.clients.indexWhere((c) => c == cl); From 175d06515d5e5cd8c6ba73e621e04c8a3329b2e4 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Wed, 19 Nov 2025 18:19:05 +0900 Subject: [PATCH 6/7] chore: delete unrelated line --- linux/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index ffff12596..ecb5b8764 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -42,7 +42,6 @@ endif() # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) - target_compile_options(${TARGET} PRIVATE -Wno-deprecated) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") From 1c614490f1d2e54abc886b648ba7fdd03cb704e0 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Wed, 19 Nov 2025 19:39:36 +0900 Subject: [PATCH 7/7] chore: remove the userId param now I do not pass userId in --- lib/widgets/local_notifications_extension.dart | 6 ++---- lib/widgets/matrix.dart | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index b61162e39..443ed6c83 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -23,7 +23,7 @@ extension LocalNotificationsExtension on MatrixState { ..src = 'assets/assets/sounds/notification.ogg' ..load(); - void showLocalNotification(Event event, String? userId) async { + void showLocalNotification(Event event) async { final roomId = event.room.id; if (activeRoomId == roomId) { if (kIsWeb && webHasFocus) return; @@ -147,9 +147,7 @@ extension LocalNotificationsExtension on MatrixState { ); break; case DesktopNotificationActions.openChat: - if (userId != null) { - setActiveClient(event.room.client); - } + setActiveClient(event.room.client); FluffyChatApp.router.go('/rooms/${event.room.id}'); break; diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 77fa4b1c4..55fd267ad 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -168,10 +168,7 @@ class MatrixState extends State with WidgetsBindingObserver { _loginClientCandidate!.clientName, store, ); - _registerSubs( - _loginClientCandidate!.clientName, - _loginClientCandidate!.userID, - ); + _registerSubs(_loginClientCandidate!.clientName); _loginClientCandidate = null; FluffyChatApp.router.go('/rooms'); }); @@ -224,7 +221,7 @@ class MatrixState extends State with WidgetsBindingObserver { initMatrix(); } - void _registerSubs(String name, String? userId) { + void _registerSubs(String name) { final c = getClientByName(name); if (c == null) { Logs().w( @@ -293,8 +290,8 @@ class MatrixState extends State with WidgetsBindingObserver { if (PlatformInfos.isWeb || PlatformInfos.isLinux) { c.onSync.stream.first.then((s) { html.Notification.requestPermission(); - onNotification[name] ??= c.onNotification.stream - .listen((data) => showLocalNotification(data, userId)); + onNotification[name] ??= + c.onNotification.stream.listen(showLocalNotification); }); } } @@ -312,7 +309,7 @@ class MatrixState extends State with WidgetsBindingObserver { void initMatrix() { for (final c in widget.clients) { - _registerSubs(c.clientName, c.userID); + _registerSubs(c.clientName); } if (kIsWeb) {