♻️ 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",
Title = localizer["SubscriptionAppliedTitle", humanReadableName],
Body = localizer["SubscriptionAppliedBody", duration, humanReadableName],
Meta = GrpcTypeHelper.ConvertObjectToByteString(new Dictionary<string, object>
{
["subscription_id"] = subscription.Id.ToString()
}),
IsSavable = true
};
notification.Meta.Add("subscription_id", Value.ForString(subscription.Id.ToString()));
await pusher.SendPushNotificationToUserAsync(
new SendPushNotificationToUserRequest
{

View File

@@ -91,7 +91,7 @@ public class PusherServiceGrpc(
request.Notification.Title,
request.Notification.Subtitle,
request.Notification.Body,
GrpcTypeHelper.ConvertFromValueMap(request.Notification.Meta),
GrpcTypeHelper.ConvertByteStringToObject<Dictionary<string, object?>>(request.Notification.Meta) ?? [],
request.Notification.ActionUri,
request.Notification.IsSilent,
request.Notification.IsSavable
@@ -108,7 +108,8 @@ public class PusherServiceGrpc(
Title = request.Notification.Title,
Subtitle = request.Notification.Subtitle,
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)
notification.Meta["action_uri"] = request.Notification.ActionUri;

View File

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

View File

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

View File

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