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:
parent
5262395340
commit
cbb2810b37
4 changed files with 34 additions and 7 deletions
|
|
@ -346,6 +346,7 @@ abstract class AppRoutes {
|
||||||
shareItems ??= [];
|
shareItems ??= [];
|
||||||
shareItems.add(TextShareItem(body));
|
shareItems.add(TextShareItem(body));
|
||||||
}
|
}
|
||||||
|
final userId = state.uri.queryParameters['userId'];
|
||||||
return defaultPageBuilder(
|
return defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
state,
|
state,
|
||||||
|
|
@ -353,6 +354,7 @@ abstract class AppRoutes {
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
shareItems: shareItems,
|
shareItems: shareItems,
|
||||||
eventId: state.uri.queryParameters['event'],
|
eventId: state.uri.queryParameters['event'],
|
||||||
|
userId: userId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,21 @@ class ChatPage extends StatelessWidget {
|
||||||
final String roomId;
|
final String roomId;
|
||||||
final List<ShareItem>? shareItems;
|
final List<ShareItem>? shareItems;
|
||||||
final String? eventId;
|
final String? eventId;
|
||||||
|
final String? userId;
|
||||||
|
|
||||||
const ChatPage({
|
const ChatPage({
|
||||||
super.key,
|
super.key,
|
||||||
required this.roomId,
|
required this.roomId,
|
||||||
this.eventId,
|
this.eventId,
|
||||||
this.shareItems,
|
this.shareItems,
|
||||||
|
this.userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (userId != null) {
|
||||||
|
Matrix.of(context).setActiveClientWithUserId(userId!);
|
||||||
|
}
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||||
if (room == null) {
|
if (room == null) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ extension LocalNotificationsExtension on MatrixState {
|
||||||
..src = 'assets/assets/sounds/notification.ogg'
|
..src = 'assets/assets/sounds/notification.ogg'
|
||||||
..load();
|
..load();
|
||||||
|
|
||||||
void showLocalNotification(Event event) async {
|
void showLocalNotification(Event event, String? userId) async {
|
||||||
final roomId = event.room.id;
|
final roomId = event.room.id;
|
||||||
if (activeRoomId == roomId) {
|
if (activeRoomId == roomId) {
|
||||||
if (kIsWeb && webHasFocus) return;
|
if (kIsWeb && webHasFocus) return;
|
||||||
|
|
@ -147,7 +147,11 @@ extension LocalNotificationsExtension on MatrixState {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case DesktopNotificationActions.openChat:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,19 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
|
|
||||||
late String currentClientSecret;
|
late String currentClientSecret;
|
||||||
RequestTokenResponse? currentThreepidCreds;
|
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) {
|
void setActiveClient(Client? cl) {
|
||||||
final i = widget.clients.indexWhere((c) => c == cl);
|
final i = widget.clients.indexWhere((c) => c == cl);
|
||||||
|
|
@ -168,7 +181,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
_loginClientCandidate!.clientName,
|
_loginClientCandidate!.clientName,
|
||||||
store,
|
store,
|
||||||
);
|
);
|
||||||
_registerSubs(_loginClientCandidate!.clientName);
|
_registerSubs(
|
||||||
|
_loginClientCandidate!.clientName,
|
||||||
|
_loginClientCandidate!.userID,
|
||||||
|
);
|
||||||
_loginClientCandidate = null;
|
_loginClientCandidate = null;
|
||||||
FluffyChatApp.router.go('/rooms');
|
FluffyChatApp.router.go('/rooms');
|
||||||
});
|
});
|
||||||
|
|
@ -221,7 +237,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
initMatrix();
|
initMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _registerSubs(String name) {
|
void _registerSubs(String name, String? userId) {
|
||||||
final c = getClientByName(name);
|
final c = getClientByName(name);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
|
|
@ -290,8 +306,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
|
if (PlatformInfos.isWeb || PlatformInfos.isLinux) {
|
||||||
c.onSync.stream.first.then((s) {
|
c.onSync.stream.first.then((s) {
|
||||||
html.Notification.requestPermission();
|
html.Notification.requestPermission();
|
||||||
onNotification[name] ??=
|
onNotification[name] ??= c.onNotification.stream
|
||||||
c.onNotification.stream.listen(showLocalNotification);
|
.listen((data) => showLocalNotification(data, userId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +325,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
||||||
|
|
||||||
void initMatrix() {
|
void initMatrix() {
|
||||||
for (final c in widget.clients) {
|
for (final c in widget.clients) {
|
||||||
_registerSubs(c.clientName);
|
_registerSubs(c.clientName, c.userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue