Live video on the AT Protocol

Merge remote-tracking branch 'origin/natb/more-strict-profile-creation' into many-nat-prs

+19 -6
+19 -6
js/components/src/streamplace-store/user.tsx
··· 1 + import { Response } from "@atproto/api/dist/client/types/com/atproto/repo/getRecord"; 1 2 import { PlaceStreamChatProfile } from "streamplace"; 2 3 import { 3 4 getStreamplaceStoreFromContext, ··· 16 17 if (!did || !pdsAgent) { 17 18 throw new Error("No DID or PDS agent"); 18 19 } 19 - let res; 20 + let res: Response | undefined; 21 + let notFound = false; 20 22 try { 21 23 res = await pdsAgent.com.atproto.repo.getRecord({ 22 24 repo: did, ··· 24 26 rkey: "self", 25 27 }); 26 28 } catch (e) { 27 - console.error( 28 - "Failed to get chat profile record, attempting creation", 29 - e, 30 - ); 29 + // if the record is a 400 with "Record not found", then we want to create an empty chat profile 30 + if ( 31 + e.error.status === 400 && 32 + e.error.data?.error.includes("Record not found") 33 + ) { 34 + notFound = true; 35 + } else { 36 + console.error("Failed to get chat profile record", e); 37 + } 31 38 } 32 - if (!res || !res.success) { 39 + if (notFound || (res && !res.success)) { 33 40 try { 34 41 await createEmptyChatProfile(); 35 42 res = await pdsAgent.com.atproto.repo.getRecord({ ··· 40 47 } catch (e) { 41 48 console.error("Failed to create empty chat profile record", e); 42 49 } 50 + } 51 + 52 + // if no response, assume some fluke happened and just return without setting state 53 + if (res === undefined) { 54 + console.error("No response from get or create chat profile"); 55 + return; 43 56 } 44 57 45 58 if (PlaceStreamChatProfile.isRecord(res.data.value)) {