Ejemplo n.º 1
0
        private FcmSharp.Requests.Notification ConvertNotification(Notification source)
        {
            if (source == null)
            {
                return(null);
            }

            return(new FcmSharp.Requests.Notification
            {
                Title = source.Title,
                Body = source.Body
            });
        }
Ejemplo n.º 2
0
        public async Task SendNotificationAsync(ApplicationUser user, Notification notification, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var context = factory.Create())
            {
                var tokens = await context.DbSet <UserRegistration>()
                             .Where(x => x.DeactivationDate == null)
                             .Select(x => x.RegistrationToken)
                             .ToListAsync(cancellationToken);

                var tasks = tokens.Select(x => SendNotificationAsync(x, notification, cancellationToken));

                await Task.WhenAll(tasks);
            }
        }
Ejemplo n.º 3
0
        private async Task SendNotificationAsync(string token, Notification notification, CancellationToken cancellationToken)
        {
            var message = new FcmMessage
            {
                ValidateOnly = false,
                Message      = new Message
                {
                    Token        = token,
                    Notification = ConvertNotification(notification)
                }
            };

            await client.SendAsync(message, cancellationToken);
        }
Ejemplo n.º 4
0
        public async Task SendNotificationAsync(Topic topic, Notification notification, CancellationToken cancellationToken = default(CancellationToken))
        {
            var message = new FcmMessage
            {
                ValidateOnly = false,
                Message      = new Message
                {
                    Topic        = topic.Name,
                    Notification = ConvertNotification(notification)
                }
            };

            await client.SendAsync(message, cancellationToken);
        }