♻️ Refactor notification meta

This commit is contained in:
2025-07-29 23:23:40 +08:00
parent 409c83b030
commit 51697c31cb
5 changed files with 10 additions and 6 deletions

View File

@@ -362,9 +362,12 @@ public class SubscriptionService(
Topic = "subscriptions.begun", Topic = "subscriptions.begun",
Title = localizer["SubscriptionAppliedTitle", humanReadableName], Title = localizer["SubscriptionAppliedTitle", humanReadableName],
Body = localizer["SubscriptionAppliedBody", duration, humanReadableName], Body = localizer["SubscriptionAppliedBody", duration, humanReadableName],
Meta = GrpcTypeHelper.ConvertObjectToByteString(new Dictionary<string, object>
{
["subscription_id"] = subscription.Id.ToString()
}),
IsSavable = true IsSavable = true
}; };
notification.Meta.Add("subscription_id", Value.ForString(subscription.Id.ToString()));
await pusher.SendPushNotificationToUserAsync( await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest new SendPushNotificationToUserRequest
{ {

View File

@@ -91,7 +91,7 @@ public class PusherServiceGrpc(
request.Notification.Title, request.Notification.Title,
request.Notification.Subtitle, request.Notification.Subtitle,
request.Notification.Body, request.Notification.Body,
GrpcTypeHelper.ConvertFromValueMap(request.Notification.Meta), GrpcTypeHelper.ConvertByteStringToObject<Dictionary<string, object?>>(request.Notification.Meta) ?? [],
request.Notification.ActionUri, request.Notification.ActionUri,
request.Notification.IsSilent, request.Notification.IsSilent,
request.Notification.IsSavable request.Notification.IsSavable
@@ -108,7 +108,8 @@ public class PusherServiceGrpc(
Title = request.Notification.Title, Title = request.Notification.Title,
Subtitle = request.Notification.Subtitle, Subtitle = request.Notification.Subtitle,
Content = request.Notification.Body, Content = request.Notification.Body,
Meta = GrpcTypeHelper.ConvertFromValueMap(request.Notification.Meta) Meta = GrpcTypeHelper.ConvertByteStringToObject<Dictionary<string, object?>>(request.Notification.Meta) ??
[]
}; };
if (request.Notification.ActionUri is not null) if (request.Notification.ActionUri is not null)
notification.Meta["action_uri"] = request.Notification.ActionUri; notification.Meta["action_uri"] = request.Notification.ActionUri;

View File

@@ -85,7 +85,7 @@ message PushNotification {
string title = 2; string title = 2;
string subtitle = 3; string subtitle = 3;
string body = 4; string body = 4;
map<string, google.protobuf.Value> meta = 5; bytes meta = 5;
optional string action_uri = 6; optional string action_uri = 6;
bool is_silent = 7; bool is_silent = 7;
bool is_savable = 8; bool is_savable = 8;

View File

@@ -241,10 +241,10 @@ public partial class ChatService(
Body = !string.IsNullOrEmpty(message.Content) Body = !string.IsNullOrEmpty(message.Content)
? message.Content[..Math.Min(message.Content.Length, 100)] ? message.Content[..Math.Min(message.Content.Length, 100)]
: "<no content>", : "<no content>",
Meta = GrpcTypeHelper.ConvertObjectToByteString(metaDict),
ActionUri = $"/chat/{room.Id}", ActionUri = $"/chat/{room.Id}",
IsSavable = false, IsSavable = false,
}; };
notification.Meta.Add(GrpcTypeHelper.ConvertToValueMap(metaDict));
List<Account> accountsToNotify = []; List<Account> accountsToNotify = [];
foreach (var member in members) foreach (var member in members)

View File

@@ -78,10 +78,10 @@ public class PublisherSubscriptionService(
Topic = "posts.new", Topic = "posts.new",
Title = localizer["PostSubscriptionTitle", post.Publisher.Name, title], Title = localizer["PostSubscriptionTitle", post.Publisher.Name, title],
Body = message, Body = message,
Meta = GrpcTypeHelper.ConvertObjectToByteString(data),
IsSavable = true, IsSavable = true,
ActionUri = $"/posts/{post.Id}" ActionUri = $"/posts/{post.Id}"
}; };
notification.Meta.Add(GrpcTypeHelper.ConvertToValueMap(data));
// Notify each subscriber // Notify each subscriber
var notifiedCount = 0; var notifiedCount = 0;