-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set up hidden posts persisted state * Wrap moderatePost * Integrate hidden posts into moderation * Complete hide-post behaviors --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
- Loading branch information
1 parent
28e0df5
commit b199405
Showing
12 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {moderatePost} from '@atproto/api' | ||
|
||
type ModeratePost = typeof moderatePost | ||
type Options = Parameters<ModeratePost>[1] & { | ||
hiddenPosts?: string[] | ||
} | ||
|
||
export function moderatePost_wrapped( | ||
subject: Parameters<ModeratePost>[0], | ||
opts: Options, | ||
) { | ||
const {hiddenPosts = [], ...options} = opts | ||
const moderations = moderatePost(subject, options) | ||
|
||
if (hiddenPosts.includes(subject.uri)) { | ||
moderations.content.filter = true | ||
moderations.content.blur = true | ||
if (!moderations.content.cause) { | ||
moderations.content.cause = { | ||
// @ts-ignore Temporary extension to the moderation system -prf | ||
type: 'post-hidden', | ||
source: {type: 'user'}, | ||
priority: 1, | ||
} | ||
} | ||
} | ||
|
||
return moderations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react' | ||
import * as persisted from '#/state/persisted' | ||
|
||
type SetStateCb = ( | ||
s: persisted.Schema['hiddenPosts'], | ||
) => persisted.Schema['hiddenPosts'] | ||
type StateContext = persisted.Schema['hiddenPosts'] | ||
type ApiContext = { | ||
hidePost: ({uri}: {uri: string}) => void | ||
unhidePost: ({uri}: {uri: string}) => void | ||
} | ||
|
||
const stateContext = React.createContext<StateContext>( | ||
persisted.defaults.hiddenPosts, | ||
) | ||
const apiContext = React.createContext<ApiContext>({ | ||
hidePost: () => {}, | ||
unhidePost: () => {}, | ||
}) | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
const [state, setState] = React.useState(persisted.get('hiddenPosts')) | ||
|
||
const setStateWrapped = React.useCallback( | ||
(fn: SetStateCb) => { | ||
const s = fn(persisted.get('hiddenPosts')) | ||
setState(s) | ||
persisted.write('hiddenPosts', s) | ||
}, | ||
[setState], | ||
) | ||
|
||
const api = React.useMemo( | ||
() => ({ | ||
hidePost: ({uri}: {uri: string}) => { | ||
setStateWrapped(s => [...(s || []), uri]) | ||
}, | ||
unhidePost: ({uri}: {uri: string}) => { | ||
setStateWrapped(s => (s || []).filter(u => u !== uri)) | ||
}, | ||
}), | ||
[setStateWrapped], | ||
) | ||
|
||
React.useEffect(() => { | ||
return persisted.onUpdate(() => { | ||
setState(persisted.get('hiddenPosts')) | ||
}) | ||
}, [setStateWrapped]) | ||
|
||
return ( | ||
<stateContext.Provider value={state}> | ||
<apiContext.Provider value={api}>{children}</apiContext.Provider> | ||
</stateContext.Provider> | ||
) | ||
} | ||
|
||
export function useHiddenPosts() { | ||
return React.useContext(stateContext) | ||
} | ||
|
||
export function useHiddenPostsApi() { | ||
return React.useContext(apiContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import React from 'react' | ||
import {Provider as LanguagesProvider} from './languages' | ||
import {Provider as AltTextRequiredProvider} from '../preferences/alt-text-required' | ||
import {Provider as HiddenPostsProvider} from '../preferences/hidden-posts' | ||
|
||
export {useLanguagePrefs, useLanguagePrefsApi} from './languages' | ||
export { | ||
useRequireAltTextEnabled, | ||
useSetRequireAltTextEnabled, | ||
} from './alt-text-required' | ||
export * from './hidden-posts' | ||
|
||
export function Provider({children}: React.PropsWithChildren<{}>) { | ||
return ( | ||
<LanguagesProvider> | ||
<AltTextRequiredProvider>{children}</AltTextRequiredProvider> | ||
<AltTextRequiredProvider> | ||
<HiddenPostsProvider>{children}</HiddenPostsProvider> | ||
</AltTextRequiredProvider> | ||
</LanguagesProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters