Write submission records
This commit is contained in:
@@ -18,6 +18,7 @@ import {isNetworkError} from '#/lib/strings/errors'
|
||||
import {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip'
|
||||
import {logger} from '#/logger'
|
||||
import {compressImage} from '#/state/gallery'
|
||||
import {writeFeedSubmissionRecords} from '#/state/queries/feedgens'
|
||||
import {writePostgateRecord} from '#/state/queries/postgate'
|
||||
import {
|
||||
fetchResolveGifQuery,
|
||||
@@ -173,6 +174,26 @@ export async function post(
|
||||
}
|
||||
}
|
||||
|
||||
if (draft.feeds?.length) {
|
||||
try {
|
||||
await writeFeedSubmissionRecords({
|
||||
agent,
|
||||
records: draft.feeds.map(feedUri => ({
|
||||
feedUri,
|
||||
postUri: res.uri,
|
||||
})),
|
||||
})
|
||||
} catch (e: any) {
|
||||
logger.error(`Failed to create submission records`, {
|
||||
context: 'composer',
|
||||
safeMessage: e.message,
|
||||
})
|
||||
throw new Error(
|
||||
t`Failed to write feed submission records. Your post was created, but it was not submitted to any feeds.`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
|
||||
import {networkRetry} from '#/lib/async/retry'
|
||||
|
||||
const $TYPE = 'club.feeed.submission'
|
||||
|
||||
/*
|
||||
{
|
||||
$type: 'club.feeed.submission',
|
||||
feed: 'at://...',
|
||||
post: 'at://...',
|
||||
}
|
||||
*/
|
||||
|
||||
export async function writeFeedSubmissionRecords({
|
||||
agent,
|
||||
records,
|
||||
}: {
|
||||
agent: BskyAgent
|
||||
records: {feedUri: string; postUri: string}[]
|
||||
}) {
|
||||
await networkRetry(2, () =>
|
||||
agent.api.com.atproto.repo.applyWrites({
|
||||
repo: agent.session!.did,
|
||||
writes: records.map(({feedUri, postUri}) => ({
|
||||
$type: 'com.atproto.repo.applyWrites#create',
|
||||
collection: $TYPE,
|
||||
value: {
|
||||
$type: $TYPE,
|
||||
feed: feedUri,
|
||||
post: postUri,
|
||||
},
|
||||
})),
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -175,6 +175,7 @@ export const ComposePost = ({
|
||||
initText,
|
||||
initMention,
|
||||
initOutlineTags: [],
|
||||
initFeeds: [],
|
||||
},
|
||||
createComposerState,
|
||||
)
|
||||
@@ -526,9 +527,12 @@ export const ComposePost = ({
|
||||
[dispatch],
|
||||
)
|
||||
|
||||
const onChangeFeeds = useCallback((uris: string[]) => {
|
||||
console.log(uris)
|
||||
}, [])
|
||||
const onChangeFeeds = useCallback(
|
||||
(uris: string[]) => {
|
||||
dispatch({type: 'feeds_update', feeds: uris})
|
||||
},
|
||||
[dispatch],
|
||||
)
|
||||
|
||||
const [showOutlineTags, setShowOutlineTags] = useState(false)
|
||||
const outlineTagsVisible = showOutlineTags || draft.tags.length > 0
|
||||
|
||||
@@ -54,6 +54,7 @@ export type ComposerDraft = {
|
||||
threadgate: ThreadgateAllowUISetting[]
|
||||
embed: EmbedDraft
|
||||
tags: string[]
|
||||
feeds: string[]
|
||||
}
|
||||
|
||||
export type ComposerAction =
|
||||
@@ -78,6 +79,7 @@ export type ComposerAction =
|
||||
| {type: 'embed_update_gif'; alt: string}
|
||||
| {type: 'embed_remove_gif'}
|
||||
| {type: 'tags_update'; tags: string[]}
|
||||
| {type: 'feeds_update'; feeds: string[]}
|
||||
|
||||
export const MAX_IMAGES = 4
|
||||
|
||||
@@ -332,6 +334,12 @@ export function composerReducer(
|
||||
tags: action.tags,
|
||||
}
|
||||
}
|
||||
case 'feeds_update': {
|
||||
return {
|
||||
...state,
|
||||
feeds: action.feeds,
|
||||
}
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
@@ -343,12 +351,14 @@ export function createComposerState({
|
||||
initImageUris,
|
||||
initQuoteUri,
|
||||
initOutlineTags,
|
||||
initFeeds,
|
||||
}: {
|
||||
initText: string | undefined
|
||||
initMention: string | undefined
|
||||
initImageUris: ComposerOpts['imageUris']
|
||||
initQuoteUri: string | undefined
|
||||
initOutlineTags: string[]
|
||||
initFeeds: string[]
|
||||
}): ComposerDraft {
|
||||
let media: ImagesMedia | undefined
|
||||
if (initImageUris?.length) {
|
||||
@@ -390,5 +400,6 @@ export function createComposerState({
|
||||
link: undefined,
|
||||
},
|
||||
tags: initOutlineTags,
|
||||
feeds: initFeeds,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user