diff --git a/DysonNetwork.Sphere/Chat/ChatService.cs b/DysonNetwork.Sphere/Chat/ChatService.cs index ef97ea3..a45a9ef 100644 --- a/DysonNetwork.Sphere/Chat/ChatService.cs +++ b/DysonNetwork.Sphere/Chat/ChatService.cs @@ -202,7 +202,7 @@ public partial class ChatService( // Create file references if message has attachments await CreateFileReferencesForMessageAsync(message); - + // Copy the value to ensure the delivery is correct message.Sender = sender; message.ChatRoom = room; @@ -287,6 +287,7 @@ public partial class ChatService( if (await scopedCrs.IsSubscribedChatRoom(member.ChatRoomId, member.Id)) subscribedMemberIds.Add(member.AccountId); } + accountsToNotify = accountsToNotify.Where(a => !subscribedMemberIds.Contains(Guid.Parse(a.Id))).ToList(); logger.LogInformation("Trying to deliver message to {count} accounts...", accountsToNotify.Count); @@ -301,7 +302,8 @@ public partial class ChatService( logger.LogInformation("Delivered message to {count} accounts.", accountsToNotify.Count); } - private PushNotification BuildNotification(SnChatMessage message, SnChatMember sender, SnChatRoom room, string roomSubject, + private PushNotification BuildNotification(SnChatMessage message, SnChatMember sender, SnChatRoom room, + string roomSubject, string type) { var metaDict = new Dictionary @@ -311,11 +313,14 @@ public partial class ChatService( ["sender_id"] = sender.Id, ["message_id"] = message.Id, ["room_id"] = room.Id, - ["images"] = message.Attachments - .Where(a => a.MimeType != null && a.MimeType.StartsWith("image")) - .Select(a => a.Id).ToList(), }; + var imageId = message.Attachments + .Where(a => a.MimeType != null && a.MimeType.StartsWith("image")) + .Select(a => a.Id).FirstOrDefault(); + if (imageId is not null) + metaDict["image"] = imageId; + if (sender.Account!.Profile is not { Picture: null }) metaDict["pfp"] = sender.Account!.Profile.Picture.Id; if (!string.IsNullOrEmpty(room.Name)) @@ -365,7 +370,8 @@ public partial class ChatService( } } - private List FilterAccountsForNotification(List members, SnChatMessage message, SnChatMember sender) + private List FilterAccountsForNotification(List members, SnChatMessage message, + SnChatMember sender) { var now = SystemClock.Instance.GetCurrentInstant(); @@ -824,4 +830,4 @@ public class SyncResponse public List Messages { get; set; } = []; public Instant CurrentTimestamp { get; set; } public int TotalCount { get; set; } = 0; -} +} \ No newline at end of file diff --git a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs index 4a34a80..2d2cd62 100644 --- a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs +++ b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs @@ -60,22 +60,19 @@ public class PublisherSubscriptionService( var (title, message) = ps.ChopPostForNotification(post); // Data to include with the notification - var images = new List(); - if (post.Attachments.Any(p => p.MimeType?.StartsWith("image/") ?? false)) - images.AddRange( - post.Attachments - .Where(p => p.MimeType?.StartsWith("image/") ?? false) - .Select(p => p.Id) - ); - else if (post.Publisher.Picture is not null) images.Add(post.Publisher.Picture.Id); - var data = new Dictionary { ["post_id"] = post.Id, - ["publisher_id"] = post.Publisher.Id.ToString(), - ["images"] = images, + ["publisher_id"] = post.Publisher.Id.ToString() }; + if (post.Attachments.Any(p => p.MimeType?.StartsWith("image/") ?? false)) + data["image"] = + post.Attachments + .Where(p => p.MimeType?.StartsWith("image/") ?? false) + .Select(p => p.Id).First(); + if (post.Publisher.Picture is not null) data["pfp"] = post.Publisher.Picture.Id; + // Gather subscribers var subscribers = await db.PublisherSubscriptions .Where(p => p.PublisherId == post.PublisherId &&