Live video on the AT Protocol
1import { AppBskyGraphBlock } from "@atproto/api";
2import { useState } from "react";
3import { usePDSAgent } from "./xrpc";
4
5export function useCreateBlockRecord() {
6 let agent = usePDSAgent();
7 const [isLoading, setIsLoading] = useState(false);
8
9 const createBlock = async (subjectDID: string) => {
10 if (!agent) {
11 throw new Error("No PDS agent found");
12 }
13
14 if (!agent.did) {
15 throw new Error("No user DID found, assuming not logged in");
16 }
17
18 setIsLoading(true);
19 try {
20 const record: AppBskyGraphBlock.Record = {
21 $type: "app.bsky.graph.block",
22 subject: subjectDID,
23 createdAt: new Date().toISOString(),
24 };
25 const result = await agent.com.atproto.repo.createRecord({
26 repo: agent.did,
27 collection: "app.bsky.graph.block",
28 record,
29 });
30 return result;
31 } finally {
32 setIsLoading(false);
33 }
34 };
35
36 return { createBlock, isLoading };
37}
38
39export function useCreateHideChatRecord() {
40 let agent = usePDSAgent();
41 const [isLoading, setIsLoading] = useState(false);
42
43 const createHideChat = async (chatMessageUri: string) => {
44 if (!agent) {
45 throw new Error("No PDS agent found");
46 }
47
48 if (!agent.did) {
49 throw new Error("No user DID found, assuming not logged in");
50 }
51
52 setIsLoading(true);
53 try {
54 const record = {
55 $type: "place.stream.chat.gate",
56 hiddenMessage: chatMessageUri,
57 };
58
59 const result = await agent.com.atproto.repo.createRecord({
60 repo: agent.did,
61 collection: "place.stream.chat.gate",
62 record,
63 });
64 return result;
65 } finally {
66 setIsLoading(false);
67 }
68 };
69
70 return { createHideChat, isLoading };
71}