R9 Web Push in decePub: one subscription per persona, each with its own token and registration
Build / Build (push) Successful in 56s
Build / Build (push) Successful in 56s
Settings gets "Notifications on this device" (PushEditor): personas, alerts in four groups, policy, a test
notification, after a one-time notice of what the push service learns. Each persona ticked gets its own service
worker registration (push-worker.js at push/{slot}/), so its own endpoint and keys, subscribed with its own token
(IHttpService's *As); nothing PrivaPub stores ties two personas together and the worker never reads the payload's
token. PushService follows the tokens (re-subscribing after a renewal), reconciles at every session start, turns
off before sign-out and drops deleted or suspended personas. A click opens that persona's notifications; the app
badge counts the unread ones. Exchanges now ask for the push scope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WpVCoDeM1qUTRp4fXQdfof
This commit is contained in:
1 parent
d33697e3fc
commit
ab17959ed4
29 files changed
+2047
-67
No files matched your search
@@ -30,6 +30,10 @@ namespace decePubClient.Services
|
||||
/// <summary>Raised once for a persona PrivaPub refused a token to (Refuse); CascadingState moves the session on.</summary>
|
||||
public event Action<string> PersonaRefused;
|
||||
|
||||
/// <summary>Raised with a persona's id when its token is replaced or forgotten: a Web Push subscription made with the
|
||||
/// old one ended with it (PushService subscribes the persona again with its new one).</summary>
|
||||
public event Action<string> PersonaTokenChanged;
|
||||
|
||||
/// <summary>The stored session, or an empty one.</summary>
|
||||
public async Task<AuthData> GetAuthData(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -59,6 +63,15 @@ namespace decePubClient.Services
|
||||
return session.PersonaTokens.GetValueOrDefault(session.PersonaId);
|
||||
}
|
||||
|
||||
/// <summary>That persona's Mastodon token, or null when it has none yet; never another persona's.</summary>
|
||||
public async Task<string> GetPersonaToken(string personaId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (personaId is null)
|
||||
return null;
|
||||
var session = await GetAuthData(cancellationToken);
|
||||
return session.PersonaTokens.GetValueOrDefault(personaId);
|
||||
}
|
||||
|
||||
public async Task<bool> IsAuthenticatedAsync(CancellationToken cancellationToken = default) =>
|
||||
await GetToken(cancellationToken) is not null;
|
||||
|
||||
@@ -81,9 +94,26 @@ namespace decePubClient.Services
|
||||
{
|
||||
var session = await GetAuthData(cancellationToken);
|
||||
session.PersonaId = personaId;
|
||||
var changed = token is not null && session.PersonaTokens.GetValueOrDefault(personaId) != token;
|
||||
if (token is not null)
|
||||
session.PersonaTokens[personaId] = token;
|
||||
await Save(session, cancellationToken);
|
||||
if (changed)
|
||||
PersonaTokenChanged?.Invoke(personaId);
|
||||
}
|
||||
|
||||
/// <summary>Remembers a persona's new token without making it current (a request as another persona than the one
|
||||
/// the session acts as, HttpService's *As).</summary>
|
||||
public async Task SetPersonaToken(string personaId, string token, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (personaId is null || token is null)
|
||||
return;
|
||||
var session = await GetAuthData(cancellationToken);
|
||||
if (session.PersonaTokens.GetValueOrDefault(personaId) == token)
|
||||
return;
|
||||
session.PersonaTokens[personaId] = token;
|
||||
await Save(session, cancellationToken);
|
||||
PersonaTokenChanged?.Invoke(personaId);
|
||||
}
|
||||
|
||||
/// <summary>Drops a persona's token that PrivaPub no longer accepts.</summary>
|
||||
@@ -93,6 +123,7 @@ namespace decePubClient.Services
|
||||
if (!session.PersonaTokens.Remove(personaId))
|
||||
return;
|
||||
await Save(session, cancellationToken);
|
||||
PersonaTokenChanged?.Invoke(personaId);
|
||||
}
|
||||
|
||||
/// <summary>Whether PrivaPub refused the persona a token in this session (Refuse).</summary>
|
||||
@@ -120,8 +151,11 @@ namespace decePubClient.Services
|
||||
var session = await GetAuthData(cancellationToken);
|
||||
if (session.PersonaTokens.Count == 0)
|
||||
return;
|
||||
var forgotten = session.PersonaTokens.Keys.ToList();
|
||||
session.PersonaTokens.Clear();
|
||||
await Save(session, cancellationToken);
|
||||
foreach (var personaId in forgotten)
|
||||
PersonaTokenChanged?.Invoke(personaId);
|
||||
}
|
||||
|
||||
public async Task LogoutAsync(CancellationToken cancellationToken = default)
|
||||
|
||||
Reference in new issue
Block a user