From ef16fbeb282aff7fdfeb3323f1a76c6a693d87dc Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 15 Apr 2022 08:02:23 +0200 Subject: [PATCH] chore: Follow up fix push --- lib/utils/push_helper.dart | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index 00771f36..335cee8c 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -1,8 +1,6 @@ import 'dart:convert'; import 'dart:ui'; -import 'package:flutter/material.dart'; - import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; @@ -63,50 +61,53 @@ Future pushHelper( l10n ??= await L10n.delegate.load(window.locale); final matrixLocals = MatrixLocals(l10n); - // Display notification// Calculate title - final title = l10n.unreadMessages(notification.counts?.unread ?? 1); - // Calculate the body final body = event.getLocalizedBody( matrixLocals, plaintextBody: true, + withSenderNamePrefix: !event.room.isDirectChat, hideReply: true, hideEdit: true, removeMarkdown: true, ); // The person object for the android message style notification - if (isBackgroundMessage) WidgetsFlutterBinding.ensureInitialized(); - final avatar = event.room.avatar?.toString(); + final avatar = event.room.avatar + ?.getThumbnail( + client, + width: 126, + height: 126, + ) + .toString(); final avatarFile = avatar == null ? null : await DefaultCacheManager().getSingleFile(avatar); - final person = Person( - name: event.room.getLocalizedDisplayname(matrixLocals), - icon: - avatarFile == null ? null : BitmapFilePathAndroidIcon(avatarFile.path), - ); - // Show notification final androidPlatformChannelSpecifics = AndroidNotificationDetails( AppConfig.pushNotificationsChannelId, AppConfig.pushNotificationsChannelName, channelDescription: AppConfig.pushNotificationsChannelDescription, styleInformation: MessagingStyleInformation( - person, - conversationTitle: title, + Person(name: event.room.client.userID), + conversationTitle: event.room.displayname, groupConversation: !event.room.isDirectChat, messages: [ Message( body, event.originServerTs, - person, + Person( + name: event.room.displayname, + icon: avatarFile == null + ? null + : BitmapFilePathAndroidIcon(avatarFile.path), + ), ) ], ), - ticker: l10n.newMessageInFluffyChat, + ticker: l10n.unreadChats(notification.counts?.unread ?? 1), importance: Importance.max, priority: Priority.high, + groupKey: event.room.id, ); const iOSPlatformChannelSpecifics = IOSNotificationDetails(); final platformChannelSpecifics = NotificationDetails( @@ -128,8 +129,8 @@ Future pushHelper( /// IDs we map the [roomId] to a number and store this number. Future mapRoomIdToInt(String roomId) async { final store = await SharedPreferences.getInstance(); - final idMap = Map.from(jsonDecode( - (store.getString(SettingKeys.notificationCurrentIds)) ?? '{}')); + final idMap = Map.from( + jsonDecode(store.getString(SettingKeys.notificationCurrentIds) ?? '{}')); int? currentInt; try { currentInt = idMap[roomId]; @@ -140,7 +141,7 @@ Future mapRoomIdToInt(String roomId) async { return currentInt; } var nCurrentInt = 0; - while (idMap.values.contains(currentInt)) { + while (idMap.values.contains(nCurrentInt)) { nCurrentInt++; } idMap[roomId] = nCurrentInt;