From 372a235dd72d76f3657fbb8c0ce72874ef2ac304 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 12 Aug 2024 10:38:39 -0500 Subject: [PATCH] Rename everything --- src/components/WhoCanReply.tsx | 10 ++--- .../dialogs/PostInteractionSettingsDialog.tsx | 12 +++--- src/state/queries/postgate/index.ts | 15 ++++---- src/state/queries/postgate/util.ts | 38 ++++++++++--------- .../com/composer/threadgate/ThreadgateBtn.tsx | 6 +-- src/view/com/util/post-embeds/QuoteEmbed.tsx | 2 +- 6 files changed, 43 insertions(+), 40 deletions(-) diff --git a/src/components/WhoCanReply.tsx b/src/components/WhoCanReply.tsx index a570c1ca78..013de473a3 100644 --- a/src/components/WhoCanReply.tsx +++ b/src/components/WhoCanReply.tsx @@ -72,10 +72,10 @@ export function WhoCanReply({ settings.length === 1 && settings[0].type === 'everybody' const noOneCanReply = settings.length === 1 && settings[0].type === 'nobody' const anyoneCanQuote = - !postgate.quotepostRules || postgate.quotepostRules.length === 0 + !postgate.embeddingRules || postgate.embeddingRules.length === 0 const noOneCanQuote = - postgate.quotepostRules?.length === 1 && - postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type + postgate.embeddingRules?.length === 1 && + postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type const anyoneCanInteract = anyoneCanReply && anyoneCanQuote const noOneCanInteract = noOneCanReply && noOneCanQuote const description = anyoneCanInteract @@ -293,8 +293,8 @@ function Rules({ }) { const t = useTheme() const noOneCanQuote = - postgate.quotepostRules?.length === 1 && - postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type + postgate.embeddingRules?.length === 1 && + postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type return ( <> diff --git a/src/components/dialogs/PostInteractionSettingsDialog.tsx b/src/components/dialogs/PostInteractionSettingsDialog.tsx index 71d57f8273..9b16ec86b1 100644 --- a/src/components/dialogs/PostInteractionSettingsDialog.tsx +++ b/src/components/dialogs/PostInteractionSettingsDialog.tsx @@ -85,11 +85,11 @@ export function PostInteractionSettingsDialogInner({ } const onChangeEmbeddingRules = React.useCallback( - (rules: AppBskyFeedPostgate.Record['quotepostRules']) => { + (rules: AppBskyFeedPostgate.Record['embeddingRules']) => { onChangePostgate( createPostgateRecord({ ...postgate, - quotepostRules: rules, + embeddingRules: rules, }), ) }, @@ -127,8 +127,8 @@ export function PostInteractionSettingsDialogInner({ onChangeEmbeddingRules([])} style={{flex: 1}} @@ -136,8 +136,8 @@ export function PostInteractionSettingsDialogInner({ v.$type === embeddingRules.disableRule.$type, ), )} diff --git a/src/state/queries/postgate/index.ts b/src/state/queries/postgate/index.ts index afa8e03b0a..5cfff7f0ed 100644 --- a/src/state/queries/postgate/index.ts +++ b/src/state/queries/postgate/index.ts @@ -179,20 +179,21 @@ export function useToggleQuoteDetachmentMutation() { if (prev) { if (action === 'detach') { return mergePostgateRecords(prev, { - detachedQuotes: [post.uri], + detachedEmbeddingUris: [post.uri], }) } else if (action === 'reattach') { return { ...prev, - detachedQuotes: - prev.detachedQuotes?.filter(uri => uri !== post.uri) || [], + detachedEmbeddingUris: + prev.detachedEmbeddingUris?.filter(uri => uri !== post.uri) || + [], } } } else { if (action === 'detach') { return createPostgateRecord({ post: quoteUri, - detachedQuotes: [post.uri], + detachedEmbeddingUris: [post.uri], }) } } @@ -245,19 +246,19 @@ export function useToggleQuotepostEnabledMutation() { if (prev) { if (action === 'disable') { return mergePostgateRecords(prev, { - quotepostRules: [{$type: 'app.bsky.feed.postgate#disableRule'}], + embeddingRules: [{$type: 'app.bsky.feed.postgate#disableRule'}], }) } else if (action === 'enable') { return { ...prev, - quotepostRules: [], + embeddingRules: [], } } } else { if (action === 'disable') { return createPostgateRecord({ post: postUri, - quotepostRules: [{$type: 'app.bsky.feed.postgate#disableRule'}], + embeddingRules: [{$type: 'app.bsky.feed.postgate#disableRule'}], }) } } diff --git a/src/state/queries/postgate/util.ts b/src/state/queries/postgate/util.ts index ba821cf618..21509c3ac4 100644 --- a/src/state/queries/postgate/util.ts +++ b/src/state/queries/postgate/util.ts @@ -5,7 +5,6 @@ import { AppBskyFeedPostgate, AtUri, } from '@atproto/api' -import {ViewRemoved} from '@atproto/api/dist/client/types/app/bsky/embed/record' export const POSTGATE_COLLECTION = 'app.bsky.feed.postgate' @@ -18,8 +17,8 @@ export function createPostgateRecord( $type: POSTGATE_COLLECTION, createdAt: new Date().toISOString(), post: postgate.post, - detachedQuotes: postgate.detachedQuotes || [], - quotepostRules: postgate.quotepostRules || [], + detachedEmbeddingUris: postgate.detachedEmbeddingUris || [], + embeddingRules: postgate.embeddingRules || [], } } @@ -27,27 +26,30 @@ export function mergePostgateRecords( prev: AppBskyFeedPostgate.Record, next: Partial, ) { - const detachedQuotes = Array.from( - new Set([...(prev.detachedQuotes || []), ...(next.detachedQuotes || [])]), + const detachedEmbeddingUris = Array.from( + new Set([ + ...(prev.detachedEmbeddingUris || []), + ...(next.detachedEmbeddingUris || []), + ]), ) - const quotepostRules = [ - ...(prev.quotepostRules || []), - ...(next.quotepostRules || []), + const embeddingRules = [ + ...(prev.embeddingRules || []), + ...(next.embeddingRules || []), ].filter( (rule, i, all) => all.findIndex(_rule => _rule.$type === rule.$type) === i, ) return createPostgateRecord({ post: prev.post, - detachedQuotes, - quotepostRules, + detachedEmbeddingUris, + embeddingRules, }) } -export function createEmbedViewRemovedRecord({uri}: {uri: string}) { - const record: ViewRemoved = { - $type: 'app.bsky.embed.record#viewRemoved', +export function createEmbedViewDetachedRecord({uri}: {uri: string}) { + const record: AppBskyEmbedRecord.ViewDetached = { + $type: 'app.bsky.embed.record#viewDetached', uri, - removed: true, + detached: true, } return { $type: 'app.bsky.embed.record#view', @@ -75,7 +77,7 @@ export function createMaybeDetachedQuoteEmbed({ }): AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined { if (AppBskyEmbedRecord.isView(post.embed)) { if (detached) { - return createEmbedViewRemovedRecord({uri: quoteUri}) + return createEmbedViewDetachedRecord({uri: quoteUri}) } else { return createEmbedRecordView({post: quote}) } @@ -83,7 +85,7 @@ export function createMaybeDetachedQuoteEmbed({ if (detached) { return { ...post.embed, - record: createEmbedViewRemovedRecord({uri: quoteUri}), + record: createEmbedViewDetachedRecord({uri: quoteUri}), } } else { return createEmbedRecordWithMediaView({post, quote}) @@ -144,7 +146,7 @@ export function getMaybeDetachedQuoteEmbed({ }) { if (AppBskyEmbedRecord.isView(post.embed)) { // detached - if (AppBskyEmbedRecord.isViewRemoved(post.embed.record)) { + if (AppBskyEmbedRecord.isViewDetached(post.embed.record)) { const urip = new AtUri(post.embed.record.uri) return { embed: post.embed, @@ -166,7 +168,7 @@ export function getMaybeDetachedQuoteEmbed({ } } else if (AppBskyEmbedRecordWithMedia.isView(post.embed)) { // detached - if (AppBskyEmbedRecord.isViewRemoved(post.embed.record.record)) { + if (AppBskyEmbedRecord.isViewDetached(post.embed.record.record)) { const urip = new AtUri(post.embed.record.record.uri) return { embed: post.embed, diff --git a/src/view/com/composer/threadgate/ThreadgateBtn.tsx b/src/view/com/composer/threadgate/ThreadgateBtn.tsx index 8a0aee687c..54fcc2fa46 100644 --- a/src/view/com/composer/threadgate/ThreadgateBtn.tsx +++ b/src/view/com/composer/threadgate/ThreadgateBtn.tsx @@ -53,10 +53,10 @@ export function ThreadgateBtn({ threadgateAllowUISettings.length === 1 && threadgateAllowUISettings[0].type === 'nobody' const anyoneCanQuote = - !postgate.quotepostRules || postgate.quotepostRules.length === 0 + !postgate.embeddingRules || postgate.embeddingRules.length === 0 const noOneCanQuote = - postgate.quotepostRules?.length === 1 && - postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type + postgate.embeddingRules?.length === 1 && + postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type const anyoneCanInteract = anyoneCanReply && anyoneCanQuote const noOneCanInteract = noOneCanReply && noOneCanQuote const label = anyoneCanInteract diff --git a/src/view/com/util/post-embeds/QuoteEmbed.tsx b/src/view/com/util/post-embeds/QuoteEmbed.tsx index e461d0b989..192aea708b 100644 --- a/src/view/com/util/post-embeds/QuoteEmbed.tsx +++ b/src/view/com/util/post-embeds/QuoteEmbed.tsx @@ -86,7 +86,7 @@ export function MaybeQuoteEmbed({ ) - } else if (AppBskyEmbedRecord.isViewRemoved(embed.record)) { + } else if (AppBskyEmbedRecord.isViewDetached(embed.record)) { const isViewerOwner = currentAccount?.did ? embed.record.uri.includes(currentAccount.did) : false