🐛 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 CorePush.Firebase;
|
||||||
using DysonNetwork.Pusher.Connection;
|
using DysonNetwork.Pusher.Connection;
|
||||||
using DysonNetwork.Pusher.Services;
|
using DysonNetwork.Pusher.Services;
|
||||||
using DysonNetwork.Shared.Cache;
|
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
@@ -56,7 +55,7 @@ public class PushService
|
|||||||
_ws = ws;
|
_ws = ws;
|
||||||
_queueService = queueService;
|
_queueService = queueService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_logger.LogInformation("PushService initialized");
|
_logger.LogInformation("PushService initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +263,8 @@ public class PushService
|
|||||||
await DeliverPushNotification(notification);
|
await DeliverPushNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendPushNotificationAsync(PushSubscription subscription, Notification notification, CancellationToken cancellationToken)
|
private async Task SendPushNotificationAsync(PushSubscription subscription, Notification notification,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -361,4 +361,26 @@ public class PushService
|
|||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
$"Successfully pushed notification #{notification.Id} to device {subscription.DeviceId} provider {subscription.Provider}");
|
$"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();
|
||||||
|
}
|
||||||
|
}
|
@@ -105,6 +105,9 @@ public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDev
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
if (request.Notification.IsSavable)
|
||||||
|
await pushService.SaveNotification(notification);
|
||||||
|
|
||||||
await queueService.EnqueuePushNotification(
|
await queueService.EnqueuePushNotification(
|
||||||
notification,
|
notification,
|
||||||
@@ -131,11 +134,15 @@ public override Task<Empty> PushWebSocketPacketToDevice(PushWebSocketPacketToDev
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
var userIds = request.UserIds.Select(Guid.Parse).ToList();
|
||||||
|
if (request.Notification.IsSavable)
|
||||||
|
await pushService.SaveNotification(notification, userIds);
|
||||||
|
|
||||||
var tasks = request.UserIds
|
var tasks = userIds
|
||||||
.Select(userId => queueService.EnqueuePushNotification(
|
.Select(userId => queueService.EnqueuePushNotification(
|
||||||
notification,
|
notification,
|
||||||
Guid.Parse(userId),
|
userId,
|
||||||
request.Notification.IsSavable
|
request.Notification.IsSavable
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@@ -81,7 +81,7 @@ public class QueueBackgroundService(
|
|||||||
switch (message.Type)
|
switch (message.Type)
|
||||||
{
|
{
|
||||||
case QueueMessageType.Email:
|
case QueueMessageType.Email:
|
||||||
await ProcessEmailMessageAsync(message, scope, cancellationToken);
|
await ProcessEmailMessageAsync(message, scope);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QueueMessageType.PushNotification:
|
case QueueMessageType.PushNotification:
|
||||||
@@ -103,8 +103,7 @@ public class QueueBackgroundService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task ProcessEmailMessageAsync(QueueMessage message, IServiceScope scope,
|
private static async Task ProcessEmailMessageAsync(QueueMessage message, IServiceScope scope)
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
var emailService = scope.ServiceProvider.GetRequiredService<EmailService>();
|
var emailService = scope.ServiceProvider.GetRequiredService<EmailService>();
|
||||||
var emailMessage = JsonSerializer.Deserialize<EmailMessage>(message.Data)
|
var emailMessage = JsonSerializer.Deserialize<EmailMessage>(message.Data)
|
||||||
|
Reference in New Issue
Block a user