✨ Post awarded notification
This commit is contained in:
@@ -5,6 +5,7 @@ using DysonNetwork.Shared;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Data;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using DysonNetwork.Sphere.WebReader;
|
||||
using DysonNetwork.Sphere.Localization;
|
||||
using DysonNetwork.Sphere.Poll;
|
||||
@@ -24,6 +25,7 @@ public partial class PostService(
|
||||
ILogger<PostService> logger,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
PusherService.PusherServiceClient pusher,
|
||||
PollService polls,
|
||||
Publisher.PublisherService ps,
|
||||
WebReaderService reader
|
||||
@@ -903,6 +905,9 @@ public partial class PostService(
|
||||
string? message
|
||||
)
|
||||
{
|
||||
var post = await db.Posts.Where(p => p.Id == postId).FirstOrDefaultAsync();
|
||||
if (post is null) throw new InvalidOperationException("Post not found");
|
||||
|
||||
var award = new PostAward
|
||||
{
|
||||
Amount = amount,
|
||||
@@ -920,6 +925,51 @@ public partial class PostService(
|
||||
await db.Posts.Where(p => p.Id == postId)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(p => p.AwardedScore, p => p.AwardedScore + delta));
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
using var scope = factory.CreateScope();
|
||||
var pub = scope.ServiceProvider.GetRequiredService<Publisher.PublisherService>();
|
||||
var nty = scope.ServiceProvider.GetRequiredService<PusherService.PusherServiceClient>();
|
||||
var accounts = scope.ServiceProvider.GetRequiredService<AccountService.AccountServiceClient>();
|
||||
var accountsHelper = scope.ServiceProvider.GetRequiredService<AccountClientHelper>();
|
||||
try
|
||||
{
|
||||
var sender = await accountsHelper.GetAccount(accountId);
|
||||
|
||||
var members = await pub.GetPublisherMembers(post.PublisherId);
|
||||
var queryRequest = new GetAccountBatchRequest();
|
||||
queryRequest.Id.AddRange(members.Select(m => m.AccountId.ToString()));
|
||||
var queryResponse = await accounts.GetAccountBatchAsync(queryRequest);
|
||||
foreach (var member in queryResponse.Accounts)
|
||||
{
|
||||
if (member is null) continue;
|
||||
CultureService.SetCultureInfo(member);
|
||||
|
||||
await nty.SendPushNotificationToUserAsync(
|
||||
new SendPushNotificationToUserRequest
|
||||
{
|
||||
UserId = member.Id,
|
||||
Notification = new PushNotification
|
||||
{
|
||||
Topic = "posts.awards.new",
|
||||
Title = localizer["PostAwardedTitle", sender.Nick],
|
||||
Body = string.IsNullOrWhiteSpace(post.Title)
|
||||
? localizer["PostAwardedBody", sender.Nick, amount]
|
||||
: localizer["PostAwardedContentBody", sender.Nick, amount,
|
||||
post.Title],
|
||||
IsSavable = true,
|
||||
ActionUri = $"/posts/{post.Id}"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"Error when sending post awarded notification: {ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
});
|
||||
|
||||
return award;
|
||||
}
|
||||
}
|
||||
|
@@ -158,5 +158,23 @@ namespace DysonNetwork.Sphere.Resources.Localization {
|
||||
return ResourceManager.GetString("OrderPaidBody", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string PostAwardedTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("PostAwardedTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string PostAwardedBody {
|
||||
get {
|
||||
return ResourceManager.GetString("PostAwardedBody", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string PostAwardedContentBody {
|
||||
get {
|
||||
return ResourceManager.GetString("PostAwardedContentBody", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -80,4 +80,13 @@
|
||||
<data name="OrderPaidBody" xml:space="preserve">
|
||||
<value>{0} {1} was removed from your wallet to pay {2}</value>
|
||||
</data>
|
||||
<data name="PostAwardedTitle" xml:space="preserve">
|
||||
<value>{0} awarded your post</value>
|
||||
</data>
|
||||
<data name="PostAwardedBody" xml:space="preserve">
|
||||
<value>{0} added {1} points to your post</value>
|
||||
</data>
|
||||
<data name="PostAwardedContentBody" xml:space="preserve">
|
||||
<value>{0} added {1} points to your post {2}</value>
|
||||
</data>
|
||||
</root>
|
@@ -72,4 +72,13 @@
|
||||
<data name="OrderPaidBody" xml:space="preserve">
|
||||
<value>{0} {1} 已从你的帐户中扣除来支付 {2}</value>
|
||||
</data>
|
||||
<data name="PostAwardedTitle" xml:space="preserve">
|
||||
<value>{0} 赞赏了你的帖子</value>
|
||||
</data>
|
||||
<data name="PostAwardedContentBody" xml:space="preserve">
|
||||
<value>{0} 给你的帖子 {2} 添加了 {1} 分</value>
|
||||
</data>
|
||||
<data name="PostAwardedBody" xml:space="preserve">
|
||||
<value>{0} 给你的帖子添加了 {1} 分</value>
|
||||
</data>
|
||||
</root>
|
@@ -157,7 +157,7 @@
|
||||
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FEmailResource/@EntryIndexedValue">False</s:Boolean>
|
||||
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FNotificationResource/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FNotificationResource/@EntryIndexedValue">False</s:Boolean>
|
||||
|
||||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=DysonNetwork_002EPass_002FResources_002FLocalization_002FSharedResource/@EntryIndexedValue">False</s:Boolean>
|
||||
|
||||
|
Reference in New Issue
Block a user