mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

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

Migrate local thread mutes (#4523)

* migrate thread mutes

* don't try and clear if not logged in yet

* migrate mutes one at a time

* write before mutating

* only migrate mutes of self posts

* use /** @deprecated */

* shouldLike -> shouldMute

authored by samuel.fm and committed by

GitHub 0012d123 502bcad7

+58 -4
+54 -1
src/state/cache/thread-mutes.tsx
··· 1 - import React from 'react' 1 + import React, {useEffect} from 'react' 2 + 3 + import * as persisted from '#/state/persisted' 4 + import {useAgent, useSession} from '../session' 2 5 3 6 type StateContext = Map<string, boolean> 4 7 type SetStateContext = (uri: string, value: boolean) => void ··· 21 24 }, 22 25 [setState], 23 26 ) 27 + 28 + useMigrateMutes(setThreadMute) 29 + 24 30 return ( 25 31 <stateContext.Provider value={state}> 26 32 <setStateContext.Provider value={setThreadMute}> ··· 42 48 export function useSetThreadMute() { 43 49 return React.useContext(setStateContext) 44 50 } 51 + 52 + function useMigrateMutes(setThreadMute: SetStateContext) { 53 + const agent = useAgent() 54 + const {currentAccount} = useSession() 55 + 56 + useEffect(() => { 57 + if (currentAccount) { 58 + if ( 59 + !persisted 60 + .get('mutedThreads') 61 + .some(uri => uri.includes(currentAccount.did)) 62 + ) { 63 + return 64 + } 65 + 66 + let cancelled = false 67 + 68 + const migrate = async () => { 69 + while (!cancelled) { 70 + const threads = persisted.get('mutedThreads') 71 + 72 + const root = threads.findLast(uri => uri.includes(currentAccount.did)) 73 + 74 + if (!root) break 75 + 76 + persisted.write( 77 + 'mutedThreads', 78 + threads.filter(uri => uri !== root), 79 + ) 80 + 81 + setThreadMute(root, true) 82 + 83 + await agent.api.app.bsky.graph 84 + .muteThread({root}) 85 + // not a big deal if this fails, since the post might have been deleted 86 + .catch(console.error) 87 + } 88 + } 89 + 90 + migrate() 91 + 92 + return () => { 93 + cancelled = true 94 + } 95 + } 96 + }, [agent, currentAccount, setThreadMute]) 97 + }
+2 -1
src/state/persisted/schema.ts
··· 74 74 flickr: z.enum(externalEmbedOptions).optional(), 75 75 }) 76 76 .optional(), 77 - mutedThreads: z.array(z.string()), // should move to server 78 77 invites: z.object({ 79 78 copiedInvites: z.array(z.string()), 80 79 }), ··· 88 87 disableHaptics: z.boolean().optional(), 89 88 disableAutoplay: z.boolean().optional(), 90 89 kawaii: z.boolean().optional(), 90 + /** @deprecated */ 91 + mutedThreads: z.array(z.string()), 91 92 }) 92 93 export type Schema = z.infer<typeof schema> 93 94
+2 -2
src/state/queries/post.ts
··· 304 304 305 305 const queueToggle = useToggleMutationQueue<boolean>({ 306 306 initialState: isThreadMuted, 307 - runMutation: async (_prev, shouldLike) => { 308 - if (shouldLike) { 307 + runMutation: async (_prev, shouldMute) => { 308 + if (shouldMute) { 309 309 await threadMuteMutation.mutateAsync({ 310 310 uri: rootUri, 311 311 })