Пример #1
0
        public async Task <IActionResult> GetNotifications(string appId, string id, [FromQuery] UserNotificationQueryDto q)
        {
            var notifications = await userNotificationsStore.QueryAsync(appId, id, q.ToQuery(true), HttpContext.RequestAborted);

            var response = new ListResponseDto <UserNotificationDetailsDto>();

            response.Items.AddRange(notifications.Select(UserNotificationDetailsDto.FromDomainObjectAsDetails));
            response.Total = notifications.Total;

            return(Ok(response));
        }
Пример #2
0
        public async Task <IActionResult> GetArchive()
        {
            var notifications = await userNotificationsStore.QueryAsync(App.Id, UserId, ArchiveQuery, HttpContext.RequestAborted);

            var response = new ListResponseDto <NotificationDto>
            {
                Items = notifications.Select(NotificationDto.FromNotification).ToList()
            };

            return(Ok(response));
        }
Пример #3
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);
Пример #4
0
        public async Task<IActionResult> GetNotifications([FromQuery] long etag = 0)
        {
            var timestamp = Instant.FromUnixTimeMilliseconds(etag);

            var notifications = await userNotificationsStore.QueryAsync(App.Id, UserId, 100, timestamp, HttpContext.RequestAborted);

            var response = new NotificationsDto
            {
                Notifications = notifications.Select(NotificationDto.FromNotification).ToArray()
            };

            if (notifications.Any())
            {
                response.Etag = notifications.Max(x => x.Updated).ToUnixTimeMilliseconds();
            }
            else if (timestamp != default)
            {
                return NoContent();
            }

            return Ok(response);
        }
Пример #5
0
 public override async Task OnConnectedAsync()
 {
     var notifications = await userNotificationsStore.QueryAsync(AppId, UserId, 100, default, Context.ConnectionAborted);