frontend client for gemstone. decentralised workplace app
1
fork

Configure Feed

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

feat: channel creation helper

serenity 69fd0fac 0c59bd5f

+38
+38
src/lib/utils/gmstn.ts
··· 7 7 import * as TID from "@atcute/tid"; 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 + import type { SystemsGmstnDevelopmentChannel } from "@/lib/types/lexicon/systems.gmstn.development.channel"; 10 11 11 12 export const getLatticeEndpointFromDid = async (did: Did) => { 12 13 return await getEndpointFromDid(did, "GemstoneLattice"); ··· 142 143 143 144 return { ok: true }; 144 145 }; 146 + 147 + export const addChannel = async ({ 148 + channelInfo, 149 + agent, 150 + }: { 151 + did: Did; 152 + channelInfo: Omit<SystemsGmstnDevelopmentChannel, "$type" | "createdAt">; 153 + agent: Agent; 154 + }): Promise<Result<undefined, string>> => { 155 + const now = new Date(); 156 + const rkey = TID.create(now.getTime(), Math.random()); 157 + 158 + const record: Omit<SystemsGmstnDevelopmentChannel, "$type"> = { 159 + // @ts-expect-error we want to explicitly use the ISO string variant 160 + createdAt: now.toISOString(), 161 + ...channelInfo, 162 + }; 163 + 164 + const { success } = await agent.call( 165 + "com.atproto.repo.createRecord", 166 + {}, 167 + { 168 + repo: agent.did, 169 + collection: "systems.gmstn.development.channel", 170 + rkey, 171 + record, 172 + }, 173 + ); 174 + 175 + if (!success) 176 + return { 177 + ok: false, 178 + error: "Attempted to create channel record failed. Check the channel info inputs.", 179 + }; 180 + 181 + return { ok: true }; 182 + };