public async Task <IActionResult> Subscription([FromBody] Lib.Net.Http.WebPush.PushSubscription subscription) { if (subscription != null && !string.IsNullOrEmpty(subscription.Endpoint)) { var tenantId = _tenantIdResolver.GetTenantId();; var existing = await _subscriptionStore.GetSubscriptionByEndpoint(tenantId, subscription.Endpoint); if (existing != null) { //the user could subscribe while not authenticated, if they are later authenticated add the userid to the subscription if (string.IsNullOrEmpty(existing.UserId) && User.Identity.IsAuthenticated) { existing.UserId = _userIdResolver.GetCurrentUserId(); await _subscriptionStore.UpdateSubscription(existing); } } else { var newSub = new PushDeviceSubscription(subscription); newSub.TenantId = _tenantIdResolver.GetTenantId(); newSub.UserId = _userIdResolver.GetCurrentUserId(); newSub.UserAgent = Request.Headers["User-Agent"].ToString(); newSub.CreatedFromIpAddress = HttpContext.Connection.RemoteIpAddress.ToString(); await _subscriptionStore.CreateSubscription(newSub); } } return(NoContent()); }
private void SendNewContentNotification(string url) { var message = new PushMessageModel() { MessageType = "newcontent", Body = "New content", Data = url }; var queueItem = new PushQueueItem( message, BuiltInRecipientProviderNames.AllButCurrentUserPushNotificationRecipientProvider); queueItem.TenantId = _tenantIdResolver.GetTenantId(); queueItem.RecipientProviderCustom1 = _userIdResolver.GetCurrentUserId(); _pushNotificationsQueue.Enqueue(queueItem); }