Rename everything

This commit is contained in:
Eric Bailey
2024-08-12 10:38:39 -05:00
parent 47dfa54ede
commit 372a235dd7
6 changed files with 43 additions and 40 deletions
+5 -5
View File
@@ -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 (
<>
@@ -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({
<Selectable
label={_(msg`Everybody`)}
isSelected={
!postgate.quotepostRules ||
postgate.quotepostRules?.length === 0
!postgate.embeddingRules ||
postgate.embeddingRules?.length === 0
}
onPress={() => onChangeEmbeddingRules([])}
style={{flex: 1}}
@@ -136,8 +136,8 @@ export function PostInteractionSettingsDialogInner({
<Selectable
label={_(msg`Nobody`)}
isSelected={Boolean(
postgate.quotepostRules &&
postgate.quotepostRules.find(
postgate.embeddingRules &&
postgate.embeddingRules.find(
v => v.$type === embeddingRules.disableRule.$type,
),
)}
+8 -7
View File
@@ -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'}],
})
}
}
+20 -18
View File
@@ -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<AppBskyFeedPostgate.Record>,
) {
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,
@@ -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
+1 -1
View File
@@ -86,7 +86,7 @@ export function MaybeQuoteEmbed({
</Text>
</View>
)
} else if (AppBskyEmbedRecord.isViewRemoved(embed.record)) {
} else if (AppBskyEmbedRecord.isViewDetached(embed.record)) {
const isViewerOwner = currentAccount?.did
? embed.record.uri.includes(currentAccount.did)
: false