Merge pull request #2648 from krille-chan/krille/use-correct-person-for-android-notification-reply
fix: Use correct own person for android notification replies
This commit is contained in:
commit
127c3fd7bf
2 changed files with 34 additions and 124 deletions
|
|
@ -9,10 +9,7 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/utils/client_download_content_extension.dart';
|
|
||||||
import 'package:fluffychat/utils/client_manager.dart';
|
import 'package:fluffychat/utils/client_manager.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
|
||||||
import 'package:fluffychat/utils/push_helper.dart';
|
import 'package:fluffychat/utils/push_helper.dart';
|
||||||
import '../config/app_config.dart';
|
import '../config/app_config.dart';
|
||||||
import '../config/setting_keys.dart';
|
import '../config/setting_keys.dart';
|
||||||
|
|
@ -172,89 +169,11 @@ Future<void> notificationTap(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final eventId = await room.sendTextEvent(
|
await room.sendTextEvent(
|
||||||
input,
|
input,
|
||||||
parseCommands: false,
|
parseCommands: false,
|
||||||
displayPendingEvent: false,
|
displayPendingEvent: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (PlatformInfos.isAndroid) {
|
|
||||||
final ownProfile = await room.client.fetchOwnProfile();
|
|
||||||
final avatar = ownProfile.avatarUrl;
|
|
||||||
final avatarFile = avatar == null
|
|
||||||
? null
|
|
||||||
: await client
|
|
||||||
.downloadMxcCached(
|
|
||||||
avatar,
|
|
||||||
thumbnailMethod: ThumbnailMethod.crop,
|
|
||||||
width: notificationAvatarDimension,
|
|
||||||
height: notificationAvatarDimension,
|
|
||||||
animated: false,
|
|
||||||
isThumbnail: true,
|
|
||||||
rounded: true,
|
|
||||||
)
|
|
||||||
.timeout(const Duration(seconds: 3));
|
|
||||||
final messagingStyleInformation =
|
|
||||||
await AndroidFlutterLocalNotificationsPlugin()
|
|
||||||
.getActiveNotificationMessagingStyle(id: room.id.hashCode);
|
|
||||||
if (messagingStyleInformation == null) return;
|
|
||||||
l10n ??= await lookupL10n(PlatformDispatcher.instance.locale);
|
|
||||||
messagingStyleInformation.messages?.add(
|
|
||||||
Message(
|
|
||||||
input,
|
|
||||||
DateTime.now(),
|
|
||||||
Person(
|
|
||||||
key: room.client.userID,
|
|
||||||
name: l10n.you,
|
|
||||||
icon: avatarFile == null
|
|
||||||
? null
|
|
||||||
: ByteArrayAndroidIcon(avatarFile),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
await FlutterLocalNotificationsPlugin().show(
|
|
||||||
id: room.id.hashCode,
|
|
||||||
title: room.getLocalizedDisplayname(MatrixLocals(l10n)),
|
|
||||||
body: input,
|
|
||||||
notificationDetails: NotificationDetails(
|
|
||||||
android: AndroidNotificationDetails(
|
|
||||||
AppConfig.pushNotificationsChannelId,
|
|
||||||
l10n.incomingMessages,
|
|
||||||
category: AndroidNotificationCategory.message,
|
|
||||||
shortcutId: room.id,
|
|
||||||
styleInformation: messagingStyleInformation,
|
|
||||||
groupKey: room.id,
|
|
||||||
playSound: false,
|
|
||||||
enableVibration: false,
|
|
||||||
actions: <AndroidNotificationAction>[
|
|
||||||
AndroidNotificationAction(
|
|
||||||
FluffyChatNotificationActions.reply.name,
|
|
||||||
l10n.reply,
|
|
||||||
inputs: [
|
|
||||||
AndroidNotificationActionInput(
|
|
||||||
label: l10n.writeAMessage,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
cancelNotification: false,
|
|
||||||
allowGeneratedReplies: true,
|
|
||||||
semanticAction: SemanticAction.reply,
|
|
||||||
),
|
|
||||||
AndroidNotificationAction(
|
|
||||||
FluffyChatNotificationActions.markAsRead.name,
|
|
||||||
l10n.markAsRead,
|
|
||||||
semanticAction: SemanticAction.markAsRead,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
payload: FluffyChatPushPayload(
|
|
||||||
client.clientName,
|
|
||||||
room.id,
|
|
||||||
eventId,
|
|
||||||
).toString(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,43 +162,15 @@ Future<void> _tryPushHelper(
|
||||||
? avatar
|
? avatar
|
||||||
: event.senderFromMemoryOrFallback.avatarUrl;
|
: event.senderFromMemoryOrFallback.avatarUrl;
|
||||||
|
|
||||||
Uint8List? roomAvatarFile, senderAvatarFile;
|
final ownUser = event.room.unsafeGetUserFromMemoryOrFallback(client.userID!);
|
||||||
try {
|
|
||||||
roomAvatarFile = avatar == null
|
final userAvatarFile = await client.tryDownloadNotificationAvatar(
|
||||||
? null
|
ownUser.avatarUrl,
|
||||||
: await client
|
);
|
||||||
.downloadMxcCached(
|
final roomAvatarFile = await client.tryDownloadNotificationAvatar(avatar);
|
||||||
avatar,
|
final senderAvatarFile = await client.tryDownloadNotificationAvatar(
|
||||||
thumbnailMethod: ThumbnailMethod.crop,
|
senderAvatar,
|
||||||
width: notificationAvatarDimension,
|
);
|
||||||
height: notificationAvatarDimension,
|
|
||||||
animated: false,
|
|
||||||
isThumbnail: true,
|
|
||||||
rounded: true,
|
|
||||||
)
|
|
||||||
.timeout(const Duration(seconds: 3));
|
|
||||||
} catch (e, s) {
|
|
||||||
Logs().e('Unable to get avatar picture', e, s);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
senderAvatarFile = event.room.isDirectChat
|
|
||||||
? roomAvatarFile
|
|
||||||
: senderAvatar == null
|
|
||||||
? null
|
|
||||||
: await client
|
|
||||||
.downloadMxcCached(
|
|
||||||
senderAvatar,
|
|
||||||
thumbnailMethod: ThumbnailMethod.crop,
|
|
||||||
width: notificationAvatarDimension,
|
|
||||||
height: notificationAvatarDimension,
|
|
||||||
animated: false,
|
|
||||||
isThumbnail: true,
|
|
||||||
rounded: true,
|
|
||||||
)
|
|
||||||
.timeout(const Duration(seconds: 3));
|
|
||||||
} catch (e, s) {
|
|
||||||
Logs().e('Unable to get avatar picture', e, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
final id = notification.roomId.hashCode;
|
final id = notification.roomId.hashCode;
|
||||||
|
|
||||||
|
|
@ -262,12 +234,11 @@ Future<void> _tryPushHelper(
|
||||||
messagingStyleInformation ??
|
messagingStyleInformation ??
|
||||||
MessagingStyleInformation(
|
MessagingStyleInformation(
|
||||||
Person(
|
Person(
|
||||||
name: senderName,
|
name: ownUser.calcDisplayname(),
|
||||||
icon: roomAvatarFile == null
|
icon: userAvatarFile == null
|
||||||
? null
|
? null
|
||||||
: ByteArrayAndroidIcon(roomAvatarFile),
|
: ByteArrayAndroidIcon(userAvatarFile),
|
||||||
key: event.roomId,
|
key: event.room.client.userID,
|
||||||
important: event.room.isFavourite,
|
|
||||||
),
|
),
|
||||||
conversationTitle: event.room.isDirectChat ? null : roomName,
|
conversationTitle: event.room.isDirectChat ? null : roomName,
|
||||||
groupConversation: !event.room.isDirectChat,
|
groupConversation: !event.room.isDirectChat,
|
||||||
|
|
@ -372,3 +343,23 @@ Future<void> _setShortcut(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension on Client {
|
||||||
|
Future<Uint8List?> tryDownloadNotificationAvatar(Uri? avatar) async {
|
||||||
|
if (avatar == null) return null;
|
||||||
|
try {
|
||||||
|
return await downloadMxcCached(
|
||||||
|
avatar,
|
||||||
|
thumbnailMethod: ThumbnailMethod.crop,
|
||||||
|
width: notificationAvatarDimension,
|
||||||
|
height: notificationAvatarDimension,
|
||||||
|
animated: false,
|
||||||
|
isThumbnail: true,
|
||||||
|
rounded: true,
|
||||||
|
).timeout(const Duration(seconds: 3));
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().e('Unable to get avatar picture', e, s);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue