mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
PM-10564: Push notification updates to other clients
When a notification is updated, marked as read or deleted, a push notification is sent with updated push type event. The push notification includes the ReadDate and DeletedDate fields.
This commit is contained in:
@ -37,7 +37,7 @@ public class CreateNotificationCommand : ICreateNotificationCommand
|
||||
|
||||
var newNotification = await _notificationRepository.CreateAsync(notification);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationAsync(newNotification);
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(newNotification, null);
|
||||
|
||||
return newNotification;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@ -16,16 +17,19 @@ public class CreateNotificationStatusCommand : ICreateNotificationStatusCommand
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INotificationRepository _notificationRepository;
|
||||
private readonly INotificationStatusRepository _notificationStatusRepository;
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
|
||||
public CreateNotificationStatusCommand(ICurrentContext currentContext,
|
||||
IAuthorizationService authorizationService,
|
||||
INotificationRepository notificationRepository,
|
||||
INotificationStatusRepository notificationStatusRepository)
|
||||
INotificationStatusRepository notificationStatusRepository,
|
||||
IPushNotificationService pushNotificationService)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_authorizationService = authorizationService;
|
||||
_notificationRepository = notificationRepository;
|
||||
_notificationStatusRepository = notificationStatusRepository;
|
||||
_pushNotificationService = pushNotificationService;
|
||||
}
|
||||
|
||||
public async Task<NotificationStatus> CreateAsync(NotificationStatus notificationStatus)
|
||||
@ -42,6 +46,10 @@ public class CreateNotificationStatusCommand : ICreateNotificationStatusCommand
|
||||
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User, notificationStatus,
|
||||
NotificationStatusOperations.Create);
|
||||
|
||||
return await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, newNotificationStatus);
|
||||
|
||||
return newNotificationStatus;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@ -16,16 +17,19 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INotificationRepository _notificationRepository;
|
||||
private readonly INotificationStatusRepository _notificationStatusRepository;
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
|
||||
public MarkNotificationDeletedCommand(ICurrentContext currentContext,
|
||||
IAuthorizationService authorizationService,
|
||||
INotificationRepository notificationRepository,
|
||||
INotificationStatusRepository notificationStatusRepository)
|
||||
INotificationStatusRepository notificationStatusRepository,
|
||||
IPushNotificationService pushNotificationService)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_authorizationService = authorizationService;
|
||||
_notificationRepository = notificationRepository;
|
||||
_notificationStatusRepository = notificationStatusRepository;
|
||||
_pushNotificationService = pushNotificationService;
|
||||
}
|
||||
|
||||
public async Task MarkDeletedAsync(Guid notificationId)
|
||||
@ -59,7 +63,9 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
|
||||
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User, notificationStatus,
|
||||
NotificationStatusOperations.Create);
|
||||
|
||||
await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, newNotificationStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -69,6 +75,8 @@ public class MarkNotificationDeletedCommand : IMarkNotificationDeletedCommand
|
||||
notificationStatus.DeletedDate = DateTime.UtcNow;
|
||||
|
||||
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, notificationStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@ -16,16 +17,19 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INotificationRepository _notificationRepository;
|
||||
private readonly INotificationStatusRepository _notificationStatusRepository;
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
|
||||
public MarkNotificationReadCommand(ICurrentContext currentContext,
|
||||
IAuthorizationService authorizationService,
|
||||
INotificationRepository notificationRepository,
|
||||
INotificationStatusRepository notificationStatusRepository)
|
||||
INotificationStatusRepository notificationStatusRepository,
|
||||
IPushNotificationService pushNotificationService)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_authorizationService = authorizationService;
|
||||
_notificationRepository = notificationRepository;
|
||||
_notificationStatusRepository = notificationStatusRepository;
|
||||
_pushNotificationService = pushNotificationService;
|
||||
}
|
||||
|
||||
public async Task MarkReadAsync(Guid notificationId)
|
||||
@ -59,7 +63,9 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
|
||||
await _authorizationService.AuthorizeOrThrowAsync(_currentContext.HttpContext.User, notificationStatus,
|
||||
NotificationStatusOperations.Create);
|
||||
|
||||
await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
var newNotificationStatus = await _notificationStatusRepository.CreateAsync(notificationStatus);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, newNotificationStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -69,6 +75,8 @@ public class MarkNotificationReadCommand : IMarkNotificationReadCommand
|
||||
notificationStatus.ReadDate = DateTime.UtcNow;
|
||||
|
||||
await _notificationStatusRepository.UpdateAsync(notificationStatus);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, notificationStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Bit.Core.NotificationCenter.Authorization;
|
||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
@ -15,14 +16,17 @@ public class UpdateNotificationCommand : IUpdateNotificationCommand
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INotificationRepository _notificationRepository;
|
||||
private readonly IPushNotificationService _pushNotificationService;
|
||||
|
||||
public UpdateNotificationCommand(ICurrentContext currentContext,
|
||||
IAuthorizationService authorizationService,
|
||||
INotificationRepository notificationRepository)
|
||||
INotificationRepository notificationRepository,
|
||||
IPushNotificationService pushNotificationService)
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_authorizationService = authorizationService;
|
||||
_notificationRepository = notificationRepository;
|
||||
_pushNotificationService = pushNotificationService;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Notification notificationToUpdate)
|
||||
@ -43,5 +47,7 @@ public class UpdateNotificationCommand : IUpdateNotificationCommand
|
||||
notification.RevisionDate = DateTime.UtcNow;
|
||||
|
||||
await _notificationRepository.ReplaceAsync(notification);
|
||||
|
||||
await _pushNotificationService.PushSyncNotificationCreateAsync(notification, null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user