Fix media notifications and photo bubbles

This commit is contained in:
sevenhill
2026-07-06 13:17:47 +03:00
parent 61d7aae7eb
commit 30361370da
4 changed files with 78 additions and 18 deletions
@@ -73,6 +73,7 @@ public sealed class MaxBridgeSyncService(
var changed = 0;
var createdMessages = new List<(Chat Chat, Message Message)>();
var updatedMessages = new List<(Chat Chat, Message Message)>();
var previewNotificationMessages = new List<(Chat Chat, Message Message)>();
var trackedChatsByExternalId = new Dictionary<string, Chat>(StringComparer.Ordinal);
foreach (var update in updates)
@@ -190,6 +191,10 @@ public sealed class MaxBridgeSyncService(
createdMessages.Add((chat, previewResult.Message));
}
}
if (previewResult.NotificationMessage is not null)
{
previewNotificationMessages.Add((chat, previewResult.NotificationMessage));
}
if (previewResult.Changed)
{
@@ -350,6 +355,14 @@ public sealed class MaxBridgeSyncService(
}
}
foreach (var (chat, message) in previewNotificationMessages)
{
if (sendPushNotifications && message.Direction == MessageDirection.Incoming)
{
await pushNotifications.SendNewMessageAsync(chat, message, cancellationToken);
}
}
foreach (var (chat, message) in updatedMessages)
{
var updated = await db.Messages
@@ -379,12 +392,12 @@ public sealed class MaxBridgeSyncService(
var preview = MessageTextSanitizer.CleanChatPreview(update.LastMessagePreview);
if (string.IsNullOrWhiteSpace(preview))
{
return new ListPreviewApplyResult(false, null);
return new ListPreviewApplyResult(false, null, null);
}
if (IsPresencePreview(preview))
{
return new ListPreviewApplyResult(false, null);
return new ListPreviewApplyResult(false, null, null);
}
var previousPreview = chat.LastMessagePreview;
@@ -392,7 +405,7 @@ public sealed class MaxBridgeSyncService(
var previewAt = ResolveListPreviewAt(update, previousPreviewAt ?? chat.UpdatedAt);
if (chat.HistoryClearedAt is { } historyClearedAt && previewAt <= historyClearedAt)
{
return new ListPreviewApplyResult(false, null);
return new ListPreviewApplyResult(false, null, null);
}
var samePreview = string.Equals(previousPreview, preview, StringComparison.Ordinal);
@@ -400,7 +413,7 @@ public sealed class MaxBridgeSyncService(
Math.Abs((previousPreviewAt.Value - previewAt).TotalSeconds) < 1;
if (samePreview && samePreviewAt)
{
return new ListPreviewApplyResult(false, null);
return new ListPreviewApplyResult(false, null, null);
}
chat.LastMessagePreview = preview;
@@ -425,7 +438,10 @@ public sealed class MaxBridgeSyncService(
var message = shouldNotify && !MessageTextSanitizer.IsGenericMediaLabel(preview)
? CreatePreviewMessage(chat, preview, previewAt)
: null;
return new ListPreviewApplyResult(true, message);
var notificationMessage = shouldNotify && message is null && MessageTextSanitizer.IsGenericMediaLabel(preview)
? CreatePreviewMessage(chat, preview, previewAt)
: null;
return new ListPreviewApplyResult(true, message, notificationMessage);
}
private static bool IsKnownOutgoingPreviewEcho(
@@ -604,7 +620,7 @@ public sealed class MaxBridgeSyncService(
text.Contains("file", StringComparison.Ordinal);
}
private sealed record ListPreviewApplyResult(bool Changed, Message? Message);
private sealed record ListPreviewApplyResult(bool Changed, Message? Message, Message? NotificationMessage);
private sealed record MessageMergeResult(bool Changed, IReadOnlyList<MessageAttachment> AddedAttachments);