1
0
mirror of https://github.com/bitwarden/server synced 2025-12-13 23:03:36 +00:00

added push events and moved cipher writing to cipher service.

This commit is contained in:
Kyle Spearrin
2016-06-29 01:15:37 -04:00
parent afa37f5ab1
commit ef0a808687
8 changed files with 120 additions and 17 deletions

View File

@@ -10,11 +10,40 @@ namespace Bit.Core.Services
public class CipherService : ICipherService
{
private readonly ICipherRepository _cipherRepository;
private readonly IPushService _pushService;
public CipherService(
ICipherRepository cipherRepository)
ICipherRepository cipherRepository,
IPushService pushService)
{
_cipherRepository = cipherRepository;
_pushService = pushService;
}
public async Task SaveAsync(Cipher cipher)
{
if(cipher.Id == default(Guid))
{
await _cipherRepository.CreateAsync(cipher);
// push
await _pushService.PushSyncCipherCreateAsync(cipher);
}
else
{
await _cipherRepository.ReplaceAsync(cipher);
// push
await _pushService.PushSyncCipherUpdateAsync(cipher);
}
}
public async Task DeleteAsync(Cipher cipher)
{
await _cipherRepository.DeleteAsync(cipher);
// push
await _pushService.PushSyncCipherDeleteAsync(cipher);
}
public async Task ImportCiphersAsync(
@@ -46,6 +75,13 @@ namespace Bit.Core.Services
// create all the ciphers
await _cipherRepository.CreateAsync(ciphers);
// push
var userId = folders.FirstOrDefault()?.UserId ?? ciphers.FirstOrDefault()?.UserId;
if(userId.HasValue)
{
await _pushService.PushSyncCiphersAsync(userId.Value);
}
}
}
}