using Bit.Core.Enums; using Bit.Core.IdentityServer; using Bit.Core.Models.Api; using Bit.Core.Settings; using Microsoft.Extensions.Logging; namespace Bit.Core.Services; public class RelayPushRegistrationService : BaseIdentityClientService, IPushRegistrationService { public RelayPushRegistrationService( IHttpClientFactory httpFactory, GlobalSettings globalSettings, ILogger logger) : base( httpFactory, globalSettings.PushRelayBaseUri, globalSettings.Installation.IdentityUri, ApiScopes.ApiPush, $"installation.{globalSettings.Installation.Id}", globalSettings.Installation.Key, logger) { } public async Task CreateOrUpdateRegistrationAsync(string pushToken, string deviceId, string userId, string identifier, DeviceType type) { var requestModel = new PushRegistrationRequestModel { DeviceId = deviceId, Identifier = identifier, PushToken = pushToken, Type = type, UserId = userId }; await SendAsync(HttpMethod.Post, "push/register", requestModel); } public async Task DeleteRegistrationAsync(string deviceId, DeviceType type) { var requestModel = new PushDeviceRequestModel { Id = deviceId, Type = type, }; await SendAsync(HttpMethod.Post, "push/delete", requestModel); } public async Task AddUserRegistrationOrganizationAsync( IEnumerable> devices, string organizationId) { if (!devices.Any()) { return; } var requestModel = new PushUpdateRequestModel(devices, organizationId); await SendAsync(HttpMethod.Put, "push/add-organization", requestModel); } public async Task DeleteUserRegistrationOrganizationAsync( IEnumerable> devices, string organizationId) { if (!devices.Any()) { return; } var requestModel = new PushUpdateRequestModel(devices, organizationId); await SendAsync(HttpMethod.Put, "push/delete-organization", requestModel); } }