Files
decePubClient/Services/PublicNoticeService.cs
T
thepraandClaude Opus 5.5 5e8fdc43af An event card joins and leaves the event
PrivaPub lets a persona join another server's event (owner decision
2026-10-05). The card of a remote event shows the persona's participation
(pending, accepted, rejected) with Join or Leave, except for events by
invitation or taken on another site. Joining is public on the event's
server, so the first join asks the persona once, as reactions and votes do,
remembered apart from them (PublicAct).

The e2e joins the event SocialPub's Mobilizon scenario keeps, checks the
participant on Mobilizon and PrivaPub's answer, and leaves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
2026-10-05 15:19:07 +02:00

49 lines
1.6 KiB
C#

using Blazored.LocalStorage;
using decePubClient.Models;
namespace decePubClient.Services
{
/// <summary>
/// Asks a persona, once, before its first reaction or poll vote, and once before it first joins an event, to accept
/// that these are public and visible as that persona (an owner decision). PublicNoticeHost shows the question; Confirm
/// returns true at once for a persona that already accepted it, and false when the reader declines.
/// </summary>
public class PublicNoticeService(ILocalStorageService localStorage)
{
TaskCompletionSource<bool> pending;
public event Action Changed;
public bool IsAsking => pending is not null;
/// <summary>What the persona is being told about.</summary>
public PublicAct Act { get; private set; } = PublicAct.Reaction;
public async Task<bool> Confirm(string personaId, PublicAct act = PublicAct.Reaction, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(personaId))
return false;
var seen = await localStorage.GetItemAsync<PublicActionNotices>(nameof(PublicActionNotices), cancellationToken) ?? new();
var told = act == PublicAct.Participation ? seen.EventPersonaIds : seen.PersonaIds;
if (told.Contains(personaId))
return true;
Act = act;
pending = new TaskCompletionSource<bool>();
Changed?.Invoke();
var accepted = await pending.Task;
pending = null;
Changed?.Invoke();
if (!accepted)
return false;
told.Add(personaId);
await localStorage.SetItemAsync(nameof(PublicActionNotices), seen, cancellationToken);
return true;
}
public void Answer(bool accepted) => pending?.TrySetResult(accepted);
}
}