Esempio n. 1
0
        public async Task HandleAsync(ConfirmMessage message,
                                      CancellationToken ct = default)
        {
            var notification = await userNotificationsStore.TrackConfirmedAsync(message.Token, ct);

            if (notification == null || !notification.Channels.Any())
            {
                return;
            }

            try
            {
                var app = await appStore.GetCachedAsync(notification.AppId, ct);

                if (app == null)
                {
                    return;
                }

                var user = await userStore.GetCachedAsync(notification.AppId, notification.UserId, ct);

                if (user == null)
                {
                    throw new DomainException(Texts.Notification_NoUser);
                }

                var options = new SendOptions {
                    App = app, User = user, IsUpdate = true
                };

                foreach (var channel in channels)
                {
                    if (notification.Channels.TryGetValue(channel.Name, out var notificationChannel))
                    {
                        foreach (var configuration in notificationChannel.Status.Keys)
                        {
                            await channel.SendAsync(notification, notificationChannel.Setting, configuration, options, ct);
                        }
                    }
                }
            }
            catch (DomainException domainException)
            {
                await logStore.LogAsync(notification.AppId, domainException.Message);

                throw;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> GetMyPolling([FromBody] PollRequest request)
        {
            var requestToken = request.Token ?? default;

            if (requestToken != default)
            {
                requestToken = requestToken.Minus(Duration.FromSeconds(10));
            }

#pragma warning disable MA0040 // Flow the cancellation token
            if (request.Delivered?.Length > 0)
            {
                var tokens = request.Delivered.Select(x => TrackingToken.Parse(x));

                await userNotificationStore.TrackSeenAsync(tokens);
            }

            if (request.Seen?.Length > 0)
            {
                var tokens = request.Seen.Select(x => TrackingToken.Parse(x));

                await userNotificationStore.TrackSeenAsync(tokens);
            }

            foreach (var id in request.Confirmed.OrEmpty())
            {
                var token = TrackingToken.Parse(id);

                await userNotificationStore.TrackConfirmedAsync(token);
            }
#pragma warning restore MA0040 // Flow the cancellation token

            foreach (var id in request.Deleted.OrEmpty())
            {
                await userNotificationStore.DeleteAsync(id, HttpContext.RequestAborted);
            }

            var notifications = await userNotificationStore.QueryAsync(App.Id, UserId, DefaultQuery with {
                After = requestToken
            }, HttpContext.RequestAborted);
        public async Task <(UserNotification?, App?)> TrackConfirmedAsync(Guid id, string?sourceChannel = null)
        {
            var notification = await userNotificationsStore.TrackConfirmedAsync(id, sourceChannel);

            if (notification != null)
            {
                var app = await appStore.GetCachedAsync(notification.AppId, default);

                if (app == null)
                {
                    return(null, null);
                }

                if (notification.Settings.Values.Any(x => x.ShouldSend))
                {
                    var user = await userStore.GetCachedAsync(notification.AppId, notification.UserId);

                    if (user == null)
                    {
                        return(null, null);
                    }

                    foreach (var channel in channels)
                    {
                        if (notification.Settings.TryGetValue(channel.Name, out var preference))
                        {
                            await channel.SendAsync(notification, preference, user, app, true);
                        }
                    }
                }

                return(notification, app);
            }

            return(null, null);
        }