chore: Try out new matrix dart sdk

pull/1552/head
Krille 2 months ago
parent 8613010c5e
commit 55eb23f14d
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -20,8 +20,9 @@ extension LocalNotificationsExtension on MatrixState {
..src = 'assets/assets/sounds/notification.ogg' ..src = 'assets/assets/sounds/notification.ogg'
..load(); ..load();
void showLocalNotification(EventUpdate eventUpdate) async { void showLocalNotification(Event event) async {
final roomId = eventUpdate.roomID; Logs().wtf('NOTIFICATION', event.toJson());
final roomId = event.room.id;
if (activeRoomId == roomId) { if (activeRoomId == roomId) {
if (kIsWeb && webHasFocus) return; if (kIsWeb && webHasFocus) return;
if (PlatformInfos.isDesktop && if (PlatformInfos.isDesktop &&
@ -29,19 +30,13 @@ extension LocalNotificationsExtension on MatrixState {
return; 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 =
final title = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))); event.room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)));
final body = await event.calcLocalizedBody( final body = await event.calcLocalizedBody(
MatrixLocals(L10n.of(context)), MatrixLocals(L10n.of(context)),
withSenderNamePrefix: withSenderNamePrefix: !event.room.isDirectChat ||
!room.isDirectChat || room.lastEvent?.senderId == client.userID, event.room.lastEvent?.senderId == client.userID,
plaintextBody: true, plaintextBody: true,
hideReply: true, hideReply: true,
hideEdit: true, hideEdit: true,
@ -107,14 +102,14 @@ extension LocalNotificationsExtension on MatrixState {
.singleWhere((a) => a.name == actionStr); .singleWhere((a) => a.name == actionStr);
switch (action) { switch (action) {
case DesktopNotificationActions.seen: case DesktopNotificationActions.seen:
room.setReadMarker( event.room.setReadMarker(
event.eventId, event.eventId,
mRead: event.eventId, mRead: event.eventId,
public: AppConfig.sendPublicReadReceipts, public: AppConfig.sendPublicReadReceipts,
); );
break; break;
case DesktopNotificationActions.openChat: case DesktopNotificationActions.openChat:
context.go('/rooms/${room.id}'); context.go('/rooms/${event.room.id}');
break; break;
} }
}); });

@ -305,15 +305,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] ??= c.onEvent.stream onNotification[name] ??=
.where( c.onNotification.stream.listen(showLocalNotification);
(e) =>
e.type == EventUpdateType.timeline &&
[EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(e.content['type']) &&
e.content['sender'] != c.userID,
)
.listen(showLocalNotification);
}); });
} }
} }

@ -1157,10 +1157,11 @@ packages:
matrix: matrix:
dependency: "direct main" dependency: "direct main"
description: description:
name: matrix path: "."
sha256: de99186797fddbf309dae0d9b9b4d35b49ca10d7bb362727f7cd916ce71a77d7 ref: HEAD
url: "https://pub.dev" resolved-ref: b23ad952a445705a200ac4b17b385a602e6fbbe4
source: hosted url: "https://github.com/famedly/matrix-dart-sdk.git"
source: git
version: "0.36.0" version: "0.36.0"
meta: meta:
dependency: transitive dependency: transitive

@ -62,7 +62,8 @@ dependencies:
just_audio: ^0.9.39 just_audio: ^0.9.39
latlong2: ^0.9.1 latlong2: ^0.9.1
linkify: ^5.0.0 linkify: ^5.0.0
matrix: ^0.36.0 matrix:
git: https://github.com/famedly/matrix-dart-sdk.git
mime: ^1.0.6 mime: ^1.0.6
native_imaging: ^0.1.1 native_imaging: ^0.1.1
opus_caf_converter_dart: ^1.0.1 opus_caf_converter_dart: ^1.0.1

Loading…
Cancel
Save