Summarize location, image and GIF messages in notifications

Notification bodies now use the chat's parsers to show a localized
summary for shared locations (m: markers), channel images, GIFs and
reactions instead of the raw payload. The marker parser moves out of the
map screen into helpers/marker_message.dart so the service can use it.
This commit is contained in:
zjs81 committed 2026-10-24 21:01:06 -07:00
1 parent ed5884e252
commit caf20b4415
28 files changed
+575 -36

No files matched your search

+20 -6
View File
@@ -8,12 +8,15 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import '../helpers/gif_helper.dart';
import '../helpers/marker_message.dart';
import '../helpers/message_url_image_helper.dart';
import '../helpers/reaction_helper.dart';
import '../l10n/app_localizations.dart';
import '../storage/prefs_manager.dart';
import '../utils/platform_info.dart';
import 'notification_reply.dart';
import 'received_image_store.dart' show ReceivedImageRef;
class NotificationService {
static final NotificationService _instance = NotificationService._internal();
@@ -278,15 +281,26 @@ class NotificationService {
await requestPermissions();
}
/// Format special message types for human-readable notifications.
static String formatNotificationText(String text) {
/// Summarizes structured payloads (reactions, images, GIFs, shared
/// locations) with the same parsers the chat bubbles use; other text is
/// returned unchanged.
static String formatNotificationText(String text, AppLocalizations l10n) {
final trimmed = text.trim();
final reaction = ReactionHelper.parseReaction(trimmed);
if (reaction != null) {
return 'Reacted ${reaction.emoji}';
return l10n.notification_reacted(reaction.emoji);
}
if (RegExp(r'^g:[A-Za-z0-9_-]+$').hasMatch(trimmed)) {
return 'Sent a GIF';
if (ReceivedImageRef.parse(trimmed) != null) {
return l10n.notification_sentImage;
}
if (GifHelper.parseGif(trimmed) != null) {
return l10n.notification_sentGif;
}
final marker = parseMarkerText(trimmed);
if (marker != null) {
return marker.label.isEmpty
? l10n.notification_sharedLocation
: l10n.notification_sharedLocationNamed(marker.label);
}
return text;
}
@@ -397,7 +411,7 @@ class NotificationService {
message,
urlImagesEnabled: urlImagesEnabled,
);
final preview = formatNotificationText(message.trim());
final preview = formatNotificationText(message.trim(), _l10n);
final body = preview.isEmpty
? _l10n.notification_receivedNewMessage
: preview;