Fix allow setting clobbering
This commit is contained in:
@@ -88,21 +88,28 @@ export function threadgateAllowUISettingToAllowRecordValue(
|
|||||||
/**
|
/**
|
||||||
* Merges two {@link AppBskyFeedThreadgate.Record} objects, combining their
|
* Merges two {@link AppBskyFeedThreadgate.Record} objects, combining their
|
||||||
* `allow` and `hiddenReplies` arrays and de-deduplicating them.
|
* `allow` and `hiddenReplies` arrays and de-deduplicating them.
|
||||||
|
*
|
||||||
|
* Note: `allow` can be undefined here, be sure you don't accidentally set it
|
||||||
|
* to an empty array. See other comments in this file.
|
||||||
*/
|
*/
|
||||||
export function mergeThreadgateRecords(
|
export function mergeThreadgateRecords(
|
||||||
prev: AppBskyFeedThreadgate.Record,
|
prev: AppBskyFeedThreadgate.Record,
|
||||||
next: Partial<AppBskyFeedThreadgate.Record>,
|
next: Partial<AppBskyFeedThreadgate.Record>,
|
||||||
): AppBskyFeedThreadgate.Record {
|
): AppBskyFeedThreadgate.Record {
|
||||||
const allow = [...(prev.allow || []), ...(next.allow || [])].filter(
|
// can be undefined if everyone can reply!
|
||||||
(v, i, a) => a.findIndex(t => t.$type === v.$type) === i,
|
const allow: AppBskyFeedThreadgate.Record['allow'] | undefined =
|
||||||
)
|
prev.allow || next.allow
|
||||||
|
? [...(prev.allow || []), ...(next.allow || [])].filter(
|
||||||
|
(v, i, a) => a.findIndex(t => t.$type === v.$type) === i,
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
const hiddenReplies = Array.from(
|
const hiddenReplies = Array.from(
|
||||||
new Set([...(prev.hiddenReplies || []), ...(next.hiddenReplies || [])]),
|
new Set([...(prev.hiddenReplies || []), ...(next.hiddenReplies || [])]),
|
||||||
)
|
)
|
||||||
|
|
||||||
return createThreadgateRecord({
|
return createThreadgateRecord({
|
||||||
post: prev.post,
|
post: prev.post,
|
||||||
allow,
|
allow, // can be undefined!
|
||||||
hiddenReplies,
|
hiddenReplies,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user