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 {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {compressImage} from '#/state/gallery'
|
import {compressImage} from '#/state/gallery'
|
||||||
|
import {writeFeedSubmissionRecords} from '#/state/queries/feedgens'
|
||||||
import {writePostgateRecord} from '#/state/queries/postgate'
|
import {writePostgateRecord} from '#/state/queries/postgate'
|
||||||
import {
|
import {
|
||||||
fetchResolveGifQuery,
|
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
|
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,
|
initText,
|
||||||
initMention,
|
initMention,
|
||||||
initOutlineTags: [],
|
initOutlineTags: [],
|
||||||
|
initFeeds: [],
|
||||||
},
|
},
|
||||||
createComposerState,
|
createComposerState,
|
||||||
)
|
)
|
||||||
@@ -526,9 +527,12 @@ export const ComposePost = ({
|
|||||||
[dispatch],
|
[dispatch],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onChangeFeeds = useCallback((uris: string[]) => {
|
const onChangeFeeds = useCallback(
|
||||||
console.log(uris)
|
(uris: string[]) => {
|
||||||
}, [])
|
dispatch({type: 'feeds_update', feeds: uris})
|
||||||
|
},
|
||||||
|
[dispatch],
|
||||||
|
)
|
||||||
|
|
||||||
const [showOutlineTags, setShowOutlineTags] = useState(false)
|
const [showOutlineTags, setShowOutlineTags] = useState(false)
|
||||||
const outlineTagsVisible = showOutlineTags || draft.tags.length > 0
|
const outlineTagsVisible = showOutlineTags || draft.tags.length > 0
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export type ComposerDraft = {
|
|||||||
threadgate: ThreadgateAllowUISetting[]
|
threadgate: ThreadgateAllowUISetting[]
|
||||||
embed: EmbedDraft
|
embed: EmbedDraft
|
||||||
tags: string[]
|
tags: string[]
|
||||||
|
feeds: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ComposerAction =
|
export type ComposerAction =
|
||||||
@@ -78,6 +79,7 @@ export type ComposerAction =
|
|||||||
| {type: 'embed_update_gif'; alt: string}
|
| {type: 'embed_update_gif'; alt: string}
|
||||||
| {type: 'embed_remove_gif'}
|
| {type: 'embed_remove_gif'}
|
||||||
| {type: 'tags_update'; tags: string[]}
|
| {type: 'tags_update'; tags: string[]}
|
||||||
|
| {type: 'feeds_update'; feeds: string[]}
|
||||||
|
|
||||||
export const MAX_IMAGES = 4
|
export const MAX_IMAGES = 4
|
||||||
|
|
||||||
@@ -332,6 +334,12 @@ export function composerReducer(
|
|||||||
tags: action.tags,
|
tags: action.tags,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'feeds_update': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
feeds: action.feeds,
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
@@ -343,12 +351,14 @@ export function createComposerState({
|
|||||||
initImageUris,
|
initImageUris,
|
||||||
initQuoteUri,
|
initQuoteUri,
|
||||||
initOutlineTags,
|
initOutlineTags,
|
||||||
|
initFeeds,
|
||||||
}: {
|
}: {
|
||||||
initText: string | undefined
|
initText: string | undefined
|
||||||
initMention: string | undefined
|
initMention: string | undefined
|
||||||
initImageUris: ComposerOpts['imageUris']
|
initImageUris: ComposerOpts['imageUris']
|
||||||
initQuoteUri: string | undefined
|
initQuoteUri: string | undefined
|
||||||
initOutlineTags: string[]
|
initOutlineTags: string[]
|
||||||
|
initFeeds: string[]
|
||||||
}): ComposerDraft {
|
}): ComposerDraft {
|
||||||
let media: ImagesMedia | undefined
|
let media: ImagesMedia | undefined
|
||||||
if (initImageUris?.length) {
|
if (initImageUris?.length) {
|
||||||
@@ -390,5 +400,6 @@ export function createComposerState({
|
|||||||
link: undefined,
|
link: undefined,
|
||||||
},
|
},
|
||||||
tags: initOutlineTags,
|
tags: initOutlineTags,
|
||||||
|
feeds: initFeeds,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user