A work-in-progress chat bot for Streamplace with chat overlay functionality
2
fork

Configure Feed

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

Deleted labelUtils, once used for pronoun label fetching, now unused, maybe it could make sense to fetch moderation labels at some point in the future

-85
-85
utils/labelUtils.ts
··· 1 - // Response types from label APIs 2 - interface Label { 3 - id: number; 4 - src: string; 5 - uri: string; 6 - val: string; 7 - neg: boolean; 8 - cts: string; 9 - sig: { $bytes: string }; 10 - ver: number; 11 - } 12 - 13 - interface LabelApiResponse { 14 - cursor?: string; 15 - labels: Label[]; 16 - } 17 - 18 - interface LabelDefinition { 19 - identifier: string; 20 - locales: Array<{ 21 - lang: string; 22 - name: string; 23 - description: string; 24 - }>; 25 - blurs: string; 26 - severity: string; 27 - adultOnly: boolean; 28 - defaultSetting: string; 29 - } 30 - 31 - interface LabelServiceDefinition { 32 - policies: { 33 - labelValues: string[]; 34 - labelValueDefinitions: LabelDefinition[]; 35 - }; 36 - } 37 - 38 - // Generic label fetching 39 - export async function fetchLabels( 40 - apiBase: string, 41 - _definitionsEndpoint: string, 42 - dids: string[], 43 - ): Promise<Map<string, Label[]>> { 44 - const results = new Map<string, Label[]>(); 45 - 46 - if (dids.length === 0) { 47 - return results; 48 - } 49 - 50 - try { 51 - // Batch request for labels 52 - const uriPatterns = dids.join(","); 53 - const labelsResponse = await fetch( 54 - `${apiBase}/com.atproto.label.queryLabels?uriPatterns=${ 55 - encodeURIComponent(uriPatterns) 56 - }`, 57 - ); 58 - 59 - if (!labelsResponse.ok) { 60 - console.warn("Failed to batch fetch labels"); 61 - return results; 62 - } 63 - 64 - const data = await labelsResponse.json() as LabelApiResponse; 65 - 66 - // Group labels by DID 67 - for (const label of data.labels) { 68 - if (!results.has(label.uri)) { 69 - results.set(label.uri, []); 70 - } 71 - results.get(label.uri)!.push(label); 72 - } 73 - 74 - // Ensure all requested DIDs have an entry 75 - for (const did of dids) { 76 - if (!results.has(did)) { 77 - results.set(did, []); 78 - } 79 - } 80 - } catch (error) { 81 - console.error("Error in batch label fetch:", error); 82 - } 83 - 84 - return results; 85 - }