private FcmSharp.Requests.Notification ConvertNotification(Notification source) { if (source == null) { return(null); } return(new FcmSharp.Requests.Notification { Title = source.Title, Body = source.Body }); }
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); } }
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); }
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); }