~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Kicker lets people ask to join, cancel, and leave, from the site

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:examples/kicker-join
examples/kicker/harness/e2e/flows.spec.mjs+59−4
@@ -4,8 +4,10 @@
// repo in the place's spaces, and read back through the host.
import { test, expect } from '@playwright/test';
import { execFileSync } from 'node:child_process';
import { join } from 'node:path';
import { portrait, poster } from '../posters.mjs';
import { serviceAuth } from '../world.mjs';
import { groupHost, serviceAuth } from '../world.mjs';
const world = JSON.parse(process.env.E2E_WORLD);
const who = Object.fromEntries(world.accounts.map((a) => [a.handle.split('.')[0], a]));
@@ -42,11 +44,28 @@ test('signed out, the place shows its landing, and the way in', async ({ page })
await expect(page).toHaveTitle('Board');
});
test('someone asking to join is not let in yet', async ({ page }) => {
const site = await signIn(page, 'erin');
await expect(site.getByText('Not a member yet')).toBeVisible();
test('someone asks to join, cancels, asks again, and is let in', async ({ page }) => {
let site = await signIn(page, 'erin');
await expect(site.getByText('Your request is waiting')).toBeVisible();
await expect(site.getByText('@erin.test')).toBeVisible();
await expect(site.getByRole('link', { name: 'Events' })).toHaveCount(0);
// Cancelled, and asked again, with a note.
await site.getByRole('button', { name: 'Cancel request' }).click();
await expect(site.getByText('Not a member yet')).toBeVisible();
await site.getByRole('button', { name: 'Ask to join' }).click();
const asking = site.getByRole('dialog', { name: 'Ask to join' });
await asking.getByLabel('Note').fill('I skate the lot most Thursdays.');
await asking.getByRole('button', { name: 'Send request' }).click();
await expect(asking).toBeHidden();
await expect(site.getByText('Your request is waiting')).toBeVisible();
// Alice has it in the host's queue, with the note, and lets her in.
const { requests } = await asAlice('fyi.opensocial.listJoinRequests', {});
const erins = requests.find((r) => r.member === who.erin.did);
expect(erins?.message).toBe('I skate the lot most Thursdays.');
opensocial('alice', 'member', 'assign', 'kicker.groups.test', who.erin.did, 'member');
await page.reload();
site = page.frameLocator('#os-page');
await expect(site.getByRole('link', { name: 'Events' })).toBeVisible();
});
test('a member pins a note, answers an event and writes her card', async ({ page }) => {
@@ -188,6 +207,19 @@ const asAlice = async (lxm, params) => {
});
return await res.json();
};
/// The `opensocial` command, as `name`.
const opensocial = (name, ...args) =>
execFileSync(join(groupHost, 'target/debug/opensocial'), args, {
encoding: 'utf8',
env: {
...process.env,
OPENSOCIAL_HOST: world.host,
PDS_URL: world.pds,
OPENSOCIAL_HOST_DID: world.hostDid,
OPENSOCIAL_AS: who[name].handle,
OPENSOCIAL_PASSWORD: who[name].password
}
});
/// The URI of the note on the board whose words begin `text`.
const noteUri = async (text) => {
const space = `at://${world.place}/space/fyi.opensocial.siteSpace/room`;
@@ -259,3 +291,26 @@ test('its author appeals, and a moderator reviews it in the console', async ({ p
const ink = site.locator('li.note', { hasText: 'Cheap bearings' });
await expect(ink).toContainText('Hidden from members by the moderators.');
});
test('a member leaves from her own row, and the last admin is told how', async ({ page }) => {
let site = await signIn(page, 'erin');
await site.getByRole('link', { name: 'People' }).click();
await expect(site.getByRole('button', { name: 'Leave' })).toHaveCount(1);
const mine = site.locator('.rows li', { hasText: '@erin.test' });
await mine.getByRole('button', { name: 'Leave' }).click();
const leaving = site.getByRole('dialog', { name: 'Leave this group?' });
await leaving.getByRole('button', { name: 'Leave' }).click();
await expect(site.getByText('Not a member yet')).toBeVisible();
await expect(site.getByRole('button', { name: 'Ask to join' })).toBeVisible();
// Alice is its one admin: refused, and told what to do first.
await site.getByRole('button', { name: 'Sign out' }).click();
await expect(site.getByRole('button', { name: 'Sign in' })).toBeVisible();
site = await signIn(page, 'alice');
await site.getByRole('link', { name: 'People' }).click();
const hers = site.locator('.rows li', { hasText: '@alice.test' });
await hers.getByRole('button', { name: 'Leave' }).click();
const refused = site.getByRole('dialog', { name: 'Leave this group?' });
await refused.getByRole('button', { name: 'Leave' }).click();
await expect(refused.getByText(/You're the last admin\./)).toBeVisible();
});
examples/kicker/harness/look.mjs+23−2
@@ -47,6 +47,26 @@ try {
await page.getByRole('button', { name: /^(accept|authorize|allow)$/i }).click();
await page.waitForURL((u) => u.origin === new URL(site.url).origin);
await frame.getByRole('button', { name: 'Sign out' }).waitFor();
const shoot = async (shot) => {
await page.waitForTimeout(300);
const file = join(out, `${shot}-as-${name}-${view}.png`);
await page.screenshot({ path: file });
console.log(file);
};
// Someone not let in yet (erin): waiting, then asking, its dialog
// open, then waiting again as they started.
if (await frame.getByText('Your request is waiting').isVisible()) {
await shoot('waiting');
await frame.getByRole('button', { name: 'Cancel request' }).click();
await frame.getByRole('button', { name: 'Ask to join' }).waitFor();
await shoot('asking');
await frame.getByRole('button', { name: 'Ask to join' }).click();
await frame.locator('dialog[open]').waitFor();
await shoot('ask-dialog');
await frame.getByRole('button', { name: 'Send request' }).click();
await frame.getByText('Your request is waiting').waitFor();
continue;
}
// Each room whole, then a discussion opened from its list.
const whole = async (file, ready) => {
await ready();
@@ -71,10 +91,11 @@ try {
await whole(join(out, `thread-as-${name}-${view}.png`), () =>
frame.locator('li.reply').first().waitFor()
);
// The dialogs, as seen: an event opened, and pinning a note.
// The dialogs, as seen: an event opened, pinning a note, and leaving.
for (const [path, open, shot] of [
['events/', () => frame.locator('li', { hasText: 'Curb jam' }).getByRole('button'), 'event'],
['', () => frame.getByRole('button', { name: 'Pin a note' }), 'pin']
['', () => frame.getByRole('button', { name: 'Pin a note' }), 'pin'],
['people/', () => frame.getByRole('button', { name: 'Leave' }), 'leave']
]) {
await page.goto(`${site.url}/${path}`);
await frame.locator('h1').waitFor();
examples/kicker/harness/seed.mjs+1−1
@@ -126,7 +126,7 @@ export function publish(run, handle) {
'--spaces',
`${SITE_SPACE}/room,${SITE_SPACE}/calendar`,
'--acts',
'createReport',
'createReport,requestJoin,cancelJoinRequest,leaveGroup',
'--writes',
WRITES.join(',')
);
examples/kicker/site/src/lib/molecules/MemberRow.svelte+3−2
@@ -3,9 +3,9 @@
/**
* A member of the place, as a row: their picture (`avatar`, its URL to
* come, or none) and handle, the roles they hold beyond being a member,
* and their card, if they wrote one.
* and their card, if they wrote one; at its end, `act`, if any.
*/
let { handle, roles, card, avatar = null } = $props();
let { handle, roles, card, avatar = null, act } = $props();
const NAMES = { admin: 'Admin', host: 'Host' };
const held = $derived(roles.filter((r) => r !== 'member').map((r) => NAMES[r] ?? r));
</script>
@@ -20,4 +20,5 @@
{#if card?.about}<span>{card.about}</span>{/if}
{#if card?.offers}<span class="what">Can help with: {card.offers}</span>{/if}
</span>
{#if act}{@render act()}{/if}
</li>
examples/kicker/site/src/lib/organisms/JoinDialog.sveltenew+31−0
@@ -0,0 +1,31 @@
<script>
import Dialog from '../molecules/Dialog.svelte';
import { sending } from '../forms.svelte.js';
/**
* Asking to join, where an admin approves each request: its button, and
* the dialog it opens, a note for the admin, given to `ask`.
*/
let { ask } = $props();
let open = $state(false);
const form = sending(async (data) => {
await ask(String(data.get('message') ?? '').trim());
open = false;
});
</script>
<button type="button" class="big" onclick={() => (open = true)}>Ask to join</button>
<Dialog bind:open label="Ask to join">
<h2 class="dialog-title">Ask to join</h2>
<p class="lede">An admin reads each request, and lets you in.</p>
<form class="form" onsubmit={form.send}>
<label class="field"
><span>Note <span class="optional">(optional)</span></span>
<textarea name="message" rows="3" maxlength="2000"></textarea></label
>
{#if form.failed}<p class="failed" role="status">{form.failed}</p>{/if}
<div class="acts end">
<button type="button" class="quiet" onclick={() => (open = false)}>Cancel</button>
<button type="submit" disabled={form.busy}>Send request</button>
</div>
</form>
</Dialog>
examples/kicker/site/src/lib/organisms/Landing.svelte+6−6
@@ -2,11 +2,11 @@
/**
* The place's front: its name as the masthead, filling the width of its
* band; under it, its line, when and where, who gets in, and across from
* them the way in (`act`, its words `actLabel`). `note`, in place of who
* gets in, to someone signed in but not let in yet. `about`: the
* place's public face.
* them the way in (`actions`, the one act that counts first). `note`, in
* place of who gets in, to someone signed in but not let in yet.
* `about`: the place's public face.
*/
let { about, act, actLabel, note } = $props();
let { about, note, actions } = $props();
</script>
<header class="band tall">
@@ -17,8 +17,8 @@
<p class="landing-line">{about.line}</p>
<p>{about.hours}<br />{about.address}</p>
{#if note}<div class="landing-note">{@render note()}</div>{:else}<p class="landing-note">
Members only. Sign in with your atproto account, and an admin lets you in.
Members only. Sign in with your Atmosphere account, and an admin lets you in.
</p>{/if}
</div>
<button type="button" class="big" onclick={act}>{actLabel}</button>
<div class="landing-acts">{@render actions()}</div>
</div>
examples/kicker/site/src/lib/organisms/LeaveDialog.sveltenew+35−0
@@ -0,0 +1,35 @@
<script>
import Dialog from '../molecules/Dialog.svelte';
import { sending } from '../forms.svelte.js';
/**
* Leaving the place: a quiet button on the viewer's own row, and the
* dialog it opens, asking first. `leave` does it. Refused for the last
* admin, who is told how to leave all the same.
*/
let { name, leave } = $props();
let open = $state(false);
const form = sending(async () => {
try {
await leave();
} catch (e) {
if (e.name !== 'LastConfigurer') throw e;
throw new Error("You're the last admin. Make someone else an admin in the console first.");
}
});
</script>
<button type="button" class="quiet small" onclick={() => (open = true)}>Leave</button>
<Dialog bind:open label="Leave this group?">
<h2 class="dialog-title">Leave this group?</h2>
<p class="lede">
You'll lose access to {name}'s board, events, discussions and people. To come back, you ask to
join again.
</p>
<form class="form" onsubmit={form.send}>
{#if form.failed}<p class="failed" role="status">{form.failed}</p>{/if}
<div class="acts end">
<button type="button" class="quiet" onclick={() => (open = false)}>Cancel</button>
<button type="submit" class="danger" disabled={form.busy}>Leave</button>
</div>
</form>
</Dialog>
examples/kicker/site/src/lib/organisms/PeopleList.svelte+9−3
@@ -1,7 +1,12 @@
<script>
import MemberRow from '../molecules/MemberRow.svelte';
/** The place's members, those who run it first, each with their card and picture (`people`). */
let { people } = $props();
import LeaveDialog from './LeaveDialog.svelte';
/**
* The place's members, those who run it first, each with their card and
* picture (`people`); on the viewer's own row (`me`, their DID), leaving
* the place (`name`) by `leave`.
*/
let { people, me, name, leave } = $props();
</script>
<ul class="rows people">
@@ -10,5 +15,6 @@
roles={p.roles}
card={p.card}
avatar={p.avatar}
/>{/each}
>{#snippet act()}{#if p.did === me}<LeaveDialog {name} {leave} />{/if}{/snippet}</MemberRow
>{/each}
</ul>
examples/kicker/site/src/lib/place.js+26−8
@@ -25,9 +25,10 @@ export const keyOf = (uri) => uri.split('/').at(-1);
/**
* The place, who is looking, and its members: `members` a Map of DID to
* `{handle, roles}`, `viewer` their standing (`member`), and `space(kind)`
* the URI of the place's space of that kind. Signed out, or turned away
* by the host, only the place and who is looking.
* `{handle, roles}`, `viewer` their standing (`member`, and `request`
* while they ask to join), and `space(kind)` the URI of the place's space
* of that kind. Signed out, or turned away by the host, only the place
* and who is looking; signed in but not a member, their standing too.
*/
export async function context() {
const group = await os().group();
@@ -43,15 +44,18 @@ export async function context() {
};
if (!me.signedIn) return base;
try {
const [{ group: place }, { members }] = await Promise.all([
os().call('fyi.opensocial.getGroup', { group: group.did }),
os().call('fyi.opensocial.listMembers', { group: group.did, limit: 100 })
]);
const { group: place } = await os().call('fyi.opensocial.getGroup', { group: group.did });
const standing = { ...base, place, viewer: place.viewer ?? null };
if (!place.viewer?.member) return standing;
const { members } = await os().call('fyi.opensocial.listMembers', {
group: group.did,
limit: 100
});
const roles = (m) => m.roles.map((r) => r.role);
const byDid = new Map(
members.map((m) => [m.actor.did, { handle: m.actor.handle, roles: roles(m) }])
);
return { ...base, place, members: byDid, viewer: place.viewer };
return { ...standing, members: byDid };
} catch (e) {
if (e.locked) return base;
throw e;
@@ -163,6 +167,20 @@ export const report = (ctx, record, reasonType, { reason, rule } = {}) =>
export const appeal = (ctx, record, reason) =>
report(ctx, record, 'com.atproto.moderation.defs#reasonAppeal', { reason });
/**
* Joins the place, or asks to, as its join policy says, with `message`
* for the admin who reads it. An invite waiting for the visitor lets them
* in under any policy. The host's page asks it of this place, as it does
* every act.
*/
export const join = (message) => os().act('fyi.opensocial.requestJoin', message ? { message } : {});
/** Cancels the visitor's request to join, while it waits. */
export const cancelRequest = () => os().act('fyi.opensocial.cancelJoinRequest');
/** Takes the visitor out of the place. Refused, `LastConfigurer`, for its last admin. */
export const leave = () => os().act('fyi.opensocial.leaveGroup');
/** The rules a report may cite: each its title and the URI of its record. */
export const rulesOf = (ctx) =>
(ctx.place?.rules ?? []).map((r) => ({
examples/kicker/site/src/rooms/People.svelte+13−4
@@ -3,12 +3,13 @@
import CardDialog from '../lib/organisms/CardDialog.svelte';
import PeopleList from '../lib/organisms/PeopleList.svelte';
import { follow, keep, kept } from '../lib/kept.svelte.js';
import { NS, picture, put, upload } from '../lib/place.js';
import { NS, leave, picture, put, upload } from '../lib/place.js';
import { cardsByWriter, recordAt } from '../lib/views.js';
/**
* People: every member, those who run the place first, each with their
* roles and the card they keep in its room, their picture with it; and
* editing the viewer's own.
* roles and the card they keep in its room, their picture with it;
* editing the viewer's own, and leaving, after which the place is read
* again (`ctx.reread`) and shows them its landing.
*/
let { ctx } = $props();
let failed = $state('');
@@ -54,4 +55,12 @@
{#snippet act()}{#if kept.room}<CardDialog card={cards.get(ctx.me.did)} {save} />{/if}{/snippet}
</RoomHead>
{#if failed}<p class="failed">{failed}</p>{/if}
<PeopleList {people} />
<PeopleList
{people}
me={ctx.me.did}
name={ctx.place?.displayName ?? ctx.group.handle}
leave={async () => {
await leave();
await ctx.reread();
}}
/>
examples/kicker/site/src/app.css+58−2
examples/kicker/site/src/App.svelte+64−9
examples/kicker/site/src/main.js+0−2
examples/kicker/site/index.html+9−0
examples/kicker/DESIGN.md+1−1
examples/kicker/README.md+9−3