// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using Squidex.Domain.Apps.Events; using Squidex.Infrastructure.EventSourcing; using Squidex.Messaging.Subscriptions; namespace Squidex.Domain.Apps.Core.Subscriptions; public sealed class SubscriptionPublisher : IEventConsumer { private readonly ISubscriptionService subscriptionService; private readonly IEnumerable subscriptionEventCreators; public string Name => "Subscriptions"; public StreamFilter EventsFilter { get; } = StreamFilter.Prefix("content-", "asset-"); public bool StartLatest => true; public bool CanClear => false; public SubscriptionPublisher(ISubscriptionService subscriptionService, IEnumerable subscriptionEventCreators) { this.subscriptionService = subscriptionService; this.subscriptionEventCreators = subscriptionEventCreators; } public bool Handles(StoredEvent @event) { return subscriptionService.HasSubscriptions; } public Task On(Envelope @event) { if (@event.Payload is not AppEvent) { return Task.CompletedTask; } var wrapper = new EventMessageWrapper(@event.To(), subscriptionEventCreators); return subscriptionService.PublishAsync(wrapper); } }