Files
decePubClient/Models/Mastodon/WebPush.cs
T

55 lines
2.1 KiB
C#
Raw Normal View History

using System.Text.Json.Serialization;
namespace decePubClient.Models.Mastodon;
/// <summary>Mastodon's WebPushSubscription (/api/v1/push/subscription): one per access token, so one per persona.
/// Alerts holds every alert PrivaPub knows, true or false.</summary>
public class WebPushSubscription
{
public string Id { get; set; }
public string Endpoint { get; set; }
public bool Standard { get; set; }
public Dictionary<string, bool> Alerts { get; set; } = [];
/// <summary>The server's VAPID public key, URL-safe base64.</summary>
public string ServerKey { get; set; }
/// <summary>all, followed, follower or none.</summary>
public string Policy { get; set; }
}
/// <summary>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], ...).</summary>
public class PushSubscriptionForm
{
public PushEndpoint Subscription { get; set; } = new();
public PushData Data { get; set; } = new();
}
/// <summary>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.</summary>
public class PushEndpoint
{
public string Endpoint { get; set; }
public PushKeys Keys { get; set; } = new();
public bool Standard { get; set; }
}
/// <summary>The browser's P-256 public key and authentication secret, URL-safe base64.</summary>
public class PushKeys
{
[JsonPropertyName("p256dh")]
public string P256dh { get; set; }
public string Auth { get; set; }
}
/// <summary>What a subscription is pushed: each alert on or off (one left out is off), and whose.</summary>
public class PushData
{
public Dictionary<string, bool> Alerts { get; set; } = [];
public string Policy { get; set; }
}
/// <summary>PUT /api/v1/push/subscription: data[alerts] and data[policy] replace what the subscription had.</summary>
public class PushDataForm
{
public PushData Data { get; set; } = new();
}