🐛 Fix queue background service in pusher didn't save notification now
This commit is contained in:
@@ -2,7 +2,6 @@ using CorePush.Apple;
|
||||
using CorePush.Firebase;
|
||||
using DysonNetwork.Pusher.Connection;
|
||||
using DysonNetwork.Pusher.Services;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
@@ -264,7 +263,8 @@ public class PushService
|
||||
await DeliverPushNotification(notification);
|
||||
}
|
||||
|
||||
private async Task SendPushNotificationAsync(PushSubscription subscription, Notification notification, CancellationToken cancellationToken)
|
||||
private async Task SendPushNotificationAsync(PushSubscription subscription, Notification notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -361,4 +361,26 @@ public class PushService
|
||||
_logger.LogInformation(
|
||||
$"Successfully pushed notification #{notification.Id} to device {subscription.DeviceId} provider {subscription.Provider}");
|
||||
}
|
||||
|
||||
public async Task SaveNotification(Notification notification)
|
||||
{
|
||||
_db.Notifications.Add(notification);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task SaveNotification(Notification notification, List<Guid> accounts)
|
||||
{
|
||||
_db.Notifications.AddRange(accounts.Select(a => new Notification
|
||||
{
|
||||
AccountId = a,
|
||||
Content = notification.Content,
|
||||
Title = notification.Title,
|
||||
Subtitle = notification.Subtitle,
|
||||
Meta = notification.Meta,
|
||||
Priority = notification.Priority,
|
||||
CreatedAt = notification.CreatedAt,
|
||||
UpdatedAt = notification.UpdatedAt,
|
||||
}));
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
}
|
@@ -106,6 +106,9 @@ public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDev
|
||||
if (request.Notification.ActionUri is not null)
|
||||
notification.Meta["action_uri"] = request.Notification.ActionUri;
|
||||
|
||||
if (request.Notification.IsSavable)
|
||||
await pushService.SaveNotification(notification);
|
||||
|
||||
await queueService.EnqueuePushNotification(
|
||||
notification,
|
||||
Guid.Parse(request.UserId),
|
||||
@@ -132,10 +135,14 @@ public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDev
|
||||
if (request.Notification.ActionUri is not null)
|
||||
notification.Meta["action_uri"] = request.Notification.ActionUri;
|
||||
|
||||
var tasks = request.UserIds
|
||||
var userIds = request.UserIds.Select(Guid.Parse).ToList();
|
||||
if (request.Notification.IsSavable)
|
||||
await pushService.SaveNotification(notification, userIds);
|
||||
|
||||
var tasks = userIds
|
||||
.Select(userId => queueService.EnqueuePushNotification(
|
||||
notification,
|
||||
Guid.Parse(userId),
|
||||
userId,
|
||||
request.Notification.IsSavable
|
||||
));
|
||||
|
||||
|
@@ -81,7 +81,7 @@ public class QueueBackgroundService(
|
||||
switch (message.Type)
|
||||
{
|
||||
case QueueMessageType.Email:
|
||||
await ProcessEmailMessageAsync(message, scope, cancellationToken);
|
||||
await ProcessEmailMessageAsync(message, scope);
|
||||
break;
|
||||
|
||||
case QueueMessageType.PushNotification:
|
||||
@@ -103,8 +103,7 @@ public class QueueBackgroundService(
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ProcessEmailMessageAsync(QueueMessage message, IServiceScope scope,
|
||||
CancellationToken cancellationToken)
|
||||
private static async Task ProcessEmailMessageAsync(QueueMessage message, IServiceScope scope)
|
||||
{
|
||||
var emailService = scope.ServiceProvider.GetRequiredService<EmailService>();
|
||||
var emailMessage = JsonSerializer.Deserialize<EmailMessage>(message.Data)
|
||||
|
Reference in New Issue
Block a user