simplify threadgate/postgate handling
This commit is contained in:
@@ -14,9 +14,12 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
|||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {type AppModerationCause} from '#/components/Pills'
|
import {type AppModerationCause} from '#/components/Pills'
|
||||||
|
|
||||||
export const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn']
|
export const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn'] as const
|
||||||
export const OTHER_SELF_LABELS = ['graphic-media']
|
export const OTHER_SELF_LABELS = ['graphic-media'] as const
|
||||||
export const SELF_LABELS = [...ADULT_CONTENT_LABELS, ...OTHER_SELF_LABELS]
|
export const SELF_LABELS = [
|
||||||
|
...ADULT_CONTENT_LABELS,
|
||||||
|
...OTHER_SELF_LABELS,
|
||||||
|
] as const
|
||||||
|
|
||||||
export type AdultSelfLabel = (typeof ADULT_CONTENT_LABELS)[number]
|
export type AdultSelfLabel = (typeof ADULT_CONTENT_LABELS)[number]
|
||||||
export type OtherSelfLabel = (typeof OTHER_SELF_LABELS)[number]
|
export type OtherSelfLabel = (typeof OTHER_SELF_LABELS)[number]
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import {type ImagePickerAsset} from 'expo-image-picker'
|
import {type ImagePickerAsset} from 'expo-image-picker'
|
||||||
import {
|
import {
|
||||||
|
type AppBskyActorDefs,
|
||||||
|
type AppBskyDraftDefs,
|
||||||
type AppBskyFeedPostgate,
|
type AppBskyFeedPostgate,
|
||||||
AppBskyRichtextFacet,
|
AppBskyRichtextFacet,
|
||||||
type BskyPreferences,
|
|
||||||
RichText,
|
RichText,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {nanoid} from 'nanoid/non-secure'
|
import {nanoid} from 'nanoid/non-secure'
|
||||||
@@ -132,12 +133,17 @@ export type ComposerAction =
|
|||||||
type: 'restore_from_draft'
|
type: 'restore_from_draft'
|
||||||
draftId: string
|
draftId: string
|
||||||
posts: PostDraft[]
|
posts: PostDraft[]
|
||||||
threadgate: Array<{type: string; list?: string}>
|
threadgateAllow: AppBskyDraftDefs.Draft['threadgateAllow']
|
||||||
|
postgateEmbeddingRules: AppBskyDraftDefs.Draft['postgateEmbeddingRules']
|
||||||
|
|
||||||
/** Map of localRefPath -> loaded media path/URL */
|
/** Map of localRefPath -> loaded media path/URL */
|
||||||
loadedMedia: Map<string, string>
|
loadedMedia: Map<string, string>
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'clear'
|
type: 'clear'
|
||||||
|
initInteractionSettings:
|
||||||
|
| AppBskyActorDefs.PostInteractionSettingsPref
|
||||||
|
| undefined
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: 'mark_saved'
|
type: 'mark_saved'
|
||||||
@@ -256,23 +262,13 @@ export function composerReducer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'restore_from_draft': {
|
case 'restore_from_draft': {
|
||||||
const {draftId, posts, threadgate, loadedMedia} = action
|
const {
|
||||||
|
draftId,
|
||||||
// Convert threadgate to UI settings format
|
posts,
|
||||||
const threadgateSettings: ThreadgateAllowUISetting[] = threadgate.map(
|
threadgateAllow,
|
||||||
rule => {
|
postgateEmbeddingRules,
|
||||||
if (rule.type === 'mention') {
|
loadedMedia,
|
||||||
return {type: 'mention'} as ThreadgateAllowUISetting
|
} = action
|
||||||
} else if (rule.type === 'following') {
|
|
||||||
return {type: 'following'} as ThreadgateAllowUISetting
|
|
||||||
} else if (rule.type === 'followers') {
|
|
||||||
return {type: 'followers'} as ThreadgateAllowUISetting
|
|
||||||
} else if (rule.type === 'list' && rule.list) {
|
|
||||||
return {type: 'list', list: rule.list} as ThreadgateAllowUISetting
|
|
||||||
}
|
|
||||||
return {type: 'mention'} as ThreadgateAllowUISetting // fallback
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activePostIndex: 0,
|
activePostIndex: 0,
|
||||||
@@ -282,40 +278,27 @@ export function composerReducer(
|
|||||||
loadedMediaMap: loadedMedia,
|
loadedMediaMap: loadedMedia,
|
||||||
thread: {
|
thread: {
|
||||||
posts,
|
posts,
|
||||||
postgate: state.thread.postgate,
|
postgate: createPostgateRecord({
|
||||||
threadgate:
|
post: '',
|
||||||
threadgateSettings.length > 0
|
embeddingRules: postgateEmbeddingRules,
|
||||||
? threadgateSettings
|
}),
|
||||||
: state.thread.threadgate,
|
threadgate: threadgateRecordToAllowUISetting({
|
||||||
|
$type: 'app.bsky.feed.threadgate',
|
||||||
|
post: '',
|
||||||
|
createdAt: new Date().toString(),
|
||||||
|
allow: threadgateAllow,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'clear': {
|
case 'clear': {
|
||||||
return {
|
return createComposerState({
|
||||||
activePostIndex: 0,
|
initText: undefined,
|
||||||
mutableNeedsFocusActive: true,
|
initMention: undefined,
|
||||||
draftId: undefined,
|
initImageUris: [],
|
||||||
isDirty: false,
|
initQuoteUri: undefined,
|
||||||
loadedMediaMap: undefined,
|
initInteractionSettings: action.postInteractionSettings,
|
||||||
thread: {
|
})
|
||||||
posts: [
|
|
||||||
{
|
|
||||||
id: nanoid(),
|
|
||||||
richtext: new RichText({text: ''}),
|
|
||||||
shortenedGraphemeLength: 0,
|
|
||||||
labels: [],
|
|
||||||
embed: {
|
|
||||||
quote: undefined,
|
|
||||||
media: undefined,
|
|
||||||
link: undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
// Keep the user's default interaction settings
|
|
||||||
postgate: state.thread.postgate,
|
|
||||||
threadgate: state.thread.threadgate,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 'mark_saved': {
|
case 'mark_saved': {
|
||||||
return {
|
return {
|
||||||
@@ -589,7 +572,7 @@ export function createComposerState({
|
|||||||
initImageUris: ComposerOpts['imageUris']
|
initImageUris: ComposerOpts['imageUris']
|
||||||
initQuoteUri: string | undefined
|
initQuoteUri: string | undefined
|
||||||
initInteractionSettings:
|
initInteractionSettings:
|
||||||
| BskyPreferences['postInteractionSettings']
|
| AppBskyActorDefs.PostInteractionSettingsPref
|
||||||
| undefined
|
| undefined
|
||||||
}): ComposerState {
|
}): ComposerState {
|
||||||
let media: ImagesMedia | undefined
|
let media: ImagesMedia | undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user