public async Task HandleSeenAsync(TrackingToken token) { using (Telemetry.Activities.StartActivity("MobilePushChannel/HandleSeenAsync")) { var mobileToken = token.DeviceIdentifier; if (string.IsNullOrWhiteSpace(mobileToken)) { return; } var notification = await userNotificationStore.FindAsync(token.Id); if (notification == null) { return; } var user = await userStore.GetCachedAsync(notification.AppId, notification.UserId); if (user == null) { return; } var userToken = user.MobilePushTokens.FirstOrDefault(x => x.Token == mobileToken && x.DeviceType == MobileDeviceType.iOS); if (userToken != null) { await TryWakeupAsync(notification, userToken, default); } } }
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 <UserNotification?> TrackConfirmedAsync(TrackingToken token, Instant now, CancellationToken ct = default) { using (Telemetry.Activities.StartActivity("MongoDbUserNotificationRepository/TrackConfirmedAsync")) { await TrackSeenAsync(Enumerable.Repeat(token, 1), now, ct); var handle = new HandledInfo(now, token.Channel); var entity = await Collection.FindOneAndUpdateAsync( Filter.And( Filter.Eq(x => x.Id, token.Id), Filter.Eq(x => x.Formatting.ConfirmMode, ConfirmMode.Explicit), Filter.Exists(x => x.FirstConfirmed, false)), Update .Set(x => x.FirstConfirmed, handle).Max(x => x.Updated, handle.Timestamp), cancellationToken : ct); if (entity != null) { if (entity.FirstConfirmed == null) { entity.FirstConfirmed = handle; } entity.Updated = handle.Timestamp; } return(entity); } }
public Task <UserNotification?> TrackConfirmedAsync(TrackingToken token, CancellationToken ct = default) { Guard.NotDefault(token); return(repository.TrackConfirmedAsync(token, clock.GetCurrentInstant(), ct)); }
public FunctionBlock(IBlock parent, BlockType type, TrackingToken start, ITextSnapshot textSnapshot, FunctionToken name) : base(parent, type, start, textSnapshot) { Name = name; Parameters = new List <IDefinitionToken>(); parent.AddToken(name); name.FunctionBlock = this; }
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_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_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 TrackConfirmedAsync(TrackingToken token) { if (!token.IsValid) { return; } await confirmProducer.ProduceAsync(token.ToString(), new ConfirmMessage { Token = token }); }
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_from_guid() { var sourceToken = Guid.NewGuid(); var sourceString = sourceToken.ToString(); var result = TrackingToken.Parse(sourceString); Assert.Equal(result, new TrackingToken(sourceToken)); }
public void SetEnd(int endPosition, TrackingToken endToken, ITextSnapshot snapshot) { if (_startPosition > endPosition) { return; } Scope = new Span(_startPosition, endPosition - _startPosition); Area = new Span(Area.Start, endToken.GetEnd(snapshot) - Area.Start); }
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);
private string GetTextAndMarkForRemoval(TrackingToken current, ref List<TrackingToken> removalCandidates) { removalCandidates.Add(current); Span span = current.GetSpan(CurrentSnapshot); if(span.End > CurrentSnapshot.Length) return null; return current.GetText(CurrentSnapshot); }
public override TaskInformation GetStatus(TrackingToken trackingToken) { throw new NotImplementedException(); }
public Block(IBlock parent, BlockType type, TrackingToken start, TrackingToken end, ITextSnapshot snapshot) : this(parent, type, start.GetStart(snapshot), end.GetEnd(snapshot)) { }
public Block(IBlock parent, BlockType type, TrackingToken start, ITextSnapshot snapshot) : this(parent, type, start.GetStart(snapshot), snapshot.Length - 1) { }
public void Should_not_throw_if_null_or_empty(string value) { var result = TrackingToken.Parse(value); Assert.False(result.IsValid); }