public async Task <IActionResult> Confirm(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null) { var token = TrackingToken.Parse(id, channel, deviceIdentifier); await userNotificationService.TrackConfirmedAsync(token); var notification = await userNotificationStore.FindAsync(token.Id, HttpContext.RequestAborted); if (notification == null) { return(View()); } var app = await appStore.GetCachedAsync(notification.AppId, HttpContext.RequestAborted); if (app?.ConfirmUrl != null && Uri.IsWellFormedUriString(app.ConfirmUrl, UriKind.Absolute)) { var url = app.ConfirmUrl !; if (url.Contains('?', StringComparison.OrdinalIgnoreCase)) { url += $"&id={id:notEmpty}"; } else { url += $"?id={id:notEmpty}"; } return(Redirect(url)); } return(View()); }
public async Task <IActionResult> ConfirmPost(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null) { var token = TrackingToken.Parse(id, channel, deviceIdentifier); await userNotificationService.TrackConfirmedAsync(token); return(NoContent()); }
public async Task <IActionResult> Delivered(string id, [FromQuery] string?channel = null, [FromQuery] string?deviceIdentifier = null) { var tokens = Enumerable.Repeat(TrackingToken.Parse(id, channel, deviceIdentifier), 1); await userNotificationService.TrackDeliveredAsync(tokens); return(TrackingPixel()); }
public void Should_not_override_channel_device_identifier() { var sourceToken = new TrackingToken(Guid.NewGuid(), "push", "123"); var sourceString = sourceToken.ToParsableString(); var result = TrackingToken.Parse(sourceString, "web", "456"); Assert.Equal(result, sourceToken); }
public void Should_parse_and_override_channel_and_device_identifier_if_not_set() { var sourceToken = new TrackingToken(Guid.NewGuid()); var sourceString = sourceToken.ToParsableString(); var result = TrackingToken.Parse(sourceString, "push", "123"); Assert.Equal(result, new TrackingToken(sourceToken.Id, "push", "123")); }
public void Should_parse_from_guid() { var sourceToken = Guid.NewGuid(); var sourceString = sourceToken.ToString(); var result = TrackingToken.Parse(sourceString); Assert.Equal(result, new TrackingToken(sourceToken)); }
public void Should_parse_from_formatted_token_with_complex_device_identifier() { var sourceToken = new TrackingToken(Guid.NewGuid(), "web", "a|very|complex|token"); var sourceString = sourceToken.ToParsableString(); var result = TrackingToken.Parse(sourceString); Assert.Equal(result, sourceToken); }
public void Should_parse_from_formatted_token_without_channel() { var sourceToken = new TrackingToken(Guid.NewGuid()); var sourceString = sourceToken.ToParsableString(); var result = TrackingToken.Parse(sourceString); Assert.Equal(result, sourceToken); }
public async Task <IActionResult> ConfirmMe([FromBody] TrackNotificationDto request) { if (request.Confirmed != null) { var token = TrackingToken.Parse(request.Confirmed, request.Channel, request.DeviceIdentifier); await userNotificationService.TrackConfirmedAsync(token); } if (request.Seen?.Length > 0) { var tokens = request.Seen.Select(x => TrackingToken.Parse(x, request.Channel, request.DeviceIdentifier)); await userNotificationService.TrackSeenAsync(tokens); } return(NoContent()); }
public async Task <IActionResult> GetMyPolling([FromBody] PollRequest request) { var requestToken = request.Token ?? default; if (requestToken != default) { requestToken = requestToken.Minus(Duration.FromSeconds(10)); } #pragma warning disable MA0040 // Flow the cancellation token if (request.Delivered?.Length > 0) { var tokens = request.Delivered.Select(x => TrackingToken.Parse(x)); await userNotificationStore.TrackSeenAsync(tokens); } if (request.Seen?.Length > 0) { var tokens = request.Seen.Select(x => TrackingToken.Parse(x)); await userNotificationStore.TrackSeenAsync(tokens); } foreach (var id in request.Confirmed.OrEmpty()) { var token = TrackingToken.Parse(id); await userNotificationStore.TrackConfirmedAsync(token); } #pragma warning restore MA0040 // Flow the cancellation token foreach (var id in request.Deleted.OrEmpty()) { await userNotificationStore.DeleteAsync(id, HttpContext.RequestAborted); } var notifications = await userNotificationStore.QueryAsync(App.Id, UserId, DefaultQuery with { After = requestToken }, HttpContext.RequestAborted);
public void Should_not_throw_if_null_or_empty(string value) { var result = TrackingToken.Parse(value); Assert.False(result.IsValid); }