diff --git a/DysonNetwork.Pass/Resources/Localization/NotificationResource.Designer.cs b/DysonNetwork.Pass/Resources/Localization/NotificationResource.Designer.cs index 113661ea..1bc64f71 100644 --- a/DysonNetwork.Pass/Resources/Localization/NotificationResource.Designer.cs +++ b/DysonNetwork.Pass/Resources/Localization/NotificationResource.Designer.cs @@ -105,18 +105,6 @@ namespace DysonNetwork.Sphere.Resources.Localization { } } - internal static string PostReplyBody { - get { - return ResourceManager.GetString("PostReplyBody", resourceCulture); - } - } - - internal static string PostReplyContentBody { - get { - return ResourceManager.GetString("PostReplyContentBody", resourceCulture); - } - } - internal static string PostOnlyMedia { get { return ResourceManager.GetString("PostOnlyMedia", resourceCulture); diff --git a/DysonNetwork.Pass/Resources/Localization/NotificationResource.resx b/DysonNetwork.Pass/Resources/Localization/NotificationResource.resx index 62bbfe83..2bb6d4d1 100644 --- a/DysonNetwork.Pass/Resources/Localization/NotificationResource.resx +++ b/DysonNetwork.Pass/Resources/Localization/NotificationResource.resx @@ -53,12 +53,6 @@ {0} replied your post - - {0} replied: {1} - - - {0} replied post {1}: {2} - shared media diff --git a/DysonNetwork.Pass/Resources/Localization/NotificationResource.zh-hans.resx b/DysonNetwork.Pass/Resources/Localization/NotificationResource.zh-hans.resx index 85e58fa2..01a313fc 100644 --- a/DysonNetwork.Pass/Resources/Localization/NotificationResource.zh-hans.resx +++ b/DysonNetwork.Pass/Resources/Localization/NotificationResource.zh-hans.resx @@ -45,12 +45,6 @@ {0} 回复了你的帖子 - - {0}:{1} - - - {0} 回复了帖子 {1}: {2} - 分享媒体 diff --git a/DysonNetwork.Sphere/Post/PostService.cs b/DysonNetwork.Sphere/Post/PostService.cs index 70064804..90e37029 100644 --- a/DysonNetwork.Sphere/Post/PostService.cs +++ b/DysonNetwork.Sphere/Post/PostService.cs @@ -57,6 +57,7 @@ public partial class PostService( { continue; } + if (plainText.Length > maxLength) { item.Content = plainText.Substring(0, maxLength); @@ -81,6 +82,7 @@ public partial class PostService( { continue; } + if (plainText.Length > embedMaxLength) { item.RepliedPost.Content = plainText.Substring(0, embedMaxLength); @@ -105,6 +107,7 @@ public partial class PostService( { continue; } + if (plainText.Length > embedMaxLength) { item.ForwardedPost.Content = plainText.Substring(0, embedMaxLength); @@ -124,8 +127,9 @@ public partial class PostService( ? string.Concat(post.Content.AsSpan(0, 97), "...") : post.Content; var title = post.Title ?? (post.Content?.Length >= 10 ? post.Content[..10] + "..." : post.Content); - content ??= localizer["PostOnlyMedia"]; title ??= localizer["PostOnlyMedia"]; + if (string.IsNullOrWhiteSpace(content)) + content = localizer["PostOnlyMedia"]; return (title, content); } @@ -219,13 +223,13 @@ public partial class PostService( using var scope = factory.CreateScope(); var pub = scope.ServiceProvider.GetRequiredService(); var nty = scope.ServiceProvider.GetRequiredService(); - var accounts = scope.ServiceProvider.GetRequiredService(); + var notifyTargets = scope.ServiceProvider.GetRequiredService(); try { var members = await pub.GetPublisherMembers(post.RepliedPost.PublisherId!.Value); var queryRequest = new GetAccountBatchRequest(); queryRequest.Id.AddRange(members.Select(m => m.AccountId.ToString())); - var queryResponse = await accounts.GetAccountBatchAsync(queryRequest); + var queryResponse = await notifyTargets.GetAccountBatchAsync(queryRequest); foreach (var member in queryResponse.Accounts) { if (member is null) continue; @@ -238,10 +242,7 @@ public partial class PostService( { Topic = "post.replies", Title = localizer["PostReplyTitle", sender!.Nick], - Body = string.IsNullOrWhiteSpace(post.Title) - ? localizer["PostReplyBody", sender.Nick, ChopPostForNotification(post).content] - : localizer["PostReplyContentBody", sender.Nick, post.Title, - ChopPostForNotification(post).content], + Body = ChopPostForNotification(post).content, IsSavable = true, ActionUri = $"/posts/{post.Id}" } @@ -649,7 +650,8 @@ public partial class PostService( : await objFactory.GetLocalActorAsync(accountPublisher.Id); var publisherActor = await objFactory.GetLocalActorAsync(post.PublisherId.Value); - if (accountActor != null && publisherActor != null && reaction.Attitude == Shared.Models.PostReactionAttitude.Positive) + if (accountActor != null && publisherActor != null && + reaction.Attitude == Shared.Models.PostReactionAttitude.Positive) { if (!isRemoving) { @@ -1239,4 +1241,4 @@ public static class PostQueryExtensions (e.Publisher.AccountId != null && userFriends.Contains(e.Publisher.AccountId.Value)) || publishersId.Contains(e.PublisherId.Value)); } -} +} \ No newline at end of file diff --git a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs index 2d2cd62e..b83a6ef9 100644 --- a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs +++ b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionService.cs @@ -26,9 +26,9 @@ public class PublisherSubscriptionService( public async Task SubscriptionExistsAsync(Guid accountId, Guid publisherId) { return await db.PublisherSubscriptions - .AnyAsync(ps => ps.AccountId == accountId && - ps.PublisherId == publisherId && - ps.Status == PublisherSubscriptionStatus.Active); + .AnyAsync(p => p.AccountId == accountId && + p.PublisherId == publisherId && + p.Status == PublisherSubscriptionStatus.Active); } /// @@ -40,8 +40,8 @@ public class PublisherSubscriptionService( public async Task GetSubscriptionAsync(Guid accountId, Guid publisherId) { return await db.PublisherSubscriptions - .Include(ps => ps.Publisher) - .FirstOrDefaultAsync(ps => ps.AccountId == accountId && ps.PublisherId == publisherId); + .Include(p => p.Publisher) + .FirstOrDefaultAsync(p => p.AccountId == accountId && p.PublisherId == publisherId); } /// @@ -51,6 +51,8 @@ public class PublisherSubscriptionService( /// The number of subscribers notified public async Task NotifySubscriberPost(SnPost post) { + if (!post.PublisherId.HasValue || post.Publisher is null) + return 0; if (post.RepliedPostId is not null) return 0; if (post.Visibility != Shared.Models.PostVisibility.Public) @@ -63,7 +65,7 @@ public class PublisherSubscriptionService( var data = new Dictionary { ["post_id"] = post.Id, - ["publisher_id"] = post.Publisher.Id.ToString() + ["publisher_id"] = post.PublisherId.Value.ToString() }; if (post.Attachments.Any(p => p.MimeType?.StartsWith("image/") ?? false)) @@ -71,7 +73,7 @@ public class PublisherSubscriptionService( 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; + if (post.Publisher?.Picture is not null) data["pfp"] = post.Publisher.Picture.Id; // Gather subscribers var subscribers = await db.PublisherSubscriptions @@ -118,7 +120,7 @@ public class PublisherSubscriptionService( var notification = new PushNotification { Topic = "posts.new", - Title = localizer["PostSubscriptionTitle", post.Publisher.Nick, title], + Title = localizer["PostSubscriptionTitle", post.Publisher!.Nick, title], Body = message, Meta = GrpcTypeHelper.ConvertObjectToByteString(data), IsSavable = true, @@ -147,8 +149,8 @@ public class PublisherSubscriptionService( public async Task> GetAccountSubscriptionsAsync(Guid accountId) { return await db.PublisherSubscriptions - .Include(ps => ps.Publisher) - .Where(ps => ps.AccountId == accountId && ps.Status == PublisherSubscriptionStatus.Active) + .Include(p => p.Publisher) + .Where(p => p.AccountId == accountId && p.Status == PublisherSubscriptionStatus.Active) .ToListAsync(); } @@ -160,7 +162,8 @@ public class PublisherSubscriptionService( public async Task> GetPublisherSubscribersAsync(Guid publisherId) { return await db.PublisherSubscriptions - .Where(ps => ps.PublisherId == publisherId && ps.Status == PublisherSubscriptionStatus.Active) + .Where(p => p.PublisherId == publisherId) + .Where(p => p.Status == PublisherSubscriptionStatus.Active) .ToListAsync(); }