using System.Text.Json.Serialization;
namespace decePubClient.Models.Mastodon;
/// Mastodon's WebPushSubscription (/api/v1/push/subscription): one per access token, so one per persona.
/// Alerts holds every alert PrivaPub knows, true or false.
public class WebPushSubscription
{
public string Id { get; set; }
public string Endpoint { get; set; }
public bool Standard { get; set; }
public Dictionary Alerts { get; set; } = [];
/// The server's VAPID public key, URL-safe base64.
public string ServerKey { get; set; }
/// all, followed, follower or none.
public string Policy { get; set; }
}
/// POST /api/v1/push/subscription as JSON: the browser's subscription and what it is pushed. PrivaPub reads it as
/// Mastodon's flattened parameters (subscription[endpoint], subscription[keys][p256dh], data[alerts][mention], ...).
public class PushSubscriptionForm
{
public PushEndpoint Subscription { get; set; } = new();
public PushData Data { get; set; } = new();
}
/// The browser's push subscription: where the push service takes the pushes, and the keys they are encrypted
/// to. Standard: RFC 8291's aes128gcm (with RFC 8292's VAPID header), which every browser that pushes decrypts.
public class PushEndpoint
{
public string Endpoint { get; set; }
public PushKeys Keys { get; set; } = new();
public bool Standard { get; set; }
}
/// The browser's P-256 public key and authentication secret, URL-safe base64.
public class PushKeys
{
[JsonPropertyName("p256dh")]
public string P256dh { get; set; }
public string Auth { get; set; }
}
/// What a subscription is pushed: each alert on or off (one left out is off), and whose.
public class PushData
{
public Dictionary Alerts { get; set; } = [];
public string Policy { get; set; }
}
/// PUT /api/v1/push/subscription: data[alerts] and data[policy] replace what the subscription had.
public class PushDataForm
{
public PushData Data { get; set; } = new();
}