private async Task SendCoreAsync(WebPushJob job, CancellationToken ct) { try { var pushSubscription = new PushSubscription( job.Subscription.Endpoint, job.Subscription.Keys["p256dh"], job.Subscription.Keys["auth"]); var json = job.Payload; await webPushClient.SendNotificationAsync(pushSubscription, json, cancellationToken : ct); } catch (WebPushException ex) when(ex.StatusCode == HttpStatusCode.Gone) { await logStore.LogAsync(job.AppId, Name, Texts.WebPush_TokenRemoved); var command = new RemoveUserWebPushSubscription { Endpoint = job.Subscription.Endpoint }; await userStore.UpsertAsync(job.AppId, job.UserId, command, ct); } catch (WebPushException ex) { throw new DomainException(ex.Message); } }
public async Task <IActionResult> DeleteSubscription([FromBody] RegisterWebTokenDto request) { var command = new RemoveUserWebPushSubscription { Subscription = request.Subscription.ToSubscription() }; await userStore.UpsertAsync(App.Id, UserId, command, HttpContext.RequestAborted); return(NoContent()); }
public async Task <IActionResult> DeleteWebPushSubscription(string appId, string id, string endpoint) { var user = await userStore.GetAsync(appId, id, HttpContext.RequestAborted); if (user == null) { return(NotFound()); } var update = new RemoveUserWebPushSubscription { Endpoint = Uri.UnescapeDataString(endpoint) }; await userStore.UpsertAsync(appId, id, update, HttpContext.RequestAborted); return(NoContent()); }