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

add a queryParameters, to support switch the current active user
pull/2142/head
ShootingStarDragons 2 months ago committed by Access
parent d42ab9e273
commit 0cab5905b5

@ -344,6 +344,7 @@ abstract class AppRoutes {
shareItems ??= [];
shareItems.add(TextShareItem(body));
}
final userId = state.uri.queryParameters['userId'];
return defaultPageBuilder(
context,
state,
@ -351,6 +352,7 @@ abstract class AppRoutes {
roomId: state.pathParameters['roomid']!,
shareItems: shareItems,
eventId: state.uri.queryParameters['event'],
userId: userId,
),
);
},

@ -48,16 +48,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(

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

@ -89,6 +89,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);
@ -170,7 +183,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');
});
@ -241,7 +257,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
}
}
void _registerSubs(String name) {
void _registerSubs(String name, String? userId) {
final c = getClientByName(name);
if (c == null) {
Logs().w(
@ -310,8 +326,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));
});
}
}
@ -329,7 +345,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) {

Loading…
Cancel
Save