Skip to content

Commit e04ee3d

Browse files
committed
chore: restore original order of members of PushService
1 parent 25d9748 commit e04ee3d

File tree

1 file changed

+50
-50
lines changed
  • Modules/Devices/src/Devices.Infrastructure/PushNotifications

1 file changed

+50
-50
lines changed

Modules/Devices/src/Devices.Infrastructure/PushNotifications/PushService.cs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace Backbone.Modules.Devices.Infrastructure.PushNotifications;
1515

1616
public class PushService : IPushNotificationRegistrationService, IPushNotificationSender
1717
{
18-
private readonly IIdentitiesRepository _identitiesRepository;
18+
private readonly IPnsRegistrationsRepository _pnsRegistrationsRepository;
1919
private readonly ILogger<PushService> _logger;
20-
private readonly IPushNotificationTextProvider _notificationTextProvider;
2120
private readonly PnsConnectorFactory _pnsConnectorFactory;
22-
private readonly IPnsRegistrationsRepository _pnsRegistrationsRepository;
21+
private readonly IPushNotificationTextProvider _notificationTextProvider;
22+
private readonly IIdentitiesRepository _identitiesRepository;
2323

2424
public PushService(IPnsRegistrationsRepository pnsRegistrationsRepository, PnsConnectorFactory pnsConnectorFactory, ILogger<PushService> logger,
2525
IPushNotificationTextProvider notificationTextProvider, IIdentitiesRepository identitiesRepository)
@@ -31,48 +31,6 @@ public PushService(IPnsRegistrationsRepository pnsRegistrationsRepository, PnsCo
3131
_identitiesRepository = identitiesRepository;
3232
}
3333

34-
public async Task<DevicePushIdentifier> UpdateRegistration(IdentityAddress address, DeviceId deviceId, PnsHandle handle, string appId, PushEnvironment environment,
35-
CancellationToken cancellationToken)
36-
{
37-
var registration = await _pnsRegistrationsRepository.FindByDeviceId(deviceId, cancellationToken, track: true);
38-
var pnsConnector = _pnsConnectorFactory.CreateFor(handle.Platform);
39-
40-
if (registration != null)
41-
{
42-
registration.Update(handle, appId, environment);
43-
pnsConnector.ValidateRegistration(registration);
44-
45-
await _pnsRegistrationsRepository.Update(registration, cancellationToken);
46-
47-
_logger.LogTrace("Device successfully updated.");
48-
}
49-
else
50-
{
51-
registration = new PnsRegistration(address, deviceId, handle, appId, environment);
52-
pnsConnector.ValidateRegistration(registration);
53-
54-
try
55-
{
56-
await _pnsRegistrationsRepository.Add(registration, cancellationToken);
57-
_logger.LogTrace("New device successfully registered.");
58-
}
59-
catch (InfrastructureException exception) when (exception.Code == InfrastructureErrors.UniqueKeyViolation().Code)
60-
{
61-
_logger.LogInformation(exception, "This exception can be ignored. It is only thrown in case of a concurrent registration request from multiple devices.");
62-
}
63-
}
64-
65-
return registration.DevicePushIdentifier;
66-
}
67-
68-
public async Task DeleteRegistration(DeviceId deviceId, CancellationToken cancellationToken)
69-
{
70-
var numberOfDeletedDevices = await _pnsRegistrationsRepository.Delete([deviceId], cancellationToken);
71-
72-
if (numberOfDeletedDevices == 1)
73-
_logger.UnregisteredDevice();
74-
}
75-
7634
public async Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, CancellationToken cancellationToken)
7735
{
7836
var devices = await FindDevices(filter, cancellationToken);
@@ -82,6 +40,11 @@ public async Task SendNotification(IPushNotification notification, SendPushNotif
8240
await SendNotificationInternal(notification, devices, notificationTexts, cancellationToken);
8341
}
8442

43+
private static List<CommunicationLanguage> GetDistinctCommunicationLanguages(IEnumerable<DeviceWithOnlyIdAndCommunicationLanguage> devices)
44+
{
45+
return devices.Select(d => d.CommunicationLanguage).Distinct().ToList();
46+
}
47+
8548
public async Task SendNotification(IPushNotification notification, SendPushNotificationFilter filter, Dictionary<string, NotificationText> notificationTexts, CancellationToken cancellationToken)
8649
{
8750
var devices = await FindDevices(filter, cancellationToken);
@@ -90,11 +53,6 @@ public async Task SendNotification(IPushNotification notification, SendPushNotif
9053
await SendNotificationInternal(notification, devices, mappedNotificationTexts, cancellationToken);
9154
}
9255

93-
private static List<CommunicationLanguage> GetDistinctCommunicationLanguages(IEnumerable<DeviceWithOnlyIdAndCommunicationLanguage> devices)
94-
{
95-
return devices.Select(d => d.CommunicationLanguage).Distinct().ToList();
96-
}
97-
9856
private async Task<DeviceWithOnlyIdAndCommunicationLanguage[]> FindDevices(SendPushNotificationFilter filter, CancellationToken cancellationToken)
9957
{
10058
var result = await _identitiesRepository.FindDevices(
@@ -161,6 +119,48 @@ private async Task HandleSendNotificationResponses(SendResults sendResults)
161119
_logger.LogTrace("Successfully sent push notifications.");
162120
}
163121

122+
public async Task<DevicePushIdentifier> UpdateRegistration(IdentityAddress address, DeviceId deviceId, PnsHandle handle, string appId, PushEnvironment environment,
123+
CancellationToken cancellationToken)
124+
{
125+
var registration = await _pnsRegistrationsRepository.FindByDeviceId(deviceId, cancellationToken, track: true);
126+
var pnsConnector = _pnsConnectorFactory.CreateFor(handle.Platform);
127+
128+
if (registration != null)
129+
{
130+
registration.Update(handle, appId, environment);
131+
pnsConnector.ValidateRegistration(registration);
132+
133+
await _pnsRegistrationsRepository.Update(registration, cancellationToken);
134+
135+
_logger.LogTrace("Device successfully updated.");
136+
}
137+
else
138+
{
139+
registration = new PnsRegistration(address, deviceId, handle, appId, environment);
140+
pnsConnector.ValidateRegistration(registration);
141+
142+
try
143+
{
144+
await _pnsRegistrationsRepository.Add(registration, cancellationToken);
145+
_logger.LogTrace("New device successfully registered.");
146+
}
147+
catch (InfrastructureException exception) when (exception.Code == InfrastructureErrors.UniqueKeyViolation().Code)
148+
{
149+
_logger.LogInformation(exception, "This exception can be ignored. It is only thrown in case of a concurrent registration request from multiple devices.");
150+
}
151+
}
152+
153+
return registration.DevicePushIdentifier;
154+
}
155+
156+
public async Task DeleteRegistration(DeviceId deviceId, CancellationToken cancellationToken)
157+
{
158+
var numberOfDeletedDevices = await _pnsRegistrationsRepository.Delete([deviceId], cancellationToken);
159+
160+
if (numberOfDeletedDevices == 1)
161+
_logger.UnregisteredDevice();
162+
}
163+
164164
public class DeviceWithOnlyIdAndCommunicationLanguage
165165
{
166166
public required DeviceId Id { get; init; }

0 commit comments

Comments
 (0)