mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
push was updated
This commit is contained in:
@@ -54,8 +54,18 @@ public class ChatNotificationService : IChatNotificationService
|
|||||||
|
|
||||||
var profile = await _profileService.GetUserProfileAsync(message.SenderId);
|
var profile = await _profileService.GetUserProfileAsync(message.SenderId);
|
||||||
var title = profile.Username;
|
var title = profile.Username;
|
||||||
|
Dictionary<string, string> data = new Dictionary<string, string>();
|
||||||
await _notificationService.SendToUserAsync(userId, title,text, "chat_messages");
|
|
||||||
|
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)
|
public async Task NotifyMessageRemovedAsync(MessageRemovedResponse response)
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ namespace Govor.Application.Interfaces.PushNotifications;
|
|||||||
|
|
||||||
public interface IPushNotificationService
|
public interface IPushNotificationService
|
||||||
{
|
{
|
||||||
Task SendToUserAsync(Guid userId, string title, string body, string channelId, Dictionary<string, string>? data = null);
|
Task SendToUserAsync(Guid userId, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null);
|
||||||
|
|
||||||
Task SendToUsersAsync(IEnumerable<Guid> userIds, string title, string body, string channelId, Dictionary<string, string>? data = null);
|
Task SendToUsersAsync(IEnumerable<Guid> userIds, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null);
|
||||||
|
|
||||||
Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, Dictionary<string, string>? data = null);
|
Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null);
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ public class PushMessage
|
|||||||
{
|
{
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
|
public string Tag { get; set; } = string.Empty;
|
||||||
public Dictionary<string, string> Data { get; set; } = new();
|
public Dictionary<string, string> Data { get; set; } = new();
|
||||||
public string? ChannelId { get; set; } = "chat_messages"; //for Android
|
public string? ChannelId { get; set; } = "chat_messages"; //for Android
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,8 @@ public class FirebasePushProvider : IPushNotificationProvider
|
|||||||
Priority = Priority.High,
|
Priority = Priority.High,
|
||||||
Notification = new AndroidNotification
|
Notification = new AndroidNotification
|
||||||
{
|
{
|
||||||
ChannelId = message.ChannelId ?? "chat_messages"
|
ChannelId = message.ChannelId ?? "chat_messages",
|
||||||
|
Tag = message.Tag,
|
||||||
}
|
}
|
||||||
} : null
|
} : null
|
||||||
};
|
};
|
||||||
@@ -96,7 +97,11 @@ public class FirebasePushProvider : IPushNotificationProvider
|
|||||||
msg.Android = new AndroidConfig
|
msg.Android = new AndroidConfig
|
||||||
{
|
{
|
||||||
Priority = Priority.High,
|
Priority = Priority.High,
|
||||||
Notification = new AndroidNotification { ChannelId = pm.ChannelId }
|
Notification = new AndroidNotification
|
||||||
|
{
|
||||||
|
ChannelId = pm.ChannelId,
|
||||||
|
Tag = pm.Tag,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToUserAsync(Guid userId, string title, string body, string channelId, Dictionary<string, string>? data = null)
|
public async Task SendToUserAsync(Guid userId, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null)
|
||||||
{
|
{
|
||||||
var tokens = await _tokenRepo.GetActiveTokensAsync(userId);
|
var tokens = await _tokenRepo.GetActiveTokensAsync(userId);
|
||||||
if (tokens.Count == 0)
|
if (tokens.Count == 0)
|
||||||
@@ -36,6 +36,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
Title = title,
|
Title = title,
|
||||||
Body = body,
|
Body = body,
|
||||||
Data = data ?? new(),
|
Data = data ?? new(),
|
||||||
|
Tag = tag,
|
||||||
ChannelId = channelId
|
ChannelId = channelId
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToUsersAsync(IEnumerable<Guid> userIds, string title, string body, string channelId, Dictionary<string, string>? data = null)
|
public async Task SendToUsersAsync(IEnumerable<Guid> userIds, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null)
|
||||||
{
|
{
|
||||||
if (userIds is null)
|
if (userIds is null)
|
||||||
throw new ArgumentNullException(nameof(userIds));
|
throw new ArgumentNullException(nameof(userIds));
|
||||||
@@ -62,6 +63,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
Title = title,
|
Title = title,
|
||||||
Body = body,
|
Body = body,
|
||||||
Data = data ?? new(),
|
Data = data ?? new(),
|
||||||
|
Tag = tag,
|
||||||
ChannelId = channelId
|
ChannelId = channelId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, Dictionary<string, string>? data = null)
|
public async Task SendToSessionAsync(Guid sessionId, string title, string body, string channelId, string tag = "", Dictionary<string, string>? data = null)
|
||||||
{
|
{
|
||||||
var token = await _tokenRepo.GetActiveTokenBySessionAsync(sessionId);
|
var token = await _tokenRepo.GetActiveTokenBySessionAsync(sessionId);
|
||||||
if(string.IsNullOrEmpty(token))
|
if(string.IsNullOrEmpty(token))
|
||||||
@@ -83,6 +85,7 @@ public class PushNotificationService : IPushNotificationService
|
|||||||
Title = title,
|
Title = title,
|
||||||
Body = body,
|
Body = body,
|
||||||
Data = data ?? new(),
|
Data = data ?? new(),
|
||||||
|
Tag = tag,
|
||||||
ChannelId = channelId
|
ChannelId = channelId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user