frontend client for gemstone. decentralised workplace app
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add membership function

serenity b9799e2b 984f58fd

+43 -1
+43 -1
src/lib/utils/gmstn.ts
··· 8 8 import type { SystemsGmstnDevelopmentLattice } from "@/lib/types/lexicon/systems.gmstn.development.lattice"; 9 9 import type { SystemsGmstnDevelopmentChannelInvite } from "@/lib/types/lexicon/systems.gmstn.development.channel.invite"; 10 10 import type { SystemsGmstnDevelopmentChannel } from "@/lib/types/lexicon/systems.gmstn.development.channel"; 11 + import type { SystemsGmstnDevelopmentChannelMembership } from "@/lib/types/lexicon/systems.gmstn.development.channel.membership"; 11 12 12 13 export const getLatticeEndpointFromDid = async (did: Did) => { 13 14 return await getEndpointFromDid(did, "GemstoneLattice"); ··· 152 153 agent: Agent; 153 154 }): Promise<Result<undefined, string>> => { 154 155 const now = new Date(); 155 - const rkey = TID.create(now.getTime(), Math.random()); 156 + const rkey = TID.create(now.getTime(), Math.floor(Math.random() * 1023)); 156 157 157 158 const record: Omit<SystemsGmstnDevelopmentChannel, "$type"> = { 158 159 // @ts-expect-error we want to explicitly use the ISO string variant ··· 179 180 180 181 return { ok: true }; 181 182 }; 183 + 184 + export const addMembership = async ({ 185 + membershipInfo, 186 + agent, 187 + }: { 188 + membershipInfo: Omit< 189 + SystemsGmstnDevelopmentChannelMembership, 190 + "$type" | "createdAt" | "updatedAt" 191 + >; 192 + agent: Agent; 193 + }): Promise<Result<undefined, string>> => { 194 + const now = new Date(); 195 + const rkey = TID.create(now.getTime(), Math.floor(Math.random() * 1023)); 196 + 197 + const record: Omit<SystemsGmstnDevelopmentChannelMembership, "$type"> = { 198 + // @ts-expect-error we want to explicitly use the ISO string variant 199 + createdAt: now.toISOString(), 200 + // @ts-expect-error we want to explicitly use the ISO string variant 201 + updatedAt: now.toISOString(), 202 + ...membershipInfo, 203 + }; 204 + 205 + const { success } = await agent.call( 206 + "com.atproto.repo.createRecord", 207 + {}, 208 + { 209 + repo: agent.did, 210 + collection: "systems.gmstn.development.channel.membership", 211 + rkey, 212 + record, 213 + }, 214 + ); 215 + 216 + if (!success) 217 + return { 218 + ok: false, 219 + error: "Attempted to create channel record failed. Check the channel info inputs.", 220 + }; 221 + 222 + return { ok: true }; 223 + };