Throttle message notifications during sync

This commit is contained in:
Janez T
2026-05-10 17:48:13 +02:00
parent e1400cf1ec
commit 6062f91c2d
3 changed files with 86 additions and 15 deletions

View File

@@ -36,6 +36,7 @@ class MessagesProvider with ChangeNotifier {
bool _isInitialized = false;
bool _isPersisting = false;
bool _persistRequested = false;
bool _suppressReceivedNotifications = false;
AppLocalizations? _localizations;
final Map<String, MessageContactLocation> _messageContactLocations = {};
final Map<String, MessageReceptionDetails> _messageReceptionDetails = {};
@@ -850,11 +851,13 @@ class MessagesProvider with ChangeNotifier {
_sarMarkers[marker.id] = marker;
// Trigger urgent notification for received SAR messages (not sent by user)
if (!finalMessage.isSentMessage) {
if (!finalMessage.isSentMessage && !_suppressReceivedNotifications) {
_triggerSarNotification(finalMessage, marker);
}
}
} else if (!finalMessage.isSentMessage && !finalMessage.isSystemMessage) {
} else if (!finalMessage.isSentMessage &&
!finalMessage.isSystemMessage &&
!_suppressReceivedNotifications) {
// Trigger notification for regular messages (not SAR, not sent by user, not system)
_triggerMessageNotification(finalMessage);
}
@@ -865,6 +868,18 @@ class MessagesProvider with ChangeNotifier {
notifyListeners();
}
Future<T> withReceivedNotificationsSuppressed<T>(
Future<T> Function() action,
) async {
final previous = _suppressReceivedNotifications;
_suppressReceivedNotifications = true;
try {
return await action();
} finally {
_suppressReceivedNotifications = previous;
}
}
/// Check if a message is a duplicate
///
/// Messages are considered duplicates if they have: