Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {useNavigation} from '@react-navigation/native'
import {useQueryClient} from '@tanstack/react-query'

import * as apilib from '#/lib/api/index'
import {EmbeddingDisabledError} from '#/lib/api/resolve'
import {EmbeddingDisabledError, type ResolvedLink} from '#/lib/api/resolve'
import {retry} from '#/lib/async/retry'
import {until} from '#/lib/async/until'
import {
Expand All @@ -78,6 +78,7 @@ import {cleanError} from '#/lib/strings/errors'
import {colors} from '#/lib/styles'
import {logger} from '#/logger'
import {isAndroid, isIOS, isNative, isWeb} from '#/platform/detection'
import {updatePostShadow} from '#/state/cache/post-shadow'
import {useDialogStateControlContext} from '#/state/dialogs'
import {emitPostCreated} from '#/state/events'
import {
Expand All @@ -94,6 +95,7 @@ import {
} from '#/state/preferences/languages'
import {usePreferencesQuery} from '#/state/queries/preferences'
import {useProfileQuery} from '#/state/queries/profile'
import {RQKEY_LINK as RQKEY_EXTERNAL_LINK} from '#/state/queries/resolve-link'
import {type Gif} from '#/state/queries/tenor'
import {useAgent, useSession} from '#/state/session'
import {useComposerControls} from '#/state/shell/composer'
Expand Down Expand Up @@ -385,6 +387,63 @@ export const ComposePost = ({
if (isPublishing) {
return
}
const firstPost = thread.posts[0]
logger.info(`composer: publish pressed`, firstPost)

let quoteForRepost: {uri: string; cid: string} | undefined
if (
!replyTo &&
thread.posts.length === 1 &&
!firstPost.embed.media &&
!firstPost.embed.link &&
firstPost.embed.quote
) {
const quoteUri = firstPost.embed.quote.uri
const text = firstPost.richtext.text.trim()

if (text.length === 0 || text === quoteUri) {
// it's an empty quote so we need to get the cid
if (initQuote?.uri === quoteUri) {
// case 1, user started with "quote post" button. we have the cid in initQuote
quoteForRepost = {
uri: initQuote.uri,
cid: initQuote.cid,
}
} else {
// case 2, user pasted a link of a post. we need to get post details from cache
const metadata = queryClient.getQueryData<ResolvedLink>(
RQKEY_EXTERNAL_LINK(quoteUri),
)
if (metadata?.type === 'record' && metadata.kind === 'post') {
quoteForRepost = {
uri: metadata.view.uri,
cid: metadata.view.cid,
}
}
}
}
}

if (quoteForRepost) {
setError('')
setIsPublishing(true)
try {
const {uri: repostUri} = await agent.repost(
quoteForRepost.uri,
quoteForRepost.cid,
)
logEvent('post:repost', {logContext: 'Post'})
updatePostShadow(queryClient, quoteForRepost.uri, {
repostUri,
})
onClose()
onPost?.(undefined)
} catch (e: any) {
setError(cleanError(e.message))
setIsPublishing(false)
}
return
}

if (!canPost) {
return
Expand Down
Loading