diff --git a/DysonNetwork.Sphere/Account/Account.cs b/DysonNetwork.Sphere/Account/Account.cs index 1347df7..a2fdbc9 100644 --- a/DysonNetwork.Sphere/Account/Account.cs +++ b/DysonNetwork.Sphere/Account/Account.cs @@ -84,6 +84,7 @@ public class AccountContact : ModelBase public Instant? VerifiedAt { get; set; } [MaxLength(1024)] public string Content { get; set; } = string.Empty; + public Guid AccountId { get; set; } [JsonIgnore] public Account Account { get; set; } = null!; } @@ -100,6 +101,7 @@ public class AccountAuthFactor : ModelBase public AccountAuthFactorType Type { get; set; } [MaxLength(8196)] public string? Secret { get; set; } = null; + public Guid AccountId { get; set; } [JsonIgnore] public Account Account { get; set; } = null!; public AccountAuthFactor HashSecret(int cost = 12) diff --git a/DysonNetwork.Sphere/Account/NotificationService.cs b/DysonNetwork.Sphere/Account/NotificationService.cs index 98dc70f..5306b8d 100644 --- a/DysonNetwork.Sphere/Account/NotificationService.cs +++ b/DysonNetwork.Sphere/Account/NotificationService.cs @@ -264,22 +264,29 @@ public class NotificationService if (_apns == null) throw new InvalidOperationException("The apple notification push service is not initialized."); - await _apns.SendAsync(new Dictionary + var alertDict = new Dictionary(); + + if (!string.IsNullOrEmpty(notification.Title)) + alertDict["title"] = notification.Title; + if (!string.IsNullOrEmpty(notification.Subtitle)) + alertDict["subtitle"] = notification.Subtitle; + if (!string.IsNullOrEmpty(notification.Content)) + alertDict["body"] = notification.Content; + + var payload = new Dictionary + { + ["topic"] = notification.Topic, + ["aps"] = new Dictionary { - ["topic"] = notification.Topic, - ["aps"] = new Dictionary - { - ["alert"] = new Dictionary - { - ["title"] = notification.Title ?? string.Empty, - ["subtitle"] = notification.Subtitle ?? string.Empty, - ["body"] = notification.Content ?? string.Empty - } - }, - ["sound"] = (notification.Priority > 0 ? "default" : null) ?? string.Empty, - ["mutable-content"] = 1, - ["meta"] = notification.Meta ?? new Dictionary() + ["alert"] = alertDict }, + ["sound"] = (notification.Priority > 0 ? "default" : null) ?? string.Empty, + ["mutable-content"] = 1, + ["meta"] = notification.Meta ?? new Dictionary() + }; + + await _apns.SendAsync( + payload, deviceToken: subscription.DeviceToken, apnsId: notification.Id.ToString(), apnsPriority: notification.Priority, diff --git a/DysonNetwork.Sphere/Activity/ActivityService.cs b/DysonNetwork.Sphere/Activity/ActivityService.cs index 47ef8e5..9596cb3 100644 --- a/DysonNetwork.Sphere/Activity/ActivityService.cs +++ b/DysonNetwork.Sphere/Activity/ActivityService.cs @@ -18,7 +18,6 @@ public class ActivityReaderService(AppDatabase db, PostService ps) if (postsId.Count > 0) { var posts = await db.Posts.Where(e => postsId.Contains(e.Id)) - .Include(e => e.Publisher) .Include(e => e.ThreadedPost) .Include(e => e.ForwardedPost) .Include(e => e.Attachments) @@ -27,6 +26,7 @@ public class ActivityReaderService(AppDatabase db, PostService ps) .FilterWithVisibility(currentUser, userFriends) .ToListAsync(); posts = PostService.TruncatePostContent(posts); + posts = await ps.LoadPublishers(posts); var reactionMaps = await ps.GetPostReactionMapBatch(postsId); foreach (var post in posts) diff --git a/DysonNetwork.Sphere/Post/Post.cs b/DysonNetwork.Sphere/Post/Post.cs index f22a337..7a39f47 100644 --- a/DysonNetwork.Sphere/Post/Post.cs +++ b/DysonNetwork.Sphere/Post/Post.cs @@ -54,7 +54,9 @@ public class Post : ModelBase [JsonIgnore] public NpgsqlTsVector SearchVector { get; set; } = null!; + public Guid PublisherId { get; set; } public Publisher.Publisher Publisher { get; set; } = null!; + public ICollection Reactions { get; set; } = new List(); public ICollection Tags { get; set; } = new List(); public ICollection Categories { get; set; } = new List(); diff --git a/DysonNetwork.Sphere/Post/PostService.cs b/DysonNetwork.Sphere/Post/PostService.cs index f4785a4..562dbda 100644 --- a/DysonNetwork.Sphere/Post/PostService.cs +++ b/DysonNetwork.Sphere/Post/PostService.cs @@ -275,13 +275,12 @@ public class PostService( public async Task> LoadPublishers(List posts) { var publisherIds = posts - .Where(e => e.Publisher.AccountId != null) .SelectMany(e => [ - e.Publisher.Id, - e.RepliedPost?.Publisher.Id, - e.ForwardedPost?.Publisher.Id, - e.ThreadedPost?.Publisher.Id + e.PublisherId, + e.RepliedPost?.PublisherId, + e.ForwardedPost?.PublisherId, + e.ThreadedPost?.PublisherId ]) .Where(e => e != null) .Distinct() @@ -289,24 +288,24 @@ public class PostService( if (publisherIds.Count == 0) return posts; var publishers = await db.Publishers - .Where(e => e.AccountId != null && publisherIds.Contains(e.AccountId.Value)) - .ToDictionaryAsync(e => e.AccountId!.Value); + .Where(e => publisherIds.Contains(e.Id)) + .ToDictionaryAsync(e => e.Id); foreach (var post in posts) { - if (publishers.TryGetValue(post.Publisher.Id, out var publisher)) + if (publishers.TryGetValue(post.PublisherId, out var publisher)) post.Publisher = publisher; - if (post.RepliedPost?.Publisher.Id != null && - publishers.TryGetValue(post.RepliedPost.Publisher.Id, out var repliedPublisher)) + if (post.RepliedPost?.PublisherId != null && + publishers.TryGetValue(post.RepliedPost.PublisherId, out var repliedPublisher)) post.RepliedPost.Publisher = repliedPublisher; - if (post.ForwardedPost?.Publisher.Id != null && - publishers.TryGetValue(post.ForwardedPost.Publisher.Id, out var forwardedPublisher)) + if (post.ForwardedPost?.PublisherId != null && + publishers.TryGetValue(post.ForwardedPost.PublisherId, out var forwardedPublisher)) post.ForwardedPost.Publisher = forwardedPublisher; - if (post.ThreadedPost?.Publisher.Id != null && - publishers.TryGetValue(post.ThreadedPost.Publisher.Id, out var threadedPublisher)) + if (post.ThreadedPost?.PublisherId != null && + publishers.TryGetValue(post.ThreadedPost.PublisherId, out var threadedPublisher)) post.ThreadedPost.Publisher = threadedPublisher; }