feat: add user-level WeChat channel accounts

This commit is contained in:
brother7 committed 2026-09-14 00:26:29 +08:00
1 parent 46e7f6f1cd
commit b7d8b1298f
15 files changed
+575 -63

No files matched your search

@@ -22,7 +22,7 @@ function useVisible(active: boolean) {
return active && visible;
}
export function CloudChannelConversations({ slug, activeView = true }: { slug: string; activeView?: boolean }) {
export function CloudChannelConversations({ slug, channelAccountId, activeView = true }: { slug: string; channelAccountId?: string; activeView?: boolean }) {
const [sessions, setSessions] = useState<CloudChannelSession[]>([]);
const [selected, setSelected] = useState('');
const [offset, setOffset] = useState<number | null>(null);
@@ -37,15 +37,18 @@ export function CloudChannelConversations({ slug, activeView = true }: { slug: s
setLoading(true);
void cloudAgentsApi.call('channelConversations', { slug }).then(page => {
if (!live) return;
setSessions(page.items); setOffset(page.next_offset); setError('');
setSelected(current => current || page.items[0]?.session_id || '');
const items = channelAccountId ? page.items.filter(item => item.channel_account_id === channelAccountId) : page.items;
setSessions(items); setOffset(page.next_offset); setError('');
setSelected(current => items.some(item => item.session_id === current) ? current : items[0]?.session_id || '');
}).catch(error => { if (live) setError(failureText(error)); }).finally(() => { if (live) setLoading(false); });
return () => { live = false; };
}, [slug, visible, revision]);
}, [channelAccountId, slug, visible, revision]);
const more = async () => {
if (loading || offset === null) return;
setLoading(true);
try { const page = await cloudAgentsApi.call('channelConversations', { slug, offset }); setSessions(items => [...items, ...page.items]); setOffset(page.next_offset); }
try { const page = await cloudAgentsApi.call('channelConversations', { slug, offset });
const next = channelAccountId ? page.items.filter(item => item.channel_account_id === channelAccountId) : page.items;
setSessions(items => [...items, ...next]); setOffset(page.next_offset); }
catch (error) { setError(failureText(error)); } finally { setLoading(false); }
};
return <section aria-label="本人微信会话" className="space-y-4">