♻️ Refactored notification meta
This commit is contained in:
@@ -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<string, object>
|
||||
@@ -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<Account> FilterAccountsForNotification(List<SnChatMember> members, SnChatMessage message, SnChatMember sender)
|
||||
private List<Account> FilterAccountsForNotification(List<SnChatMember> members, SnChatMessage message,
|
||||
SnChatMember sender)
|
||||
{
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
|
||||
|
||||
@@ -60,22 +60,19 @@ public class PublisherSubscriptionService(
|
||||
var (title, message) = ps.ChopPostForNotification(post);
|
||||
|
||||
// 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>
|
||||
{
|
||||
["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 &&
|
||||
|
||||
Reference in New Issue
Block a user