💄 Enrich post susbcription notification
This commit is contained in:
@@ -55,15 +55,25 @@ public class PublisherSubscriptionService(
|
|||||||
return 0;
|
return 0;
|
||||||
if (post.Visibility != Shared.Models.PostVisibility.Public)
|
if (post.Visibility != Shared.Models.PostVisibility.Public)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Create notification data
|
// Create notification data
|
||||||
var (title, message) = ps.ChopPostForNotification(post);
|
var (title, message) = ps.ChopPostForNotification(post);
|
||||||
|
|
||||||
// Data to include with the notification
|
// Data to include with the notification
|
||||||
|
var images = new List<string>();
|
||||||
|
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<string, object>
|
var data = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "post_id", post.Id.ToString() },
|
["post_id"] = post.Id,
|
||||||
{ "publisher_id", post.Publisher.Id.ToString() }
|
["publisher_id"] = post.Publisher.Id.ToString(),
|
||||||
|
["images"] = images,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Gather subscribers
|
// Gather subscribers
|
||||||
@@ -83,6 +93,7 @@ public class PublisherSubscriptionService(
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
categorySubscribers.AddRange(subs);
|
categorySubscribers.AddRange(subs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.Tags.Count > 0)
|
if (post.Tags.Count > 0)
|
||||||
{
|
{
|
||||||
var tagIds = post.Tags.Select(x => x.Id).ToList();
|
var tagIds = post.Tags.Select(x => x.Id).ToList();
|
||||||
@@ -110,7 +121,7 @@ public class PublisherSubscriptionService(
|
|||||||
var notification = new PushNotification
|
var notification = new PushNotification
|
||||||
{
|
{
|
||||||
Topic = "posts.new",
|
Topic = "posts.new",
|
||||||
Title = localizer["PostSubscriptionTitle", post.Publisher.Name, title],
|
Title = localizer["PostSubscriptionTitle", post.Publisher.Nick, title],
|
||||||
Body = message,
|
Body = message,
|
||||||
Meta = GrpcTypeHelper.ConvertObjectToByteString(data),
|
Meta = GrpcTypeHelper.ConvertObjectToByteString(data),
|
||||||
IsSavable = true,
|
IsSavable = true,
|
||||||
@@ -221,4 +232,4 @@ public class PublisherSubscriptionService(
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user