From bc95cb5331347ce263c61ce4e19e750a5a00b2f3 Mon Sep 17 00:00:00 2001 From: Artemy <109195690+stalcker2288969@users.noreply.github.com> Date: Sat, 7 Mar 2026 21:36:27 +0700 Subject: [PATCH] push was updated --- .../Hubs/Infrastructure/ChatNotificationService.cs | 14 ++++++++++++-- .../PushNotifications/IPushNotificationService.cs | 6 +++--- .../PushNotifications/Models/PushMessage.cs | 1 + .../Providers/FirebasePushProvider.cs | 9 +++++++-- .../PushNotifications/PushNotificationService.cs | 9 ++++++--- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Govor.API/Hubs/Infrastructure/ChatNotificationService.cs b/Govor.API/Hubs/Infrastructure/ChatNotificationService.cs index 5d0486b..fa0cf3e 100644 --- a/Govor.API/Hubs/Infrastructure/ChatNotificationService.cs +++ b/Govor.API/Hubs/Infrastructure/ChatNotificationService.cs @@ -54,8 +54,18 @@ public class ChatNotificationService : IChatNotificationService var profile = await _profileService.GetUserProfileAsync(message.SenderId); var title = profile.Username; - - await _notificationService.SendToUserAsync(userId, title,text, "chat_messages"); + Dictionary data = new Dictionary(); + + data["chatId"] = message.RecipientId.ToString(); + data["isGroup"] = message.RecipientType == RecipientType.Group ? "true" : "false"; + + await _notificationService.SendToUserAsync( + userId, + title, + text, + "chat_messages", + $"private_chat_{message.RecipientId}", + data); } public async Task NotifyMessageRemovedAsync(MessageRemovedResponse response) diff --git a/Govor.Application/Interfaces/PushNotifications/IPushNotificationService.cs b/Govor.Application/Interfaces/PushNotifications/IPushNotificationService.cs index 8a7c9b5..e7872fa 100644 --- a/Govor.Application/Interfaces/PushNotifications/IPushNotificationService.cs +++ b/Govor.Application/Interfaces/PushNotifications/IPushNotificationService.cs @@ -2,9 +2,9 @@ namespace Govor.Application.Interfaces.PushNotifications; public interface IPushNotificationService { - Task SendToUserAsync(Guid userId, string title, string body, string channelId, Dictionary? data = null); + Task SendToUserAsync(Guid userId, string title, string body, string channelId, string tag = "", Dictionary? data = null); - Task SendToUsersAsync(IEnumerable userIds, string title, string body, string channelId, Dictionary? data = null); + Task SendToUsersAsync(IEnumerable userIds, string title, string body, string channelId, string tag = "", Dictionary? data = null); - Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, Dictionary? data = null); + Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, string tag = "", Dictionary? data = null); } \ No newline at end of file diff --git a/Govor.Application/Interfaces/PushNotifications/Models/PushMessage.cs b/Govor.Application/Interfaces/PushNotifications/Models/PushMessage.cs index 315bc51..ae200be 100644 --- a/Govor.Application/Interfaces/PushNotifications/Models/PushMessage.cs +++ b/Govor.Application/Interfaces/PushNotifications/Models/PushMessage.cs @@ -4,6 +4,7 @@ public class PushMessage { public string Title { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; + public string Tag { get; set; } = string.Empty; public Dictionary Data { get; set; } = new(); public string? ChannelId { get; set; } = "chat_messages"; //for Android } \ No newline at end of file diff --git a/Govor.Application/Services/PushNotifications/Providers/FirebasePushProvider.cs b/Govor.Application/Services/PushNotifications/Providers/FirebasePushProvider.cs index 4107a6d..5d7ac4b 100644 --- a/Govor.Application/Services/PushNotifications/Providers/FirebasePushProvider.cs +++ b/Govor.Application/Services/PushNotifications/Providers/FirebasePushProvider.cs @@ -47,7 +47,8 @@ public class FirebasePushProvider : IPushNotificationProvider Priority = Priority.High, Notification = new AndroidNotification { - ChannelId = message.ChannelId ?? "chat_messages" + ChannelId = message.ChannelId ?? "chat_messages", + Tag = message.Tag, } } : null }; @@ -96,7 +97,11 @@ public class FirebasePushProvider : IPushNotificationProvider msg.Android = new AndroidConfig { Priority = Priority.High, - Notification = new AndroidNotification { ChannelId = pm.ChannelId } + Notification = new AndroidNotification + { + ChannelId = pm.ChannelId, + Tag = pm.Tag, + } }; } diff --git a/Govor.Application/Services/PushNotifications/PushNotificationService.cs b/Govor.Application/Services/PushNotifications/PushNotificationService.cs index 200732c..4fa824f 100644 --- a/Govor.Application/Services/PushNotifications/PushNotificationService.cs +++ b/Govor.Application/Services/PushNotifications/PushNotificationService.cs @@ -22,7 +22,7 @@ public class PushNotificationService : IPushNotificationService _logger = logger; } - public async Task SendToUserAsync(Guid userId, string title, string body, string channelId, Dictionary? data = null) + public async Task SendToUserAsync(Guid userId, string title, string body, string channelId, string tag = "", Dictionary? data = null) { var tokens = await _tokenRepo.GetActiveTokensAsync(userId); if (tokens.Count == 0) @@ -36,6 +36,7 @@ public class PushNotificationService : IPushNotificationService Title = title, Body = body, Data = data ?? new(), + Tag = tag, ChannelId = channelId }; @@ -48,7 +49,7 @@ public class PushNotificationService : IPushNotificationService } } - public async Task SendToUsersAsync(IEnumerable userIds, string title, string body, string channelId, Dictionary? data = null) + public async Task SendToUsersAsync(IEnumerable userIds, string title, string body, string channelId, string tag = "", Dictionary? data = null) { if (userIds is null) throw new ArgumentNullException(nameof(userIds)); @@ -62,6 +63,7 @@ public class PushNotificationService : IPushNotificationService Title = title, Body = body, Data = data ?? new(), + Tag = tag, ChannelId = channelId }); @@ -72,7 +74,7 @@ public class PushNotificationService : IPushNotificationService } } - public async Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, Dictionary? data = null) + public async Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, string tag = "", Dictionary? data = null) { var token = await _tokenRepo.GetActiveTokenBySessionAsync(sessionId); if(string.IsNullOrEmpty(token)) @@ -83,6 +85,7 @@ public class PushNotificationService : IPushNotificationService Title = title, Body = body, Data = data ?? new(), + Tag = tag, ChannelId = channelId });