this repo has no description
0
fork

Configure Feed

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

Apply labelers and handle language for PWI home (#5816)

authored by

Eric Bailey and committed by
GitHub
05ca9795 e9be8f45

+30 -4
+20 -4
src/lib/api/feed/custom.ts
··· 5 5 jsonStringToLex, 6 6 } from '@atproto/api' 7 7 8 - import {getContentLanguages} from '#/state/preferences/languages' 8 + import { 9 + getAppLanguageAsContentLanguage, 10 + getContentLanguages, 11 + } from '#/state/preferences/languages' 9 12 import {FeedAPI, FeedAPIResponse} from './types' 10 13 import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils' 11 14 ··· 103 106 limit: number 104 107 cursor?: string 105 108 }) { 106 - let contentLangs = getContentLanguages().join(',') 109 + let contentLangs = getAppLanguageAsContentLanguage() 110 + 111 + /** 112 + * Copied from our root `Agent` class 113 + * @see https://github.com/bluesky-social/atproto/blob/60df3fc652b00cdff71dd9235d98a7a4bb828f05/packages/api/src/agent.ts#L120 114 + */ 115 + const labelersHeader = { 116 + 'atproto-accept-labelers': BskyAgent.appLabelers 117 + .map(l => `${l};redact`) 118 + .join(', '), 119 + } 107 120 108 121 // manually construct fetch call so we can add the `lang` cache-busting param 109 122 let res = await fetch( 110 123 `https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${ 111 124 cursor ? `&cursor=${cursor}` : '' 112 125 }&limit=${limit}&lang=${contentLangs}`, 113 - {method: 'GET', headers: {'Accept-Language': contentLangs}}, 126 + { 127 + method: 'GET', 128 + headers: {'Accept-Language': contentLangs, ...labelersHeader}, 129 + }, 114 130 ) 115 131 let data = res.ok ? jsonStringToLex(await res.text()) : null 116 132 if (data?.feed?.length) { ··· 125 141 `https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=${feed}${ 126 142 cursor ? `&cursor=${cursor}` : '' 127 143 }&limit=${limit}`, 128 - {method: 'GET', headers: {'Accept-Language': ''}}, 144 + {method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}}, 129 145 ) 130 146 data = res.ok ? jsonStringToLex(await res.text()) : null 131 147 if (data?.feed?.length) {
+10
src/state/preferences/languages.tsx
··· 139 139 return persisted.get('languagePrefs').contentLanguages 140 140 } 141 141 142 + /** 143 + * Be careful with this. It's used for the PWI home screen so that users can 144 + * select a UI language and have it apply to the fetched Discover feed. 145 + * 146 + * We only support BCP-47 two-letter codes here, hence the split. 147 + */ 148 + export function getAppLanguageAsContentLanguage() { 149 + return persisted.get('languagePrefs').appLanguage.split('-')[0] 150 + } 151 + 142 152 export function toPostLanguages(postLanguage: string): string[] { 143 153 // filter out empty strings if exist 144 154 return postLanguage.split(',').filter(Boolean)