frontend client for gemstone. decentralised workplace app

feat: add membership function

serenity b9799e2b 984f58fd

Changed files
+43 -1
src
lib
utils
+43 -1
src/lib/utils/gmstn.ts
···
import type { SystemsGmstnDevelopmentLattice } from "@/lib/types/lexicon/systems.gmstn.development.lattice";
import type { SystemsGmstnDevelopmentChannelInvite } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite";
import type { SystemsGmstnDevelopmentChannel } from "@/lib/types/lexicon/systems.gmstn.development.channel";
+
import type { SystemsGmstnDevelopmentChannelMembership } from "@/lib/types/lexicon/systems.gmstn.development.channel.membership";
export const getLatticeEndpointFromDid = async (did: Did) => {
return await getEndpointFromDid(did, "GemstoneLattice");
···
agent: Agent;
}): Promise<Result<undefined, string>> => {
const now = new Date();
-
const rkey = TID.create(now.getTime(), Math.random());
+
const rkey = TID.create(now.getTime(), Math.floor(Math.random() * 1023));
const record: Omit<SystemsGmstnDevelopmentChannel, "$type"> = {
// @ts-expect-error we want to explicitly use the ISO string variant
···
return { ok: true };
};
+
+
export const addMembership = async ({
+
membershipInfo,
+
agent,
+
}: {
+
membershipInfo: Omit<
+
SystemsGmstnDevelopmentChannelMembership,
+
"$type" | "createdAt" | "updatedAt"
+
>;
+
agent: Agent;
+
}): Promise<Result<undefined, string>> => {
+
const now = new Date();
+
const rkey = TID.create(now.getTime(), Math.floor(Math.random() * 1023));
+
+
const record: Omit<SystemsGmstnDevelopmentChannelMembership, "$type"> = {
+
// @ts-expect-error we want to explicitly use the ISO string variant
+
createdAt: now.toISOString(),
+
// @ts-expect-error we want to explicitly use the ISO string variant
+
updatedAt: now.toISOString(),
+
...membershipInfo,
+
};
+
+
const { success } = await agent.call(
+
"com.atproto.repo.createRecord",
+
{},
+
{
+
repo: agent.did,
+
collection: "systems.gmstn.development.channel.membership",
+
rkey,
+
record,
+
},
+
);
+
+
if (!success)
+
return {
+
ok: false,
+
error: "Attempted to create channel record failed. Check the channel info inputs.",
+
};
+
+
return { ok: true };
+
};