diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index a59a540fa..e32ac1d38 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -20,8 +20,9 @@ extension LocalNotificationsExtension on MatrixState { ..src = 'assets/assets/sounds/notification.ogg' ..load(); - void showLocalNotification(EventUpdate eventUpdate) async { - final roomId = eventUpdate.roomID; + void showLocalNotification(Event event) async { + Logs().wtf('NOTIFICATION', event.toJson()); + final roomId = event.room.id; if (activeRoomId == roomId) { if (kIsWeb && webHasFocus) return; if (PlatformInfos.isDesktop && @@ -29,19 +30,13 @@ extension LocalNotificationsExtension on MatrixState { return; } } - final room = client.getRoomById(roomId); - if (room == null) { - Logs().w('Can not display notification for unknown room $roomId'); - return; - } - if (room.notificationCount == 0) return; - final event = Event.fromJson(eventUpdate.content, room); - final title = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))); + final title = + event.room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))); final body = await event.calcLocalizedBody( MatrixLocals(L10n.of(context)), - withSenderNamePrefix: - !room.isDirectChat || room.lastEvent?.senderId == client.userID, + withSenderNamePrefix: !event.room.isDirectChat || + event.room.lastEvent?.senderId == client.userID, plaintextBody: true, hideReply: true, hideEdit: true, @@ -107,14 +102,14 @@ extension LocalNotificationsExtension on MatrixState { .singleWhere((a) => a.name == actionStr); switch (action) { case DesktopNotificationActions.seen: - room.setReadMarker( + event.room.setReadMarker( event.eventId, mRead: event.eventId, public: AppConfig.sendPublicReadReceipts, ); break; case DesktopNotificationActions.openChat: - context.go('/rooms/${room.id}'); + context.go('/rooms/${event.room.id}'); break; } }); diff --git a/lib/widgets/matrix.dart b/lib/widgets/matrix.dart index 1dac4ae9c..677bfb744 100644 --- a/lib/widgets/matrix.dart +++ b/lib/widgets/matrix.dart @@ -305,15 +305,8 @@ class MatrixState extends State with WidgetsBindingObserver { if (PlatformInfos.isWeb || PlatformInfos.isLinux) { c.onSync.stream.first.then((s) { html.Notification.requestPermission(); - onNotification[name] ??= c.onEvent.stream - .where( - (e) => - e.type == EventUpdateType.timeline && - [EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted] - .contains(e.content['type']) && - e.content['sender'] != c.userID, - ) - .listen(showLocalNotification); + onNotification[name] ??= + c.onNotification.stream.listen(showLocalNotification); }); } } diff --git a/pubspec.lock b/pubspec.lock index 3461425a7..80548af70 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1157,10 +1157,11 @@ packages: matrix: dependency: "direct main" description: - name: matrix - sha256: de99186797fddbf309dae0d9b9b4d35b49ca10d7bb362727f7cd916ce71a77d7 - url: "https://pub.dev" - source: hosted + path: "." + ref: HEAD + resolved-ref: b23ad952a445705a200ac4b17b385a602e6fbbe4 + url: "https://github.com/famedly/matrix-dart-sdk.git" + source: git version: "0.36.0" meta: dependency: transitive diff --git a/pubspec.yaml b/pubspec.yaml index 7b2152ea2..71f4d6d26 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,7 +62,8 @@ dependencies: just_audio: ^0.9.39 latlong2: ^0.9.1 linkify: ^5.0.0 - matrix: ^0.36.0 + matrix: + git: https://github.com/famedly/matrix-dart-sdk.git mime: ^1.0.6 native_imaging: ^0.1.1 opus_caf_converter_dart: ^1.0.1