💄 Optimize chat message notification

This commit is contained in:
2025-08-10 12:24:34 +08:00
parent 360b58885e
commit 0b44c4547c
2 changed files with 17 additions and 4 deletions

View File

@@ -515,7 +515,7 @@ public class AccountService(
.AnyAsync(); .AnyAsync();
if (isExists) if (isExists)
throw new InvalidOperationException("Contact method already exists."); throw new InvalidOperationException("Contact method already exists.");
var contact = new AccountContact var contact = new AccountContact
{ {
Type = type, Type = type,

View File

@@ -239,13 +239,26 @@ public partial class ChatService(
{ {
Topic = "messages.new", Topic = "messages.new",
Title = $"{sender.Nick ?? sender.Account.Nick} ({roomSubject})", Title = $"{sender.Nick ?? sender.Account.Nick} ({roomSubject})",
Body = !string.IsNullOrEmpty(message.Content)
? message.Content[..Math.Min(message.Content.Length, 100)]
: "<no content>",
Meta = GrpcTypeHelper.ConvertObjectToByteString(metaDict), Meta = GrpcTypeHelper.ConvertObjectToByteString(metaDict),
ActionUri = $"/chat/{room.Id}", ActionUri = $"/chat/{room.Id}",
IsSavable = false, IsSavable = false,
}; };
if (message.DeletedAt is not null)
notification.Body = "Deleted a message";
switch (message.Type)
{
case "call.ended":
notification.Body = "Call ended";
break;
case "call.start":
notification.Body = "Call begun";
break;
default:
notification.Body = !string.IsNullOrEmpty(message.Content)
? message.Content[..Math.Min(message.Content.Length, 100)]
: $"<{message.Attachments.Count} attachments>";
break;
}
List<Account> accountsToNotify = []; List<Account> accountsToNotify = [];
foreach (var member in members) foreach (var member in members)