feat(sns): limit right contacts to covered users

This commit is contained in:
tisonhuang
2026-03-02 14:38:16 +08:00
parent 36ec12fd0f
commit c6c7f128a9
2 changed files with 41 additions and 13 deletions

View File

@@ -69,6 +69,16 @@ export const SnsFilterPanel: React.FC<SnsFilterPanelProps> = ({
return { text: `${Math.max(0, Number(contact.postCount || 0))}`, className: '' } return { text: `${Math.max(0, Number(contact.postCount || 0))}`, className: '' }
} }
const getEmptyStateText = () => {
if (loading && contacts.length === 0) {
return '正在加载联系人...'
}
if (contacts.length === 0) {
return '有朋友圈数据的好友或者曾经的好友数量为 0'
}
return '没有找到联系人'
}
return ( return (
<aside className="sns-filter-panel"> <aside className="sns-filter-panel">
<div className="filter-header"> <div className="filter-header">
@@ -172,7 +182,7 @@ export const SnsFilterPanel: React.FC<SnsFilterPanelProps> = ({
) )
})} })}
{filteredContacts.length === 0 && ( {filteredContacts.length === 0 && (
<div className="empty-state"></div> <div className="empty-state">{getEmptyStateText()}</div>
)} )}
</div> </div>
</div> </div>

View File

@@ -351,25 +351,24 @@ export default function SnsPage() {
} }
}, [jumpTargetDate, persistSnsPageCache, searchKeyword, selectedUsernames]) }, [jumpTargetDate, persistSnsPageCache, searchKeyword, selectedUsernames])
// Load Contacts合并好友+曾经好友+朋友圈发布者enrichSessionsContactInfo 补充头像) // Load Contacts仅加载朋友圈覆盖好友/曾经好友enrichSessionsContactInfo 补充头像)
const loadContacts = useCallback(async () => { const loadContacts = useCallback(async () => {
const requestToken = ++contactsLoadTokenRef.current const requestToken = ++contactsLoadTokenRef.current
setContactsLoading(true) setContactsLoading(true)
try { try {
// 先加载联系人基础信息,再异步补齐朋友圈条数 // 先加载联系人基础信息和朋友圈覆盖用户名,再异步补齐条数
const [contactsResult, snsResult] = await Promise.all([ const [contactsResult, snsResult] = await Promise.all([
window.electronAPI.chat.getContacts(), window.electronAPI.chat.getContacts(),
window.electronAPI.sns.getSnsUsernames() window.electronAPI.sns.getSnsUsernames()
]) ])
// 以联系人为基础,按 username 去重 // 好友/曾经好友基础信息(用于补充 displayName/avatar/type
const contactMap = new Map<string, Contact>() const knownContacts = new Map<string, Contact>()
// 好友和曾经的好友
if (contactsResult.success && contactsResult.contacts) { if (contactsResult.success && contactsResult.contacts) {
for (const c of contactsResult.contacts) { for (const c of contactsResult.contacts) {
if (c.type === 'friend' || c.type === 'former_friend') { if (c.type === 'friend' || c.type === 'former_friend') {
contactMap.set(c.username, { knownContacts.set(c.username, {
username: c.username, username: c.username,
displayName: c.displayName, displayName: c.displayName,
avatarUrl: c.avatarUrl, avatarUrl: c.avatarUrl,
@@ -380,12 +379,31 @@ export default function SnsPage() {
} }
} }
// 朋友圈发布者(补充不在联系人列表中的用户) if (!snsResult.success) {
if (snsResult.success && snsResult.usernames) { console.error('Failed to load SNS usernames:', snsResult.error)
for (const u of snsResult.usernames) { }
if (!contactMap.has(u)) {
contactMap.set(u, { username: u, displayName: u, type: 'sns_only', postCountStatus: 'loading' }) // 右侧联系人只基于“朋友圈覆盖用户名”集合构建
} const snsUsernames = Array.from(
new Set(
(snsResult.usernames || [])
.map(username => (typeof username === 'string' ? username.trim() : ''))
.filter(Boolean)
)
)
const contactMap = new Map<string, Contact>()
for (const username of snsUsernames) {
const known = knownContacts.get(username)
if (known) {
contactMap.set(username, { ...known })
} else {
contactMap.set(username, {
username,
displayName: username,
type: 'sns_only',
postCountStatus: 'loading'
})
} }
} }