Skip to content

Commit 25d9748

Browse files
committed
refactor: simplify AnnouncementCreatedDomainEventHandler
1 parent 7992d91 commit 25d9748

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Modules/Devices/src/Devices.Application/DomainEvents/Incoming/AnnouncementCreated/AnnouncementCreatedDomainEventHandler.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Backbone.DevelopmentKit.Identity.ValueObjects;
44
using Backbone.Modules.Devices.Application.Infrastructure.PushNotifications.Announcements;
55
using Backbone.Modules.Devices.Domain.DomainEvents.Incoming.AnnouncementCreated;
6+
using Backbone.Tooling.Extensions;
67

78
namespace Backbone.Modules.Devices.Application.DomainEvents.Incoming.AnnouncementCreated;
89

@@ -19,9 +20,10 @@ public async Task Handle(AnnouncementCreatedDomainEvent @event)
1920
{
2021
var pushNotificationTexts = @event.Texts.ToDictionary(k => k.Language, k => new NotificationText(k.Title, k.Body) { Title = k.Title, Body = k.Body });
2122

22-
var recipientIdentityAddresses = @event.Recipients.Select(IdentityAddress.Parse).ToArray();
23-
await _pushSenderService.SendNotification(new NewAnnouncementPushNotification { AnnouncementId = @event.Id }, SendPushNotificationFilter.AllDevicesOf(recipientIdentityAddresses),
24-
pushNotificationTexts,
25-
CancellationToken.None);
23+
var pushNotificationFilter = @event.Recipients.IsEmpty()
24+
? SendPushNotificationFilter.AllDevicesOfAllIdentities()
25+
: SendPushNotificationFilter.AllDevicesOf(@event.Recipients.Select(IdentityAddress.Parse).ToArray());
26+
27+
await _pushSenderService.SendNotification(new NewAnnouncementPushNotification { AnnouncementId = @event.Id }, pushNotificationFilter, pushNotificationTexts, CancellationToken.None);
2628
}
2729
}

0 commit comments

Comments
 (0)