Skip to content

Commit 136e757

Browse files
matt2eclaude
andcommitted
fix(communities): give synced-in communities their local name and presentation
A membership the account's list adds now reads the viewer's saved local name and starts a presentation read, as joining does. No fence is needed: only absent memberships are added, and leaving one already fenced and aborted its read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent c6e2b6b commit 136e757

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

‎src/features/communities/service.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Context } from "@deepseek-ai/cordis";
22
import { assert, afterEach, expect, it, vi } from "vitest";
33
import { createCommunities } from "./service";
44
import { communityDestination } from "./destination";
5+
import { localCommunityNameKey } from "./names";
56
import * as destinations from "./destination";
67
import { flush } from "../relay/testing";
78
import type { ReadTransport } from "../relay/transport";
@@ -907,6 +908,27 @@ it("applies a server list in one record write: adds under the host name, forgets
907908
expect(requests.filter((url) => url.endsWith("/session"))).toHaveLength(2);
908909
});
909910

911+
it("a synced-in community shows the viewer's local name and reads its presentation", async () => {
912+
const client = setup();
913+
await flush();
914+
localStorage.setItem(
915+
localCommunityNameKey("https://new.example", viewer),
916+
"Mine",
917+
);
918+
const release = client.retainPresentation();
919+
await client.applySync({ known: ["wss://new.example"], outbox: [] }, [
920+
"wss://new.example",
921+
]);
922+
expect(client.snapshot().memberships).toEqual([
923+
{ id: "https://new.example", name: "new.example", localName: "Mine" },
924+
]);
925+
await flush();
926+
expect(requests).toContain(
927+
`/api/relay/${encodeURIComponent("https://new.example")}/icon-info`,
928+
);
929+
release();
930+
});
931+
910932
it("a native sync write that will not save throws before anything changes", async () => {
911933
const nativeViewer = "c".repeat(64);
912934
const storage = new Map([

‎src/features/communities/service.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,17 +579,26 @@ export function createCommunities(
579579
pendingSync: () => state.sync.outbox,
580580
/** Writes the sync owner's settled state and, in the same device record,
581581
* the memberships a server list adds: destinations saved on another
582-
* device appear here under their host name without a session. Sync never
583-
* forgets a membership. Persistence follows `joined`, and that save is the
584-
* only step that throws, before anything has changed. */
582+
* device appear here under their host name, or the viewer's local name
583+
* for them, without a session. Sync never forgets a membership.
584+
* Persistence follows `joined`, and that save is the only step that
585+
* throws, before anything has changed. */
585586
async applySync(next: SyncState, add: string[] = []) {
586587
const memberships = [...state.memberships];
587588
for (const url of add) {
588589
const { id, name } = communityDestination(url);
589-
if (!memberships.some((m) => m.id === id))
590-
memberships.push({ id, name });
590+
if (memberships.some((m) => m.id === id)) continue;
591+
memberships.push({
592+
id,
593+
name,
594+
...(state.viewer
595+
? { localName: readLocalCommunityName(id, state.viewer) }
596+
: {}),
597+
});
591598
}
599+
const added = memberships.length > state.memberships.length;
592600
update({ memberships, sync: next }, true, !!nativeConnect && !live);
601+
if (added) refreshPresentation();
593602
},
594603
};
595604
}

0 commit comments

Comments
 (0)