fix: when user has multi counts,notification not works well

add a queryParameters, to support switch the current active user
This commit is contained in:
ShootingStarDragons 2025-08-19 22:43:41 +09:00
parent 5262395340
commit cbb2810b37
4 changed files with 34 additions and 7 deletions

View file

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

View file

@ -46,16 +46,21 @@ class ChatPage extends StatelessWidget {
final String roomId;
final List<ShareItem>? 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(

View file

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

View file

@ -87,6 +87,19 @@ class MatrixState extends State<Matrix> 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<Matrix> 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<Matrix> 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<Matrix> 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<Matrix> with WidgetsBindingObserver {
void initMatrix() {
for (final c in widget.clients) {
_registerSubs(c.clientName);
_registerSubs(c.clientName, c.userID);
}
if (kIsWeb) {