From af0a2ff493bb878c44be00c01c8a97df43d064ad Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 22 Nov 2025 18:08:11 +0800 Subject: [PATCH] :lipstick: Enrich post susbcription notification --- .../Publisher/PublisherSubscriptionService.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs index 68f415c..4a34a80 100644 --- a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs +++ b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs @@ -55,15 +55,25 @@ public class PublisherSubscriptionService( return 0; if (post.Visibility != Shared.Models.PostVisibility.Public) return 0; - + // Create notification data 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.ToString() }, - { "publisher_id", post.Publisher.Id.ToString() } + ["post_id"] = post.Id, + ["publisher_id"] = post.Publisher.Id.ToString(), + ["images"] = images, }; // Gather subscribers @@ -83,6 +93,7 @@ public class PublisherSubscriptionService( .ToListAsync(); categorySubscribers.AddRange(subs); } + if (post.Tags.Count > 0) { var tagIds = post.Tags.Select(x => x.Id).ToList(); @@ -110,7 +121,7 @@ public class PublisherSubscriptionService( var notification = new PushNotification { Topic = "posts.new", - Title = localizer["PostSubscriptionTitle", post.Publisher.Name, title], + Title = localizer["PostSubscriptionTitle", post.Publisher.Nick, title], Body = message, Meta = GrpcTypeHelper.ConvertObjectToByteString(data), IsSavable = true, @@ -221,4 +232,4 @@ public class PublisherSubscriptionService( return true; } -} +} \ No newline at end of file