2016-08-05 23:59:59 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2017-03-08 21:45:08 -05:00
|
|
|
|
using Bit.Core.Models.Table;
|
2016-08-05 23:59:59 -04:00
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
public class DeviceService : IDeviceService
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IDeviceRepository _deviceRepository;
|
2017-05-26 00:50:27 -04:00
|
|
|
|
private readonly IPushRegistrationService _pushRegistrationService;
|
2016-08-05 23:59:59 -04:00
|
|
|
|
|
|
|
|
|
|
public DeviceService(
|
2017-05-26 00:50:27 -04:00
|
|
|
|
IDeviceRepository deviceRepository,
|
|
|
|
|
|
IPushRegistrationService pushRegistrationService)
|
2016-08-05 23:59:59 -04:00
|
|
|
|
{
|
|
|
|
|
|
_deviceRepository = deviceRepository;
|
2017-05-26 00:50:27 -04:00
|
|
|
|
_pushRegistrationService = pushRegistrationService;
|
2016-08-05 23:59:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SaveAsync(Device device)
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (device.Id == default(Guid))
|
2016-08-05 23:59:59 -04:00
|
|
|
|
{
|
|
|
|
|
|
await _deviceRepository.CreateAsync(device);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
device.RevisionDate = DateTime.UtcNow;
|
|
|
|
|
|
await _deviceRepository.ReplaceAsync(device);
|
|
|
|
|
|
}
|
2017-05-26 00:50:27 -04:00
|
|
|
|
|
2017-08-11 08:57:31 -04:00
|
|
|
|
await _pushRegistrationService.CreateOrUpdateRegistrationAsync(device.PushToken, device.Id.ToString(),
|
|
|
|
|
|
device.UserId.ToString(), device.Identifier, device.Type);
|
2017-05-26 00:50:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task ClearTokenAsync(Device device)
|
|
|
|
|
|
{
|
2017-06-02 16:52:54 -04:00
|
|
|
|
await _deviceRepository.ClearPushTokenAsync(device.Id);
|
2017-08-11 08:57:31 -04:00
|
|
|
|
await _pushRegistrationService.DeleteRegistrationAsync(device.Id.ToString());
|
2017-05-26 00:50:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeleteAsync(Device device)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _deviceRepository.DeleteAsync(device);
|
2017-08-11 08:57:31 -04:00
|
|
|
|
await _pushRegistrationService.DeleteRegistrationAsync(device.Id.ToString());
|
2016-08-05 23:59:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|