Fix: persist labels to local storage to reduce coverage gaps
This commit is contained in:
@@ -22,6 +22,7 @@ import {
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useLabelDefinitions} from '#/state/queries/preferences/moderation'
|
||||
import {useHiddenPosts} from '#/state/preferences'
|
||||
import {saveLabelers} from '#/state/session/agent-config'
|
||||
|
||||
export * from '#/state/queries/preferences/types'
|
||||
export * from '#/state/queries/preferences/moderation'
|
||||
@@ -42,6 +43,13 @@ export function usePreferencesQuery() {
|
||||
return DEFAULT_LOGGED_OUT_PREFERENCES
|
||||
} else {
|
||||
const res = await agent.getPreferences()
|
||||
|
||||
// save to local storage to ensure there are labels on initial requests
|
||||
saveLabelers(
|
||||
agent.session.did,
|
||||
res.moderationPrefs.labelers.map(l => l.did),
|
||||
)
|
||||
|
||||
const preferences: UsePreferencesQueryResponse = {
|
||||
...res,
|
||||
feeds: {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
|
||||
const PREFIX = 'agent-labelers'
|
||||
|
||||
export async function saveLabelers(did: string, value: string[]) {
|
||||
await AsyncStorage.setItem(`${PREFIX}:${did}`, JSON.stringify(value))
|
||||
}
|
||||
|
||||
export async function readLabelers(did: string): Promise<string[] | undefined> {
|
||||
const rawData = await AsyncStorage.getItem(`${PREFIX}:${did}`)
|
||||
return rawData ? JSON.parse(rawData) : undefined
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {track} from '#/lib/analytics/analytics'
|
||||
import {hasProp} from '#/lib/type-guards'
|
||||
import {readLabelers} from './agent-config'
|
||||
|
||||
let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT
|
||||
|
||||
@@ -661,12 +662,23 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
|
||||
async function configureModeration(agent: BskyAgent, account: SessionAccount) {
|
||||
if (IS_TEST_USER(account.handle)) {
|
||||
console.warn('USING TEST ENV MODERATION')
|
||||
const did = (await agent.resolveHandle({handle: 'mod-authority.test'})).data
|
||||
.did
|
||||
BskyAgent.configure({appLabelers: [did]})
|
||||
const did = (
|
||||
await agent
|
||||
.resolveHandle({handle: 'mod-authority.test'})
|
||||
.catch(_ => undefined)
|
||||
)?.data.did
|
||||
if (did) {
|
||||
console.warn('USING TEST ENV MODERATION')
|
||||
BskyAgent.configure({appLabelers: [did]})
|
||||
}
|
||||
} else {
|
||||
BskyAgent.configure({appLabelers: [BSKY_LABELER_DID]})
|
||||
const labelerDids = await readLabelers(account.did).catch(_ => {})
|
||||
if (labelerDids) {
|
||||
agent.configureLabelersHeader(
|
||||
labelerDids.filter(did => did !== BSKY_LABELER_DID),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user