Fix media placeholders and image cache

This commit is contained in:
sevenhill
2026-07-06 09:10:31 +03:00
parent 9940f9e43c
commit 61d7aae7eb
10 changed files with 275 additions and 16 deletions
@@ -106,6 +106,7 @@ public sealed class ChatsController(
}
var messages = (await query.ToArrayAsync(cancellationToken))
.Where(message => !IsGenericPreviewPlaceholder(message))
.OrderByDescending(x => x.SentAt)
.Take(Math.Clamp(take, 1, 200))
.ToArray();
@@ -121,6 +122,11 @@ public sealed class ChatsController(
return;
}
if (MessageTextSanitizer.IsGenericMediaLabel(preview))
{
return;
}
var previewAt = chat.LastMessageAt.Value;
if (chat.HistoryClearedAt is { } historyClearedAt && previewAt <= historyClearedAt)
{
@@ -202,6 +208,14 @@ public sealed class ChatsController(
return hash.ToString("x8");
}
private static bool IsGenericPreviewPlaceholder(Message message)
{
return message.Direction == MessageDirection.Incoming &&
message.Attachments.Count == 0 &&
message.ExternalId?.StartsWith("preview:", StringComparison.Ordinal) == true &&
MessageTextSanitizer.IsGenericMediaLabel(message.Text);
}
[HttpPost("{chatId:guid}/read")]
public async Task<IActionResult> MarkRead(Guid chatId, CancellationToken cancellationToken)
{
@@ -422,7 +422,7 @@ public sealed class MaxBridgeSyncService(
chat.UnreadCount++;
}
var message = shouldNotify
var message = shouldNotify && !MessageTextSanitizer.IsGenericMediaLabel(preview)
? CreatePreviewMessage(chat, preview, previewAt)
: null;
return new ListPreviewApplyResult(true, message);
@@ -35,6 +35,8 @@ public static class MessageTextSanitizer
{
return value?.Trim().ToLowerInvariant() switch
{
"\u043c\u0435\u0434\u0438\u0430" => true,
"media" => true,
"\u0444\u043e\u0442\u043e" => true,
"photo" => true,
"image" => true,