1
0
mirror of https://github.com/bitwarden/server synced 2026-01-16 07:23:15 +00:00

PM-10600: Revert global push notifications

This commit is contained in:
Maciej Zieniuk
2024-10-22 18:27:18 +01:00
parent 4173fa8e81
commit 3035abfa30
12 changed files with 10 additions and 115 deletions

View File

@@ -93,21 +93,7 @@ public static class HubHelpers
var syncNotification =
JsonSerializer.Deserialize<PushNotificationData<SyncNotificationPushNotification>>(
notificationJson, _deserializerOptions);
if (syncNotification.Payload.Global)
{
if (syncNotification.Payload.ClientType == ClientType.All)
{
await hubContext.Clients.All.SendAsync(_receiveMessageMethod, syncNotification,
cancellationToken);
}
else
{
await hubContext.Clients
.Group(NotificationsHub.GetGlobalGroup(syncNotification.Payload.ClientType))
.SendAsync(_receiveMessageMethod, syncNotification, cancellationToken);
}
}
else if (syncNotification.Payload.UserId.HasValue)
if (syncNotification.Payload.UserId.HasValue)
{
if (syncNotification.Payload.ClientType == ClientType.All)
{

View File

@@ -24,14 +24,9 @@ public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub
await currentContext.BuildAsync(Context.User, _globalSettings);
var clientType = DeviceTypes.ToClientType(currentContext.DeviceType);
if (clientType != ClientType.All)
if (clientType != ClientType.All && currentContext.UserId.HasValue)
{
await Groups.AddToGroupAsync(Context.ConnectionId, GetGlobalGroup(clientType));
if (currentContext.UserId.HasValue)
{
await Groups.AddToGroupAsync(Context.ConnectionId,
GetUserGroup(currentContext.UserId.Value, clientType));
}
await Groups.AddToGroupAsync(Context.ConnectionId, GetUserGroup(currentContext.UserId.Value, clientType));
}
if (currentContext.Organizations != null)
@@ -56,14 +51,10 @@ public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub
await currentContext.BuildAsync(Context.User, _globalSettings);
var clientType = DeviceTypes.ToClientType(currentContext.DeviceType);
if (clientType != ClientType.All)
if (clientType != ClientType.All && currentContext.UserId.HasValue)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, GetGlobalGroup(clientType));
if (currentContext.UserId.HasValue)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId,
GetUserGroup(currentContext.UserId.Value, clientType));
}
await Groups.RemoveFromGroupAsync(Context.ConnectionId,
GetUserGroup(currentContext.UserId.Value, clientType));
}
if (currentContext.Organizations != null)
@@ -82,11 +73,6 @@ public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub
await base.OnDisconnectedAsync(exception);
}
public static string GetGlobalGroup(ClientType clientType)
{
return $"ClientType_{clientType}";
}
public static string GetUserGroup(Guid userId, ClientType clientType)
{
return $"UserClientType_{userId}_{clientType}";