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:
@@ -8,11 +8,27 @@ public static class PushMessageValidator
|
||||
{
|
||||
if (message?.Data is not { } data || message.CorrelationContext is null) return false;
|
||||
return Guid.TryParse(message.CorrelationContext.CorrelationId, out _) &&
|
||||
data.Version == 1 && data.RegistrationId != Guid.Empty && data.BindingId != Guid.Empty &&
|
||||
data.RegistrationId != Guid.Empty && data.BindingId != Guid.Empty &&
|
||||
data.ServiceName is { Length: > 0 and <= 100 } && data.UserId != Guid.Empty &&
|
||||
data.Token is { Length: > 0 and <= 2048 } && data.TokenHash is { Length: 64 } &&
|
||||
data.Title is { Length: > 0 and <= 100 } && data.Body is { Length: > 0 and <= 500 } &&
|
||||
data.Route == "/home" && data.ExpiresAt <= DateTimeOffset.UtcNow.AddMinutes(15);
|
||||
IsValidContent(data) && data.ExpiresAt <= DateTimeOffset.UtcNow.AddMinutes(15);
|
||||
}
|
||||
|
||||
public static bool IsSupportedVersion(int version) => version is 1 or 2;
|
||||
|
||||
public static bool IsValidContent(SendPushMessageData data) => data.Version switch
|
||||
{
|
||||
1 => data.Title is { Length: > 0 and <= 100 } && data.Body is { Length: > 0 and <= 500 } && data.Route == "/home",
|
||||
2 => ValidTemplateData(data),
|
||||
_ => false
|
||||
};
|
||||
|
||||
private static bool ValidTemplateData(SendPushMessageData data) =>
|
||||
data.TemplateKey is { Length: > 0 and <= 100 } &&
|
||||
data.LanguageCode is { Length: > 0 and <= 10 } &&
|
||||
data.TemplateData?.Bindings is not null && data.TemplateData.Actions is not null &&
|
||||
data.TemplateData.Bindings.All(pair => !string.IsNullOrWhiteSpace(pair.Key) && pair.Value is not null) &&
|
||||
data.TemplateData.Actions.All(pair => !string.IsNullOrWhiteSpace(pair.Key) && pair.Value is not null &&
|
||||
(pair.Value.ObjectId is null || pair.Value.ObjectId is { Length: > 0 and <= 256 }));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user