fix: refresh sns feed with latest selected contacts

This commit is contained in:
aits2026
2026-03-10 11:48:25 +08:00
parent c02bc753fd
commit cbdd5b3a24

View File

@@ -407,6 +407,15 @@ export default function SnsPage() {
return `${names.slice(0, 2).join('、')}${names.length}` return `${names.slice(0, 2).join('、')}${names.length}`
}, [contacts, selectedContactUsernames]) }, [contacts, selectedContactUsernames])
const selectedContactUsernameSet = useMemo(() => (
new Set(selectedContactUsernames.map((username) => normalizeAccountId(username)))
), [selectedContactUsernames])
const visiblePosts = useMemo(() => {
if (selectedContactUsernameSet.size === 0) return posts
return posts.filter((post) => selectedContactUsernameSet.has(normalizeAccountId(post.username)))
}, [posts, selectedContactUsernameSet])
const myTimelineCount = useMemo(() => { const myTimelineCount = useMemo(() => {
if (resolvedCurrentUserContact?.postCountStatus === 'ready' && typeof resolvedCurrentUserContact.postCount === 'number') { if (resolvedCurrentUserContact?.postCountStatus === 'ready' && typeof resolvedCurrentUserContact.postCount === 'number') {
return normalizePostCount(resolvedCurrentUserContact.postCount) return normalizePostCount(resolvedCurrentUserContact.postCount)
@@ -624,14 +633,19 @@ export default function SnsPage() {
try { try {
const limit = 20 const limit = 20
const selectedUsernames = selectedContactUsernames.length > 0 ? selectedContactUsernames : undefined const currentSearchKeyword = searchKeywordRef.current
const currentJumpTargetDate = jumpTargetDateRef.current
const currentSelectedContactUsernames = selectedContactUsernamesRef.current
const selectedUsernames = currentSelectedContactUsernames.length > 0
? [...currentSelectedContactUsernames]
: undefined
let startTs: number | undefined = undefined let startTs: number | undefined = undefined
let endTs: number | undefined = undefined let endTs: number | undefined = undefined
if (reset) { if (reset) {
// If jumping to date, set endTs to end of that day // If jumping to date, set endTs to end of that day
if (jumpTargetDate) { if (currentJumpTargetDate) {
endTs = Math.floor(jumpTargetDate.getTime() / 1000) + 86399 endTs = Math.floor(currentJumpTargetDate.getTime() / 1000) + 86399
} }
} else if (direction === 'newer') { } else if (direction === 'newer') {
const currentPosts = postsRef.current const currentPosts = postsRef.current
@@ -642,7 +656,7 @@ export default function SnsPage() {
limit, limit,
0, 0,
selectedUsernames, selectedUsernames,
searchKeyword, currentSearchKeyword,
topTs + 1, topTs + 1,
undefined undefined
); );
@@ -683,7 +697,7 @@ export default function SnsPage() {
limit, limit,
0, 0,
selectedUsernames, selectedUsernames,
searchKeyword, currentSearchKeyword,
startTs, // default undefined startTs, // default undefined
endTs endTs
) )
@@ -697,7 +711,7 @@ export default function SnsPage() {
// Check for newer items above topTs // Check for newer items above topTs
const topTs = result.timeline[0]?.createTime || 0; const topTs = result.timeline[0]?.createTime || 0;
if (topTs > 0) { if (topTs > 0) {
const checkResult = await window.electronAPI.sns.getTimeline(1, 0, selectedUsernames, searchKeyword, topTs + 1, undefined); const checkResult = await window.electronAPI.sns.getTimeline(1, 0, selectedUsernames, currentSearchKeyword, topTs + 1, undefined);
setHasNewer(!!(checkResult.success && checkResult.timeline && checkResult.timeline.length > 0)); setHasNewer(!!(checkResult.success && checkResult.timeline && checkResult.timeline.length > 0));
} else { } else {
setHasNewer(false); setHasNewer(false);
@@ -728,7 +742,7 @@ export default function SnsPage() {
void loadPosts({ reset: true }) void loadPosts({ reset: true })
} }
} }
}, [jumpTargetDate, persistSnsPageCache, searchKeyword, selectedContactUsernames]) }, [persistSnsPageCache])
const stopContactsCountHydration = useCallback((resetProgress = false) => { const stopContactsCountHydration = useCallback((resetProgress = false) => {
contactsCountHydrationTokenRef.current += 1 contactsCountHydrationTokenRef.current += 1
@@ -1406,7 +1420,7 @@ export default function SnsPage() {
)} )}
<div className="posts-list"> <div className="posts-list">
{posts.map(post => ( {visiblePosts.map(post => (
<SnsPostItem <SnsPostItem
key={post.id} key={post.id}
post={{ ...post, isProtected: triggerInstalled === true }} post={{ ...post, isProtected: triggerInstalled === true }}
@@ -1424,7 +1438,7 @@ export default function SnsPage() {
))} ))}
</div> </div>
{loading && posts.length === 0 && ( {loading && visiblePosts.length === 0 && (
<div className="initial-loading"> <div className="initial-loading">
<div className="loading-pulse"> <div className="loading-pulse">
<div className="pulse-circle"></div> <div className="pulse-circle"></div>
@@ -1433,18 +1447,18 @@ export default function SnsPage() {
</div> </div>
)} )}
{loading && posts.length > 0 && ( {loading && visiblePosts.length > 0 && (
<div className="status-indicator loading-more"> <div className="status-indicator loading-more">
<RefreshCw size={16} className="spinning" /> <RefreshCw size={16} className="spinning" />
<span>...</span> <span>...</span>
</div> </div>
)} )}
{!hasMore && posts.length > 0 && ( {!hasMore && visiblePosts.length > 0 && (
<div className="status-indicator no-more"></div> <div className="status-indicator no-more"></div>
)} )}
{!loading && posts.length === 0 && ( {!loading && visiblePosts.length === 0 && (
<div className="no-results"> <div className="no-results">
<div className="no-results-icon"><Search size={48} /></div> <div className="no-results-icon"><Search size={48} /></div>
<p></p> <p></p>