74b0318d89
* Don't reconstruct threads from separate posts * Remove post-level dedupe for now * Change repost dedupe condition to look just at length * Delete unused isThread * Delete another isThread field It is now meaningless because there's nothing special about author threads. * Narrow down slice item shape so it does not need reply * Consolidate slice validation criteria in one place * Show replies in context * Make fallback marker work * Remove misleading and now-unused property It was called rootUri but it was actually the leaf URI. Regardless, it's not used anymore. * Add by-thread dedupe to non-author feeds * Add post-level dedupe * Always count from the start This is easier to think about. * Only tuner state need to be untouched on dry run * Account for threads in reply filtering * Remove repost deduping This is already being taken care of by item-level deduping. It's also now wrong and removing too much (since it wasn't filtering for reposts directly). * Calculate rootUri correctly * Apply Following settings to all lists * Don't dedupe intentional reposts by thread * Show reply parent when ambiguous * Explicitly remove orphaned replies from following/lists * Fix thread dedupe to work across pages * Mark grandparent-blocked as orphaned * Guard tuner state change by dryRun * Remove dead code * Don't dedupe feedgen threads * Revert "Apply Following settings to all lists" This reverts commit aff86be6d37b60cc5d0ac38f22c31a4808342cf4. Let's not do this yet and have a bit more discussion. This is a chunky change already. * Reason belongs to a slice, not item * Logically feedContext belongs to the slice * Update comment to reflect latest behavior
159 lines
4.9 KiB
TypeScript
159 lines
4.9 KiB
TypeScript
import React, {memo} from 'react'
|
|
import {StyleSheet, View} from 'react-native'
|
|
import Svg, {Circle, Line} from 'react-native-svg'
|
|
import {AtUri} from '@atproto/api'
|
|
import {Trans} from '@lingui/macro'
|
|
|
|
import {FeedPostSlice} from '#/state/queries/post-feed'
|
|
import {usePalette} from 'lib/hooks/usePalette'
|
|
import {makeProfileLink} from 'lib/routes/links'
|
|
import {Link} from '../util/Link'
|
|
import {Text} from '../util/text/Text'
|
|
import {FeedItem} from './FeedItem'
|
|
|
|
let FeedSlice = ({
|
|
slice,
|
|
hideTopBorder,
|
|
}: {
|
|
slice: FeedPostSlice
|
|
hideTopBorder?: boolean
|
|
}): React.ReactNode => {
|
|
if (slice.isIncompleteThread && slice.items.length >= 3) {
|
|
const beforeLast = slice.items.length - 2
|
|
const last = slice.items.length - 1
|
|
return (
|
|
<>
|
|
<FeedItem
|
|
key={slice.items[0]._reactKey}
|
|
post={slice.items[0].post}
|
|
record={slice.items[0].record}
|
|
reason={slice.reason}
|
|
feedContext={slice.feedContext}
|
|
parentAuthor={slice.items[0].parentAuthor}
|
|
showReplyTo={false}
|
|
moderation={slice.items[0].moderation}
|
|
isThreadParent={isThreadParentAt(slice.items, 0)}
|
|
isThreadChild={isThreadChildAt(slice.items, 0)}
|
|
hideTopBorder={hideTopBorder}
|
|
isParentBlocked={slice.items[0].isParentBlocked}
|
|
/>
|
|
<ViewFullThread uri={slice.items[0].uri} />
|
|
<FeedItem
|
|
key={slice.items[beforeLast]._reactKey}
|
|
post={slice.items[beforeLast].post}
|
|
record={slice.items[beforeLast].record}
|
|
reason={undefined}
|
|
feedContext={slice.feedContext}
|
|
parentAuthor={slice.items[beforeLast].parentAuthor}
|
|
showReplyTo={
|
|
slice.items[beforeLast].parentAuthor?.did !==
|
|
slice.items[beforeLast].post.author.did
|
|
}
|
|
moderation={slice.items[beforeLast].moderation}
|
|
isThreadParent={isThreadParentAt(slice.items, beforeLast)}
|
|
isThreadChild={isThreadChildAt(slice.items, beforeLast)}
|
|
isParentBlocked={slice.items[beforeLast].isParentBlocked}
|
|
/>
|
|
<FeedItem
|
|
key={slice.items[last]._reactKey}
|
|
post={slice.items[last].post}
|
|
record={slice.items[last].record}
|
|
reason={undefined}
|
|
feedContext={slice.feedContext}
|
|
parentAuthor={slice.items[last].parentAuthor}
|
|
showReplyTo={false}
|
|
moderation={slice.items[last].moderation}
|
|
isThreadParent={isThreadParentAt(slice.items, last)}
|
|
isThreadChild={isThreadChildAt(slice.items, last)}
|
|
isParentBlocked={slice.items[last].isParentBlocked}
|
|
isThreadLastChild
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{slice.items.map((item, i) => (
|
|
<FeedItem
|
|
key={item._reactKey}
|
|
post={slice.items[i].post}
|
|
record={slice.items[i].record}
|
|
reason={i === 0 ? slice.reason : undefined}
|
|
feedContext={slice.feedContext}
|
|
moderation={slice.items[i].moderation}
|
|
parentAuthor={slice.items[i].parentAuthor}
|
|
showReplyTo={i === 0}
|
|
isThreadParent={isThreadParentAt(slice.items, i)}
|
|
isThreadChild={isThreadChildAt(slice.items, i)}
|
|
isThreadLastChild={
|
|
isThreadChildAt(slice.items, i) && slice.items.length === i + 1
|
|
}
|
|
isParentBlocked={slice.items[i].isParentBlocked}
|
|
hideTopBorder={hideTopBorder && i === 0}
|
|
/>
|
|
))}
|
|
</>
|
|
)
|
|
}
|
|
FeedSlice = memo(FeedSlice)
|
|
export {FeedSlice}
|
|
|
|
function ViewFullThread({uri}: {uri: string}) {
|
|
const pal = usePalette('default')
|
|
const itemHref = React.useMemo(() => {
|
|
const urip = new AtUri(uri)
|
|
return makeProfileLink({did: urip.hostname, handle: ''}, 'post', urip.rkey)
|
|
}, [uri])
|
|
|
|
return (
|
|
<Link style={[styles.viewFullThread]} href={itemHref} asAnchor noFeedback>
|
|
<View style={styles.viewFullThreadDots}>
|
|
<Svg width="4" height="40">
|
|
<Line
|
|
x1="2"
|
|
y1="0"
|
|
x2="2"
|
|
y2="15"
|
|
stroke={pal.colors.replyLine}
|
|
strokeWidth="2"
|
|
/>
|
|
<Circle cx="2" cy="22" r="1.5" fill={pal.colors.replyLineDot} />
|
|
<Circle cx="2" cy="28" r="1.5" fill={pal.colors.replyLineDot} />
|
|
<Circle cx="2" cy="34" r="1.5" fill={pal.colors.replyLineDot} />
|
|
</Svg>
|
|
</View>
|
|
|
|
<Text type="md" style={[pal.link, {paddingTop: 18, paddingBottom: 4}]}>
|
|
<Trans>View full thread</Trans>
|
|
</Text>
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
viewFullThread: {
|
|
flexDirection: 'row',
|
|
gap: 10,
|
|
paddingLeft: 18,
|
|
},
|
|
viewFullThreadDots: {
|
|
width: 52,
|
|
alignItems: 'center',
|
|
},
|
|
})
|
|
|
|
function isThreadParentAt<T>(arr: Array<T>, i: number) {
|
|
if (arr.length === 1) {
|
|
return false
|
|
}
|
|
return i < arr.length - 1
|
|
}
|
|
|
|
function isThreadChildAt<T>(arr: Array<T>, i: number) {
|
|
if (arr.length === 1) {
|
|
return false
|
|
}
|
|
return i > 0
|
|
}
|