Rename everything
This commit is contained in:
@@ -72,10 +72,10 @@ export function WhoCanReply({
|
|||||||
settings.length === 1 && settings[0].type === 'everybody'
|
settings.length === 1 && settings[0].type === 'everybody'
|
||||||
const noOneCanReply = settings.length === 1 && settings[0].type === 'nobody'
|
const noOneCanReply = settings.length === 1 && settings[0].type === 'nobody'
|
||||||
const anyoneCanQuote =
|
const anyoneCanQuote =
|
||||||
!postgate.quotepostRules || postgate.quotepostRules.length === 0
|
!postgate.embeddingRules || postgate.embeddingRules.length === 0
|
||||||
const noOneCanQuote =
|
const noOneCanQuote =
|
||||||
postgate.quotepostRules?.length === 1 &&
|
postgate.embeddingRules?.length === 1 &&
|
||||||
postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type
|
postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type
|
||||||
const anyoneCanInteract = anyoneCanReply && anyoneCanQuote
|
const anyoneCanInteract = anyoneCanReply && anyoneCanQuote
|
||||||
const noOneCanInteract = noOneCanReply && noOneCanQuote
|
const noOneCanInteract = noOneCanReply && noOneCanQuote
|
||||||
const description = anyoneCanInteract
|
const description = anyoneCanInteract
|
||||||
@@ -293,8 +293,8 @@ function Rules({
|
|||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const noOneCanQuote =
|
const noOneCanQuote =
|
||||||
postgate.quotepostRules?.length === 1 &&
|
postgate.embeddingRules?.length === 1 &&
|
||||||
postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type
|
postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ export function PostInteractionSettingsDialogInner({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onChangeEmbeddingRules = React.useCallback(
|
const onChangeEmbeddingRules = React.useCallback(
|
||||||
(rules: AppBskyFeedPostgate.Record['quotepostRules']) => {
|
(rules: AppBskyFeedPostgate.Record['embeddingRules']) => {
|
||||||
onChangePostgate(
|
onChangePostgate(
|
||||||
createPostgateRecord({
|
createPostgateRecord({
|
||||||
...postgate,
|
...postgate,
|
||||||
quotepostRules: rules,
|
embeddingRules: rules,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -127,8 +127,8 @@ export function PostInteractionSettingsDialogInner({
|
|||||||
<Selectable
|
<Selectable
|
||||||
label={_(msg`Everybody`)}
|
label={_(msg`Everybody`)}
|
||||||
isSelected={
|
isSelected={
|
||||||
!postgate.quotepostRules ||
|
!postgate.embeddingRules ||
|
||||||
postgate.quotepostRules?.length === 0
|
postgate.embeddingRules?.length === 0
|
||||||
}
|
}
|
||||||
onPress={() => onChangeEmbeddingRules([])}
|
onPress={() => onChangeEmbeddingRules([])}
|
||||||
style={{flex: 1}}
|
style={{flex: 1}}
|
||||||
@@ -136,8 +136,8 @@ export function PostInteractionSettingsDialogInner({
|
|||||||
<Selectable
|
<Selectable
|
||||||
label={_(msg`Nobody`)}
|
label={_(msg`Nobody`)}
|
||||||
isSelected={Boolean(
|
isSelected={Boolean(
|
||||||
postgate.quotepostRules &&
|
postgate.embeddingRules &&
|
||||||
postgate.quotepostRules.find(
|
postgate.embeddingRules.find(
|
||||||
v => v.$type === embeddingRules.disableRule.$type,
|
v => v.$type === embeddingRules.disableRule.$type,
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -179,20 +179,21 @@ export function useToggleQuoteDetachmentMutation() {
|
|||||||
if (prev) {
|
if (prev) {
|
||||||
if (action === 'detach') {
|
if (action === 'detach') {
|
||||||
return mergePostgateRecords(prev, {
|
return mergePostgateRecords(prev, {
|
||||||
detachedQuotes: [post.uri],
|
detachedEmbeddingUris: [post.uri],
|
||||||
})
|
})
|
||||||
} else if (action === 'reattach') {
|
} else if (action === 'reattach') {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
detachedQuotes:
|
detachedEmbeddingUris:
|
||||||
prev.detachedQuotes?.filter(uri => uri !== post.uri) || [],
|
prev.detachedEmbeddingUris?.filter(uri => uri !== post.uri) ||
|
||||||
|
[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (action === 'detach') {
|
if (action === 'detach') {
|
||||||
return createPostgateRecord({
|
return createPostgateRecord({
|
||||||
post: quoteUri,
|
post: quoteUri,
|
||||||
detachedQuotes: [post.uri],
|
detachedEmbeddingUris: [post.uri],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,19 +246,19 @@ export function useToggleQuotepostEnabledMutation() {
|
|||||||
if (prev) {
|
if (prev) {
|
||||||
if (action === 'disable') {
|
if (action === 'disable') {
|
||||||
return mergePostgateRecords(prev, {
|
return mergePostgateRecords(prev, {
|
||||||
quotepostRules: [{$type: 'app.bsky.feed.postgate#disableRule'}],
|
embeddingRules: [{$type: 'app.bsky.feed.postgate#disableRule'}],
|
||||||
})
|
})
|
||||||
} else if (action === 'enable') {
|
} else if (action === 'enable') {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
quotepostRules: [],
|
embeddingRules: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (action === 'disable') {
|
if (action === 'disable') {
|
||||||
return createPostgateRecord({
|
return createPostgateRecord({
|
||||||
post: postUri,
|
post: postUri,
|
||||||
quotepostRules: [{$type: 'app.bsky.feed.postgate#disableRule'}],
|
embeddingRules: [{$type: 'app.bsky.feed.postgate#disableRule'}],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
AppBskyFeedPostgate,
|
AppBskyFeedPostgate,
|
||||||
AtUri,
|
AtUri,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {ViewRemoved} from '@atproto/api/dist/client/types/app/bsky/embed/record'
|
|
||||||
|
|
||||||
export const POSTGATE_COLLECTION = 'app.bsky.feed.postgate'
|
export const POSTGATE_COLLECTION = 'app.bsky.feed.postgate'
|
||||||
|
|
||||||
@@ -18,8 +17,8 @@ export function createPostgateRecord(
|
|||||||
$type: POSTGATE_COLLECTION,
|
$type: POSTGATE_COLLECTION,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
post: postgate.post,
|
post: postgate.post,
|
||||||
detachedQuotes: postgate.detachedQuotes || [],
|
detachedEmbeddingUris: postgate.detachedEmbeddingUris || [],
|
||||||
quotepostRules: postgate.quotepostRules || [],
|
embeddingRules: postgate.embeddingRules || [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,27 +26,30 @@ export function mergePostgateRecords(
|
|||||||
prev: AppBskyFeedPostgate.Record,
|
prev: AppBskyFeedPostgate.Record,
|
||||||
next: Partial<AppBskyFeedPostgate.Record>,
|
next: Partial<AppBskyFeedPostgate.Record>,
|
||||||
) {
|
) {
|
||||||
const detachedQuotes = Array.from(
|
const detachedEmbeddingUris = Array.from(
|
||||||
new Set([...(prev.detachedQuotes || []), ...(next.detachedQuotes || [])]),
|
new Set([
|
||||||
|
...(prev.detachedEmbeddingUris || []),
|
||||||
|
...(next.detachedEmbeddingUris || []),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
const quotepostRules = [
|
const embeddingRules = [
|
||||||
...(prev.quotepostRules || []),
|
...(prev.embeddingRules || []),
|
||||||
...(next.quotepostRules || []),
|
...(next.embeddingRules || []),
|
||||||
].filter(
|
].filter(
|
||||||
(rule, i, all) => all.findIndex(_rule => _rule.$type === rule.$type) === i,
|
(rule, i, all) => all.findIndex(_rule => _rule.$type === rule.$type) === i,
|
||||||
)
|
)
|
||||||
return createPostgateRecord({
|
return createPostgateRecord({
|
||||||
post: prev.post,
|
post: prev.post,
|
||||||
detachedQuotes,
|
detachedEmbeddingUris,
|
||||||
quotepostRules,
|
embeddingRules,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createEmbedViewRemovedRecord({uri}: {uri: string}) {
|
export function createEmbedViewDetachedRecord({uri}: {uri: string}) {
|
||||||
const record: ViewRemoved = {
|
const record: AppBskyEmbedRecord.ViewDetached = {
|
||||||
$type: 'app.bsky.embed.record#viewRemoved',
|
$type: 'app.bsky.embed.record#viewDetached',
|
||||||
uri,
|
uri,
|
||||||
removed: true,
|
detached: true,
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
$type: 'app.bsky.embed.record#view',
|
$type: 'app.bsky.embed.record#view',
|
||||||
@@ -75,7 +77,7 @@ export function createMaybeDetachedQuoteEmbed({
|
|||||||
}): AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined {
|
}): AppBskyEmbedRecord.View | AppBskyEmbedRecordWithMedia.View | undefined {
|
||||||
if (AppBskyEmbedRecord.isView(post.embed)) {
|
if (AppBskyEmbedRecord.isView(post.embed)) {
|
||||||
if (detached) {
|
if (detached) {
|
||||||
return createEmbedViewRemovedRecord({uri: quoteUri})
|
return createEmbedViewDetachedRecord({uri: quoteUri})
|
||||||
} else {
|
} else {
|
||||||
return createEmbedRecordView({post: quote})
|
return createEmbedRecordView({post: quote})
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ export function createMaybeDetachedQuoteEmbed({
|
|||||||
if (detached) {
|
if (detached) {
|
||||||
return {
|
return {
|
||||||
...post.embed,
|
...post.embed,
|
||||||
record: createEmbedViewRemovedRecord({uri: quoteUri}),
|
record: createEmbedViewDetachedRecord({uri: quoteUri}),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return createEmbedRecordWithMediaView({post, quote})
|
return createEmbedRecordWithMediaView({post, quote})
|
||||||
@@ -144,7 +146,7 @@ export function getMaybeDetachedQuoteEmbed({
|
|||||||
}) {
|
}) {
|
||||||
if (AppBskyEmbedRecord.isView(post.embed)) {
|
if (AppBskyEmbedRecord.isView(post.embed)) {
|
||||||
// detached
|
// detached
|
||||||
if (AppBskyEmbedRecord.isViewRemoved(post.embed.record)) {
|
if (AppBskyEmbedRecord.isViewDetached(post.embed.record)) {
|
||||||
const urip = new AtUri(post.embed.record.uri)
|
const urip = new AtUri(post.embed.record.uri)
|
||||||
return {
|
return {
|
||||||
embed: post.embed,
|
embed: post.embed,
|
||||||
@@ -166,7 +168,7 @@ export function getMaybeDetachedQuoteEmbed({
|
|||||||
}
|
}
|
||||||
} else if (AppBskyEmbedRecordWithMedia.isView(post.embed)) {
|
} else if (AppBskyEmbedRecordWithMedia.isView(post.embed)) {
|
||||||
// detached
|
// detached
|
||||||
if (AppBskyEmbedRecord.isViewRemoved(post.embed.record.record)) {
|
if (AppBskyEmbedRecord.isViewDetached(post.embed.record.record)) {
|
||||||
const urip = new AtUri(post.embed.record.record.uri)
|
const urip = new AtUri(post.embed.record.record.uri)
|
||||||
return {
|
return {
|
||||||
embed: post.embed,
|
embed: post.embed,
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ export function ThreadgateBtn({
|
|||||||
threadgateAllowUISettings.length === 1 &&
|
threadgateAllowUISettings.length === 1 &&
|
||||||
threadgateAllowUISettings[0].type === 'nobody'
|
threadgateAllowUISettings[0].type === 'nobody'
|
||||||
const anyoneCanQuote =
|
const anyoneCanQuote =
|
||||||
!postgate.quotepostRules || postgate.quotepostRules.length === 0
|
!postgate.embeddingRules || postgate.embeddingRules.length === 0
|
||||||
const noOneCanQuote =
|
const noOneCanQuote =
|
||||||
postgate.quotepostRules?.length === 1 &&
|
postgate.embeddingRules?.length === 1 &&
|
||||||
postgate.quotepostRules[0]?.$type === embeddingRules.disableRule.$type
|
postgate.embeddingRules[0]?.$type === embeddingRules.disableRule.$type
|
||||||
const anyoneCanInteract = anyoneCanReply && anyoneCanQuote
|
const anyoneCanInteract = anyoneCanReply && anyoneCanQuote
|
||||||
const noOneCanInteract = noOneCanReply && noOneCanQuote
|
const noOneCanInteract = noOneCanReply && noOneCanQuote
|
||||||
const label = anyoneCanInteract
|
const label = anyoneCanInteract
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export function MaybeQuoteEmbed({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else if (AppBskyEmbedRecord.isViewRemoved(embed.record)) {
|
} else if (AppBskyEmbedRecord.isViewDetached(embed.record)) {
|
||||||
const isViewerOwner = currentAccount?.did
|
const isViewerOwner = currentAccount?.did
|
||||||
? embed.record.uri.includes(currentAccount.did)
|
? embed.record.uri.includes(currentAccount.did)
|
||||||
: false
|
: false
|
||||||
|
|||||||
Reference in New Issue
Block a user