feat(templates): add localized push templates and actions
Share template keys across email and push with independent editors and revisions. Render localized actions and preserve version-one delivery. Ref: IT-1627
This commit is contained in:
@@ -9,13 +9,17 @@ public sealed class PushChannelTestService(IPushChannelRepository channels, IFir
|
||||
{
|
||||
public async Task<PushDeliveryOutcome> TestAsync(PushChannelTestSettings settings, bool send, CancellationToken ct)
|
||||
{
|
||||
if (send && !ValidToken(settings.RecipientToken))
|
||||
return new PushDeliveryOutcome("Enter a valid recipient FCM token.");
|
||||
var message = new PushChannelTestMessage
|
||||
{
|
||||
Token = settings.RecipientToken?.Trim() ?? "", Version = settings.Version,
|
||||
BindingId = settings.BindingId, ActionKey = settings.ActionKey, ButtonLabel = settings.ButtonLabel
|
||||
};
|
||||
if (send && message.Validate() is { } error) return new PushDeliveryOutcome(error);
|
||||
var project = settings.FirebaseProjectId?.Trim() ?? "";
|
||||
var json = await ResolveCredentialsAsync(settings, project, ct);
|
||||
if (string.IsNullOrWhiteSpace(json))
|
||||
return new PushDeliveryOutcome("Provide credentials for this project. Saved credentials can only be used with the unchanged project.");
|
||||
return await ExecuteAsync(json, project, settings.RecipientToken, send, ct);
|
||||
return await ExecuteAsync(json, project, message, send, ct);
|
||||
}
|
||||
|
||||
private async Task<string?> ResolveCredentialsAsync(PushChannelTestSettings settings, string project, CancellationToken ct)
|
||||
@@ -26,12 +30,12 @@ public sealed class PushChannelTestService(IPushChannelRepository channels, IFir
|
||||
return saved?.FirebaseProjectId == project ? await channels.GetCredentialsAsync(id, ct) : null;
|
||||
}
|
||||
|
||||
private async Task<PushDeliveryOutcome> ExecuteAsync(string json, string project, string? token, bool send, CancellationToken ct)
|
||||
private async Task<PushDeliveryOutcome> ExecuteAsync(string json, string project, PushChannelTestMessage message, bool send, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var credentials = FirebaseServiceAccountCredentials.Parse(json, project);
|
||||
return send ? await firebase.SendTestAsync(token!.Trim(), credentials, ct)
|
||||
return send ? await firebase.SendTestAsync(message, credentials, ct)
|
||||
: await firebase.CheckAuthorizationAsync(credentials, ct);
|
||||
}
|
||||
catch (Exception error) when (error is JsonException or FormatException or ArgumentException or CryptographicException)
|
||||
@@ -44,6 +48,4 @@ public sealed class PushChannelTestService(IPushChannelRepository channels, IFir
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ValidToken(string? token) => !string.IsNullOrWhiteSpace(token)
|
||||
&& token.Trim().Length <= 4096 && !token.Trim().Any(char.IsWhiteSpace);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user