|
|
|
@ -20,6 +20,7 @@ using Squidex.Domain.Apps.Events.Contents; |
|
|
|
using Squidex.Domain.Users; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.EventSourcing; |
|
|
|
using Squidex.Log; |
|
|
|
using Squidex.Shared.Identity; |
|
|
|
using Squidex.Shared.Users; |
|
|
|
|
|
|
|
@ -31,22 +32,28 @@ namespace Squidex.Domain.Apps.Entities.History |
|
|
|
private readonly NotifoOptions options; |
|
|
|
private readonly IUrlGenerator urlGenerator; |
|
|
|
private readonly IUserResolver userResolver; |
|
|
|
private readonly ISemanticLog log; |
|
|
|
private readonly IClock clock; |
|
|
|
private readonly INotifoClient? client; |
|
|
|
|
|
|
|
public NotifoService(IOptions<NotifoOptions> options, IUrlGenerator urlGenerator, IUserResolver userResolver, IClock clock) |
|
|
|
public NotifoService(IOptions<NotifoOptions> options, |
|
|
|
IUrlGenerator urlGenerator, |
|
|
|
IUserResolver userResolver, |
|
|
|
ISemanticLog log, |
|
|
|
IClock clock) |
|
|
|
{ |
|
|
|
Guard.NotNull(options, nameof(options)); |
|
|
|
Guard.NotNull(urlGenerator, nameof(urlGenerator)); |
|
|
|
Guard.NotNull(userResolver, nameof(userResolver)); |
|
|
|
Guard.NotNull(log, nameof(log)); |
|
|
|
Guard.NotNull(clock, nameof(clock)); |
|
|
|
|
|
|
|
this.options = options.Value; |
|
|
|
|
|
|
|
this.urlGenerator = urlGenerator; |
|
|
|
this.userResolver = userResolver; |
|
|
|
|
|
|
|
this.clock = clock; |
|
|
|
this.log = log; |
|
|
|
|
|
|
|
if (options.Value.IsConfigured()) |
|
|
|
{ |
|
|
|
@ -86,6 +93,8 @@ namespace Squidex.Domain.Apps.Entities.History |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
var settings = new Dictionary<string, NotificationSettingDto> |
|
|
|
{ |
|
|
|
[Providers.WebPush] = new NotificationSettingDto |
|
|
|
@ -123,8 +132,17 @@ namespace Squidex.Domain.Apps.Entities.History |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
var apiKey = response.First().ApiKey; |
|
|
|
|
|
|
|
await userResolver.SetClaimAsync(user.Id, SquidexClaimTypes.NotifoKey, response.First().ApiKey, true); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
log.LogError(ex, w => w |
|
|
|
.WriteProperty("action", "RegisterToNotifo") |
|
|
|
.WriteProperty("status", "Failed")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public async Task HandleEventsAsync(IEnumerable<(Envelope<AppEvent> AppEvent, HistoryEvent? HistoryEvent)> events) |
|
|
|
{ |
|
|
|
|