Exemple #1
0
        public async Task Should_not_produce_message_if_app_id_not_set()
        {
            var @event = CreateMinimumEvent();

            @event.AppId = null !;

            await sut.PublishAsync(@event, default);

            A.CallTo(() => subscriptionStore.QueryAsync(@event.AppId, A <TopicId> ._, @event.CreatorId, A <CancellationToken> ._))
            .MustNotHaveHappened();

            A.CallTo(() => logStore.LogAsync(A <string> ._, A <string> ._, A <CancellationToken> ._))
            .MustNotHaveHappened();
        }
Exemple #2
0
        private async Task <Dictionary <Topic, bool> > GetEmailTopicsAsync(
            CancellationToken ct)
        {
            var result = new Dictionary <Topic, bool>();

            var topics = await topicStore.QueryAsync(App.Id, TopicQuery, ct);

            // Only handled topics where emails are explicitly allowed.
            var topicsWithEmail = topics.Where(x => x.Channels.GetOrDefault(Providers.Email) == TopicChannel.Allowed);

            if (!topicsWithEmail.Any())
            {
                return(result);
            }

            var subscriptions = await subscriptionStore.QueryAsync(App.Id, new SubscriptionQuery { UserId = UserId }, ct);

            foreach (var topic in topicsWithEmail)
            {
                var subscription = subscriptions.FirstOrDefault(x => x.TopicPrefix == topic.Path);

                if (subscription?.TopicSettings?.GetOrDefault(Providers.Email)?.Send == ChannelSend.Send)
                {
                    result[topic] = true;
                }
            }

            return(result);
        }
        private async IAsyncEnumerable <Subscription> GetSubscriptions(EventMessage @event)
        {
            var topic = @event.Topic;

            if (IsAllUsers(topic))
            {
                await foreach (var userId in userStore.QueryIdsAsync(@event.AppId))
                {
                    yield return(new Subscription
                    {
                        AppId = @event.AppId,
                        TopicPrefix = "users/all",
                        TopicSettings = null,
                        UserId = userId
                    });
                }
            }
            else if (IsUserTopic(topic, out var userId))
            {
                yield return(new Subscription
                {
                    AppId = @event.AppId,
                    TopicPrefix = $"users/{userId}",
                    TopicSettings = null,
                    UserId = userId
                });
            }
            else
            {
                await foreach (var subscription in subscriptionStore.QueryAsync(@event.AppId, @event.Topic, @event.CreatorId))
                {
                    yield return(subscription);
                }
            }
        }
Exemple #4
0
        public async Task <IActionResult> GetSubscriptions(string appId, string id, [FromQuery] QueryDto q)
        {
            var subscriptions = await subscriptionStore.QueryAsync(appId, ParseQuery(id, q), HttpContext.RequestAborted);

            var response = new ListResponseDto <SubscriptionDto>();

            response.Items.AddRange(subscriptions.Select(SubscriptionDto.FromDomainObject));
            response.Total = subscriptions.Total;

            return(Ok(response));
        }
Exemple #5
0
        public async Task <IActionResult> GetMySubscriptions([FromQuery] SubscriptionQueryDto q)
        {
            var subscriptions = await subscriptionStore.QueryAsync(App.Id, q.ToQuery(false, UserId), HttpContext.RequestAborted);

            var response = new ListResponseDto <SubscriptionDto>();

            response.Items.AddRange(subscriptions.Select(SubscriptionDto.FromDomainObject));
            response.Total = subscriptions.Total;

            return(Ok(response));
        }
        private async IAsyncEnumerable <Subscription> GetSubscriptions(EventMessage @event)
        {
            var topic = @event.Topic;

            if (IsUserTopic(topic, out var userId))
            {
                yield return(new Subscription
                {
                    AppId = @event.AppId,
                    TopicPrefix = topic,
                    TopicSettings = new NotificationSettings(),
                    UserId = userId
                });
            }
            else
            {
                await foreach (var subscription in subscriptionStore.QueryAsync(@event.AppId, @event.Topic, @event.CreatorId))
                {
                    yield return(subscription);
                }
            }
        }