コード例 #1
0
        public async Task NotifyPopularStreams()
        {
            if (MinimumEventViewers == 0)
            {
                return;
            }

            var livestreamModels = await GetPopularStreams();

            foreach (var stream in livestreamModels)
            {
                // don't notify about the same event again within the next hour
                if (notifiedEvents.Get(stream.UniqueStreamKey.ToString()) != null)
                {
                    continue;
                }

                notifiedEvents.Set(stream.UniqueStreamKey.ToString(), stream, DateTimeOffset.Now.AddHours(1));

                stream.SetLivestreamNotifyState(settingsHandler.Settings);
                notificationHandler.AddNotification(new LivestreamNotification()
                {
                    LivestreamModel = stream,
                    ImageUrl        = stream.ThumbnailUrls?.Small,
                    Message         = stream.Description,
                    Title           = $"[POPULAR {stream.Viewers.ToString("N0")} Viewers]\n{stream.DisplayName}",
                    Duration        = LivestreamNotification.MaxDuration,
                    ClickAction     = clickAction
                });
            }
        }
コード例 #2
0
        public async Task Handle(PresenceUpdated notification, CancellationToken cancellationToken)
        {
            var bbq = await _context.GetAll()
                      .FirstOrDefaultAsync(o => o.Id == notification.BarbecueId);

            if (bbq == null)
            {
                _notifications.AddNotification(AppConsts.BarbecueNotFound);
                return;
            }

            bbq.TotalAmount = bbq.TotalAmount - notification.OldValue + notification.Value;

            if (notification.Paid)
            {
                bbq.TotalRaised = bbq.TotalRaised - notification.OldValue + notification.Value;
            }

            await _context.Commit();
        }
コード例 #3
0
        public async Task <Unit> Handle(PresenceOnBarbecue request, CancellationToken cancellationToken)
        {
            var barbecue = await _barbecues.GetAll()
                           .Include(o => o.Presences)
                           .FirstOrDefaultAsync(o => o.Id == request.BarbecueId);

            if (barbecue == null)
            {
                _notifications.AddNotification(AppConsts.BarbecueNotFound);
                return(Unit.Value);
            }

            if (!barbecue.Presences.Any(o => o.ParticipantId == request.ParticipantId))
            {
                barbecue.UpdateDate = DateTime.Now;
                _presences.Add(new Presence(request.Value, request.BarbecueId, request.ParticipantId));
                await _presences.Commit();

                await _mediator.Publish(PresenceConfirmed.Notify(request.BarbecueId, request.Value));
            }

            return(Unit.Value);
        }