🐛 Fixes and optimize deliver message
This commit is contained in:
@@ -254,14 +254,36 @@ public partial class ChatService(
|
||||
notification.Body = "Call begun";
|
||||
break;
|
||||
default:
|
||||
var attachmentWord = message.Attachments.Count == 1 ? "attachment" : "attachments";
|
||||
notification.Body = !string.IsNullOrEmpty(message.Content)
|
||||
? message.Content[..Math.Min(message.Content.Length, 100)]
|
||||
: $"<{message.Attachments.Count} attachments>";
|
||||
: $"<{message.Attachments.Count} {attachmentWord}>";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case WebSocketPacketType.MessageUpdate:
|
||||
notification.Body += " (edited)";
|
||||
break;
|
||||
case WebSocketPacketType.MessageDelete:
|
||||
notification.Body = "Deleted a message";
|
||||
break;
|
||||
}
|
||||
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
|
||||
var request = new PushWebSocketPacketToUsersRequest
|
||||
{
|
||||
Packet = new WebSocketPacket
|
||||
{
|
||||
Type = type,
|
||||
Data = GrpcTypeHelper.ConvertObjectToByteString(message),
|
||||
},
|
||||
};
|
||||
request.UserIds.AddRange(members.Select(a => a.Account).Where(a => a is not null).Select(a => a!.Id.ToString()));
|
||||
await scopedNty.PushWebSocketPacketToUsersAsync(request);
|
||||
|
||||
List<Account> accountsToNotify = [];
|
||||
foreach (
|
||||
var member in members
|
||||
@@ -279,17 +301,6 @@ public partial class ChatService(
|
||||
accountsToNotify.Add(member.Account.ToProtoValue());
|
||||
}
|
||||
|
||||
var request = new PushWebSocketPacketToUsersRequest
|
||||
{
|
||||
Packet = new WebSocketPacket
|
||||
{
|
||||
Type = type,
|
||||
Data = GrpcTypeHelper.ConvertObjectToByteString(message),
|
||||
},
|
||||
};
|
||||
request.UserIds.AddRange(accountsToNotify.Select(a => a.Id.ToString()));
|
||||
await scopedNty.PushWebSocketPacketToUsersAsync(request);
|
||||
|
||||
accountsToNotify = accountsToNotify
|
||||
.Where(a => a.Id != sender.AccountId.ToString()).ToList();
|
||||
|
||||
@@ -389,15 +400,11 @@ public partial class ChatService(
|
||||
|
||||
// Remove messages with no sender
|
||||
foreach (var key in messagesToRemove)
|
||||
{
|
||||
messages.Remove(key);
|
||||
}
|
||||
|
||||
// Update remaining messages with their senders
|
||||
foreach (var message in messages)
|
||||
{
|
||||
message.Value!.Sender = messageSenders.First(x => x.Id == message.Value.SenderId);
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
Reference in New Issue
Block a user