mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
p2 (Pi Mobile on Chord v2) moves from pi-private into pi as one commit. Root scripts that loop all workspaces use --if-present; npm test, ./test.sh and the release script cover packages/* only (p2: cd apps/p2 && npm test); sync-versions also updates apps' workspace pins.
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { arr, num, obj, type Static, str, union } from "@earendil-works/pi-schema";
|
|
import { literal, local, method, param, record, remote, sessionHost } from "@p2/app/v1";
|
|
|
|
export const AuthorSchema = obj({
|
|
kind: union([literal("owner"), literal("guest")]),
|
|
id: str(),
|
|
name: str(),
|
|
});
|
|
|
|
export const DraftSchema = obj({ id: num(), text: str() });
|
|
export type Draft = Static<typeof DraftSchema>;
|
|
|
|
/** Restored drafts by `<conversation>:<author id>`, oldest first. */
|
|
export const DraftsByKeySchema = record(arr(DraftSchema));
|
|
|
|
export const draftKey = (conversation: number, authorId: string): string => `${conversation}:${authorId}`;
|
|
|
|
/**
|
|
* Inputs withdrawn by someone else (Stop, a queue edit) wait here for their author (worker, in memory, for the
|
|
* worker's lifetime). Each is claimed once: the first of an author's tabs to claim it puts it into its composer.
|
|
*/
|
|
export const DraftStore = local("p2.draft-store", {
|
|
version: 1,
|
|
params: {},
|
|
members: {
|
|
drafts: DraftsByKeySchema,
|
|
add: method(
|
|
obj({
|
|
conversation: num(),
|
|
items: arr(obj({ author: AuthorSchema, text: str() })),
|
|
}),
|
|
),
|
|
claim: method(obj({ conversation: num(), authorId: str(), ids: arr(num()) }), obj({ texts: arr(str()) })),
|
|
},
|
|
});
|
|
|
|
/** The caller's own restored drafts in one conversation (participants only). */
|
|
export const Drafts = remote("p2.drafts", {
|
|
version: 1,
|
|
params: { session: param.str(), conversation: param.int() },
|
|
hostAddress: sessionHost,
|
|
variants: {
|
|
author: {
|
|
state: { drafts: arr(DraftSchema) },
|
|
methods: {
|
|
/** Removes the drafts and returns the texts of those still there (another tab may have taken some). */
|
|
claim: method(obj({ ids: arr(num()) }), obj({ texts: arr(str()) })),
|
|
},
|
|
},
|
|
},
|
|
});
|