Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(bots): let the reader follow a group Thread

zqchris32929bad517b
diff --git a/apps/desktop/scripts/fixtures/group-control/group-control-fixture.tsx b/apps/desktop/scripts/fixtures/group-control/group-control-fixture.tsx
index fed23d3967..e24d290492 100644
--- a/apps/desktop/scripts/fixtures/group-control/group-control-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/group-control/group-control-fixture.tsx
@@ -13,6 +13,8 @@ interface GroupData {
wrappedReactions?: boolean;
/** Server read state: unread thread entries and the in-chat 话题 hint. */
threadUnread?: boolean;
+ /** The Thread panel answers reads and keeps the reader's follow switch. */
+ threadPanel?: boolean;
}
const T0 = 1700000000000;
@@ -104,11 +106,15 @@ function bubbleMessages(wrappedReactions = false) {
];
}
-/** Two Threads name the reader, one is merely unread, one is read (bot-group-chat.md §10「话题未读与提示」). */
+/**
+ * Two Threads name the reader, one they follow is unread without naming them, one is read
+ * (bot-group-chat.md §10「话题未读与提示」).
+ */
const UNREAD = { a1: { count: 2, mentioned: true }, q3: { count: 1, mentioned: true }, q2: { count: 1, mentioned: false } } as Record<string, { count: number; mentioned: boolean }>;
+const FOLLOWED = new Set(['q2']);
function threadSummaries() {
const summary = (rootId: string, rootText: string, rootAuthorName: string, rootAuthorBotId: string | null, replyCount: number, last: [string, string, number]) => ({
- rootId, rootText, rootAuthorName, rootAuthorBotId, replyCount, unread: UNREAD[rootId] ?? { count: 0, mentioned: false },
+ rootId, rootText, rootAuthorName, rootAuthorBotId, replyCount, unread: UNREAD[rootId] ?? { count: 0, mentioned: false }, following: FOLLOWED.has(rootId),
lastReply: { authorName: last[0], text: last[1], createdAt: T0 + last[2] * MINUTE },
});
return [
@@ -166,7 +172,18 @@ function groupFrom(data: GroupData) {
void mountPage({
route: '/bots/groups/fixture-group',
host: (ctx) => {
- const group = groupFrom(ctx.data as unknown as GroupData);
+ const data = ctx.data as unknown as GroupData;
+ const group = groupFrom(data);
+ let following = false;
+ const thread = async (input: { rootId: string; following?: boolean }) => {
+ if (input.following !== undefined) following = input.following;
+ const root = group.messages.find(m => m.id === input.rootId);
+ const replies = ((root?.threadPreview as { replies?: Array<Record<string, unknown>> } | undefined)?.replies ?? []).map((reply, index) => message({
+ id: reply.id, sequence: 100 + index, threadRootId: input.rootId, authorKind: reply.authorKind, authorBotId: reply.authorBotId,
+ authorName: reply.authorName, isSelf: reply.isSelf, content: reply.text, createdAt: reply.createdAt,
+ }));
+ return { ok: true, root, replies, hasMore: false, following };
+ };
return {
maker: {
listBotGroups: async () => ({ ok: true, groups: [] }),
@@ -177,6 +194,7 @@ void mountPage({
chatServer: {
reactors: async () => ({ ok: true, reactors: [{ actorId: 'me', isSelf: true, name: 'You', formerMember: false }] }),
react: forbid('maker.chatServer.react'),
+ ...(data.threadPanel ? { thread } : {}),
},
},
deviceLink: {
diff --git a/apps/desktop/scripts/fixtures/group-control/ui-page.mjs b/apps/desktop/scripts/fixtures/group-control/ui-page.mjs
index 8983856452..63bdc8575b 100644
--- a/apps/desktop/scripts/fixtures/group-control/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/group-control/ui-page.mjs
@@ -37,6 +37,10 @@ export default {
about: 'Server read state: unread thread entries (with @you), the in-chat 话题 hint above the composer and its list of this group\'s Threads',
data: { ...base, bubbles: true, threadUnread: true },
},
+ 'thread-follow': {
+ about: 'The Thread panel\'s 关注 switch, off by default; switched on it reads 已关注',
+ data: { ...base, bubbles: true, threadUnread: true, threadPanel: true },
+ },
'bubbles-wrapped': {
about: 'PR #6549: wrapped reactions keep both toolbars level with their bubbles; server messages with empty mention ids still open unique member cards',
viewport: { width: 800, height: 800 },
@@ -86,9 +90,9 @@ export default {
return { aboveComposer: box.bottom <= composer.top + 1, inside: box.right <= timeline.right + 1 && box.left >= timeline.left };
});
assert.ok(geometry.inside, 'the hint stays inside the chat column');
- // Only Threads that name the reader ask for attention; the merely unread one waits at its entry.
+ // Threads that name the reader or that they follow ask for attention; others wait at their entry.
const label = await hint.textContent();
- assert.ok(label.includes('2'), `the hint counts the two Threads that mention the reader (${label})`);
+ assert.ok(label.includes('3'), `the hint counts the two Threads that mention the reader and the one they follow (${label})`);
await ui.capture('hint');
await hint.locator('button').first().click();
const rows = page.locator('[data-thread-hint-row]');
@@ -98,6 +102,20 @@ export default {
return;
}
+ if (ui.case === 'thread-follow') {
+ await page.locator('[data-thread-preview="q2"]').click();
+ const follow = page.locator('[data-thread-follow]');
+ await follow.waitFor();
+ assert.equal(await follow.getAttribute('aria-pressed'), 'false', 'a Thread is not followed until the reader asks');
+ await ui.capture('off');
+ await follow.click();
+ await page.locator('[data-thread-follow][aria-pressed="true"]').waitFor();
+ // The resting state, not the hover the click leaves behind.
+ await page.mouse.move(0, 0);
+ await ui.capture('on');
+ return;
+ }
+
if (ui.case.startsWith('bubbles')) {
const answer = page.getByText('Android 更新卡那个 PR', { exact: false });
await answer.waitFor();
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index f15b82d5e5..eecb7fa8c1 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -2464,6 +2464,27 @@ describe('Chat Server result delivery and refresh', () => {
expect(writes()).toHaveLength(1);
});
+ // bot-group-chat.md §10「话题未读与提示」: following is the reader's own switch, kept by the server.
+ it('follows a Thread only when the reader switches it on, restating its read position', async () => {
+ let following = false;
+ fixture.handle.mockImplementation((route, method, body) => {
+ if (route.endsWith('/snapshot')) return { body: { room: room(roomId), members, messages: [...shares, ...replies, root].sort((a, b) => Number(b.seq) - Number(a.seq)), cursor: '8', reads: [{ thread_key: rootId, read_seq: '3', following }] } };
+ if (route.includes('threadRootId=')) return { body: [...replies].reverse() };
+ if (route === `/conversations/${roomId}/read` && method === 'POST') { following = (body as { following: boolean }).following; return { body: { readSeq: '3', following } }; }
+ return threadResponse(route, method, body);
+ });
+ const writes = () => fixture.handle.mock.calls.filter(([route, method]) => route === `/conversations/${roomId}/read` && method === 'POST');
+ expect(await service.chatServer!.thread({ groupId: roomId, rootId })).toMatchObject({ ok: true, following: false });
+ expect(writes()).toHaveLength(0);
+ expect(await service.chatServer!.thread({ groupId: roomId, rootId, following: true })).toMatchObject({ ok: true, following: true });
+ expect(writes()).toHaveLength(1);
+ expect(writes()[0]![2]).toMatchObject({ threadRootId: rootId, readSeq: '3', following: true });
+ await vi.advanceTimersByTimeAsync(150);
+ const listed = await service.getGroup(roomId);
+ if (!listed.ok) throw new Error('Expected group');
+ expect(listed.group.threads?.find(thread => thread.rootId === rootId)?.following).toBe(true);
+ });
+
it('projects distinct responders independently of repeated-author summaries', async () => {
const rows = [botId, botId, botId, aliceId, selfId].map((author, i) =>
msg(`70000000-0000-4000-8000-00000000000${i + 1}`, 6 - i, author, { threadRootId: rootId }));
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 72c8a16c30..f969d33c7a 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -66,7 +66,7 @@ interface Room {
created_at: string; updated_at: string; revision: number; archived: boolean; dissolved_at?: string | null; organizer_id?: string | null; kind?: string;
}
/** `reads`: this reader's read position per Thread (`thread_key` = root ID, `main` for the main timeline); older servers omit it. */
-interface Snapshot { room: Room; members: Member[]; messages: Message[]; cursor: string; reads?: Array<{ thread_key: string; read_seq: string }> }
+interface Snapshot { room: Room; members: Member[]; messages: Message[]; cursor: string; reads?: Array<{ thread_key: string; read_seq: string; following?: boolean }> }
interface Execution {
id: string; conversation_id: string; source_message_id: string; bot_id: string;
requester_id?: string;
@@ -1037,6 +1037,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
for (const m of known) if (!m.threadRootId && (m.replyCount ?? 0) > 0) rootIds.add(m.id);
// A root outside the window is read in the background; its summary fills in on the next refresh.
const roots = threads.sources(roomId, [...rootIds], known);
+ const followed = new Set(s.reads?.filter(read => read.following).map(read => read.thread_key));
return [...rootIds].map((rootId): BotGroupThreadSummary => {
const root = roots.get(rootId) ?? undefined;
const rootView = root ? messageView(root, s.members) : null;
@@ -1046,7 +1047,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
return { rootId, rootAuthorName: rootView?.authorName ?? '', rootAuthorBotId: rootView?.authorBotId ?? null,
rootText: root && !root.deleted ? threadPreviewText(root) || mediaNames(root) : '',
replyCount: root?.replyCount ?? s.messages.filter(m => m.threadRootId === rootId).length,
- unread: threadUnread(rootId, s.messages, reads),
+ unread: threadUnread(rootId, s.messages, reads), following: followed.has(rootId),
lastReply: last && lastView ? { authorName: lastView.authorName, text: threadPreviewText(last) || mediaNames(last), createdAt: lastView.createdAt } : null };
}).sort((a, b) => Number(b.unread.count > 0) - Number(a.unread.count > 0) || (b.lastReply?.createdAt ?? 0) - (a.lastReply?.createdAt ?? 0))
.slice(0, THREAD_LIST_LIMIT);
@@ -1179,6 +1180,22 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
}
return Number(before);
}
+ /**
+ * Whether the reader follows this Thread, after first setting it when `next` is given; undefined
+ * when the server keeps no read state. Following is only ever the reader's choice: it is what
+ * makes later replies notify them (bot-group-chat.md §10「话题未读与提示」).
+ */
+ async function threadFollowing(roomId: string, rootId: string, next?: boolean): Promise<boolean | undefined> {
+ const s = await recentSnapshot(roomId);
+ if (!s.reads) return undefined;
+ const read = s.reads.find(entry => entry.thread_key === rootId);
+ if (next === undefined) return read?.following === true;
+ // The read position the server keeps never moves back, so restating it changes nothing else.
+ const written = await api<{ following: boolean }>(`/conversations/${roomId}/read`, 'POST', {
+ operationId: randomUUID(), threadRootId: rootId, readSeq: read?.read_seq ?? '0', following: next });
+ changed(roomId);
+ return written.following;
+ }
async function detail(roomId: string, options?: unknown, summaryOnly = false): Promise<BotGroupDetail> {
id.parse(roomId);
const o = z.object({ beforeSequence: z.number().int().positive().optional(), limit: z.number().int().min(1).max(100).optional(),
@@ -1959,8 +1976,10 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
status: async () => ({ enabled: true, connected: current() && connected }),
thread: input => result(async () => {
const i = z.object({ groupId: id, rootId: id, before: z.number().int().positive().optional(), sourceMessageIds: z.array(id).optional(),
- markRead: z.boolean().optional() }).parse(input);
+ markRead: z.boolean().optional(), following: z.boolean().optional() }).parse(input);
i.groupId = await groupRoom(i.groupId);
+ const followingWrite = i.following === undefined ? undefined : threadFollowing(i.groupId, i.rootId, i.following);
+ followingWrite?.catch(() => undefined);
// One round trip; awaited in the former order so the same failure is reported first.
const membersRead = api<Member[]>(`/conversations/${i.groupId}/members`);
const rootRead = api<Message>(`/conversations/${i.groupId}/messages/${i.rootId}`);
@@ -1973,10 +1992,12 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
// A share in the main chat can itself be a thread root.
const rootViews = await messageViews(i.groupId, [root], members);
await decorateThreads(i.groupId, rootViews, [root], page, members, false);
+ // An older page is history being scrolled: it says nothing about the Thread's switches.
+ const following = await (followingWrite ?? (i.before ? undefined : threadFollowing(i.groupId, root.id)));
const readBefore = i.markRead && !i.before ? await markThreadRead(i.groupId, root, page) : undefined;
return { root: rootViews[0], executionFailures,
replies: await messageViews(i.groupId, page.reverse(), members), hasMore: page.length === 50,
- ...(readBefore !== undefined ? { readBefore } : {}) };
+ ...(readBefore !== undefined ? { readBefore } : {}), ...(following !== undefined ? { following } : {}) };
}),
shareToMain: input => result(async () => {
const i = z.object({ groupId: id, messageId: id }).strict().parse(input);
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupThreadHint.tsx b/apps/desktop/src/renderer/features/bots/BotGroupThreadHint.tsx
index 69be5ddcb5..2c418f8a69 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupThreadHint.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupThreadHint.tsx
@@ -1,8 +1,9 @@
/**
* The in-chat 话题 hint (docs/product-rules/bot-group-chat.md §10「话题未读与提示」): a small
* button above the composer, at the column's right edge, shown while a Thread that concerns the
- * reader has unread replies. With one such Thread it opens it; with more it lists this group's
- * Threads, those with news first. Dismissing it hides it until something new arrives.
+ * reader (one they follow, or one naming them) has unread replies. With one such Thread it opens
+ * it; with more it lists this group's Threads, those with news first. Dismissing it hides it until
+ * something new arrives.
*/
import { useState } from 'react';
import { MessagesSquare, X } from 'lucide-react';
@@ -16,9 +17,9 @@ import { BotAvatar } from './BotAvatar';
const key = (name: string) => `bots.groupChat.server.thread.${name}`;
const FOCUS = 'outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]';
-/** A Thread concerns the reader when someone named them in an unread reply. */
+/** A Thread concerns the reader when they follow it or someone named them in an unread reply. */
export function botGroupHintThreads(threads: readonly BotGroupThreadSummary[], openRootId: string | null) {
- return threads.filter(thread => thread.rootId !== openRootId && thread.unread.count > 0 && thread.unread.mentioned);
+ return threads.filter(thread => thread.rootId !== openRootId && thread.unread.count > 0 && (thread.unread.mentioned || thread.following === true));
}
/** What the reader had already been told about when they dismissed the hint: each Thread's newest unread reply. */
diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
index ac7aabb9f8..ae0dcc6d3d 100644
--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
@@ -7,7 +7,7 @@
* 服务器的回复到了原地替换;失败撤掉、文字放回,原因写在输入框上方。
*/
import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
-import { Check, CornerDownRight, MessageSquareShare, X } from 'lucide-react';
+import { Bell, BellRing, Check, CornerDownRight, MessageSquareShare, X } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
@@ -138,6 +138,10 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
/** Where the reader had read up to when the panel opened; fixed for the panel's life. */
const [readBefore, setReadBefore] = useState<number | null>(null);
const readBeforeRef = useRef<number | null>(null);
+ /** Whether the reader follows this Thread; undefined until known, or when the server keeps no read state. */
+ const [following, setFollowing] = useState<boolean | undefined>(undefined);
+ /** A follow change being written: reads that started before it must not undo it on screen. */
+ const followWriteRef = useRef(0);
/**
* Reads the latest page, or the page before `before`. `rereadOnly` re-reads an opened page for a
@@ -155,9 +159,11 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
// Reading the latest page marks the Thread read only while the reader is at the newest reply:
// a reply that arrives while they read further up stays unread until they scroll down to it.
const markRead = !before && stickToBottomRef.current;
+ const followWrite = followWriteRef.current;
const result = await api().thread({ groupId: group.id, rootId, before, sourceMessageIds: shown.map(message => message.id), markRead });
if (!current()) return;
if (!result.ok) { setError(t(chatErrorKey(result.errorCode))); return; }
+ if (!before && followWrite === followWriteRef.current) setFollowing(result.following);
if (readBeforeRef.current === null && result.readBefore !== undefined) {
readBeforeRef.current = result.readBefore;
setReadBefore(result.readBefore);
@@ -207,6 +213,23 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
}, [read]);
const refreshRef = useRef(refresh);
refreshRef.current = refresh;
+ /** Following is the reader's own switch, off by default: replying or being named never turns it on. */
+ const toggleFollowing = useCallback(async () => {
+ if (following === undefined) return;
+ const next = !following;
+ const write = ++followWriteRef.current;
+ const owner = getDataOwnerGeneration();
+ setFollowing(next);
+ try {
+ const result = await api().thread({ groupId: group.id, rootId, following: next });
+ if (!aliveRef.current || !isDataOwnerGenerationCurrent(owner) || write !== followWriteRef.current) return;
+ if (result.ok) { setFollowing(result.following); return; }
+ setFollowing(!next);
+ toast.error(t(chatErrorKey(result.errorCode)));
+ } catch {
+ if (aliveRef.current && write === followWriteRef.current) { setFollowing(!next); toast.error(t(key('requestFailed'))); }
+ }
+ }, [following, group.id, rootId, t]);
useEffect(() => {
aliveRef.current = true;
refreshRef.current();
@@ -393,11 +416,23 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
className="flex h-full min-w-0 w-1/2 max-w-[min(50%,28rem)] shrink-0 flex-col overflow-hidden border-l border-[var(--border-default)] bg-[var(--surface)]">
<header className="flex h-14 shrink-0 items-center justify-between border-b border-[var(--border-default)] px-5">
<h2 id={titleId} className="text-15 font-medium text-[var(--text-primary)]">{t(key('topic'))}</h2>
- <Tip text={t('bots.close')}>
- <Button variant="secondary" tone="quiet" size="md"
- className="w-8 rounded-none px-0 [&::before]:rounded-full"
- aria-label={t('bots.close')} onClick={onClose}><X size={17} aria-hidden /></Button>
- </Tip>
+ <div className="flex items-center gap-1">
+ {following !== undefined ? (
+ <Tip text={t(key(following ? 'thread.unfollowTip' : 'thread.followTip'))}>
+ <Button variant="secondary" tone="quiet" size="sm" aria-pressed={following} data-thread-follow=""
+ className={cn('gap-1.5 px-2.5', following ? 'text-[var(--text-primary)]' : 'text-[var(--text-secondary)]')}
+ onClick={() => void toggleFollowing()}>
+ {following ? <BellRing size={14} aria-hidden /> : <Bell size={14} aria-hidden />}
+ {t(key(following ? 'thread.following' : 'thread.follow'))}
+ </Button>
+ </Tip>
+ ) : null}
+ <Tip text={t('bots.close')}>
+ <Button variant="secondary" tone="quiet" size="md"
+ className="w-8 rounded-none px-0 [&::before]:rounded-full"
+ aria-label={t('bots.close')} onClick={onClose}><X size={17} aria-hidden /></Button>
+ </Tip>
+ </div>
</header>
<div ref={scrollRef} className="min-h-0 flex-1 overflow-y-auto px-5 pb-4 pt-3"
onScroll={(event) => {
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index cb46d161a8..836542e132 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9627,6 +9627,10 @@
"hintMany_other": "New replies in {{count}} threads",
"hintMentioned": "You were mentioned",
"hintDismiss": "Not now",
+ "follow": "Follow",
+ "following": "Following",
+ "followTip": "Get a hint in the group chat when this thread has new replies",
+ "unfollowTip": "Unfollow: you will only be told when someone mentions you",
"listLabel": "Threads in this group chat",
"listNews": "New replies",
"listOthers": "Other threads",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 3a8d27c460..8db4cb3333 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9588,6 +9588,10 @@
"hintMany_other": "{{count}} 件のスレッドに新着返信があります",
"hintMentioned": "あなたへのメンションがあります",
"hintDismiss": "あとで見る",
+ "follow": "フォロー",
+ "following": "フォロー中",
+ "followTip": "新しい返信があるとグループチャットでお知らせします",
+ "unfollowTip": "フォローを解除すると、メンションされたときだけお知らせします",
"listLabel": "このグループチャットのスレッド",
"listNews": "新着返信あり",
"listOthers": "その他のスレッド",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 6224bea9bd..a7ca9670c5 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9588,6 +9588,10 @@
"hintMany_other": "스레드 {{count}}개에 새 답글이 있습니다",
"hintMentioned": "나를 언급했습니다",
"hintDismiss": "나중에 보기",
+ "follow": "팔로우",
+ "following": "팔로우 중",
+ "followTip": "새 답글이 있으면 그룹 채팅에서 알려 드립니다",
+ "unfollowTip": "팔로우를 해제하면 나를 언급할 때만 알려 드립니다",
"listLabel": "이 그룹 채팅의 스레드",
"listNews": "새 답글 있음",
"listOthers": "다른 스레드",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 8fa6f066e4..237b9b989b 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9588,6 +9588,10 @@
"hintMany_other": "{{count}} 个话题有新回复",
"hintMentioned": "有人提到你",
"hintDismiss": "先不看",
+ "follow": "关注",
+ "following": "已关注",
+ "followTip": "关注后,有新回复时在群聊右下角提示你",
+ "unfollowTip": "取消关注后,只在有人提到你时提示",
"listLabel": "这个群聊里的话题",
"listNews": "有新回复",
"listOthers": "其他话题",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 836fd179a6..b36f0cafb0 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9588,6 +9588,10 @@
"hintMany_other": "{{count}} 個話題有新回覆",
"hintMentioned": "有人提到你",
"hintDismiss": "先不看",
+ "follow": "關注",
+ "following": "已關注",
+ "followTip": "關注後,有新回覆時在群聊右下角提示你",
+ "unfollowTip": "取消關注後,只在有人提到你時提示",
"listLabel": "這個群聊裡的話題",
"listNews": "有新回覆",
"listOthers": "其他話題",
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 029fe37e98..119eaa40f3 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -633,12 +633,16 @@ Desktop 主聊天在根消息下方提示话题里的最新回复,并能把话
(快照的 `reads`,`thread_key` 为根消息 ID),多台电脑同步;服务器不提供已读状态时(旧服务器)一律不显示未读,不把所有话题都标成未读。
- **话题入口**:根消息下那一行里,别人在已读位置之后发的回复(不含自己、系统消息和已删除的)显示为蓝色未读圆点 +「N 条新回复」,
取代「最后回复时间」;其中有人 @ 了你时再加「@你」。只统计房间快照最新 100 条里的回复。从没打开过的话题从头算。
- - **群聊里的话题提示**:输入框上方、聊天列右侧浮一个按钮,只在「有人在话题里 @ 了你、且还没看」时出现(关注的话题来新回复也会出现,见下文关注开关,待服务器去掉自动关注后上线)。
+ - **群聊里的话题提示**:输入框上方、聊天列右侧浮一个按钮,只在「有人在话题里 @ 了你、且还没看」或「你关注的话题来了没看的新回复」时出现。
只有一个这样的话题时点一下直接打开;多个时弹出本群话题列表:上面「有新回复」是进提示的话题,下面「其他话题」是其余有回复的话题,最多 50 个。
点 × 先收起,直到出现比收起时更新的未读回复才再出现(按回复序号判断,删除或滑出窗口的回复不会让它重新出现)。已经开在旁边的话题不进提示。不做跨群的全局话题面板(Chris:「到不同频道去看」)。
- **已读**:话题面板打开、且停在最新回复处时,把已读位置推进到读到的最新回复;往上翻看时新到的回复保持未读,
滚回底部才记为已读。只前进不后退,翻更早的页不算已读。另一台电脑读过,服务器推送 `read.changed`,这里刷新后未读随之清掉;
「查看更早」打开的旧页不重新读取,其中话题入口的未读随最新话题列表更新。
+ - **关注开关**:话题面板右上角「关注」,默认关;打开后显示「已关注」,这个话题的新回复会进群聊右下角的提示。
+ 在话题里回复、被 @ 都不会自动关注(Chris:「以免回了一个就关注了,一直通知」),服务端同时去掉了自动关注并清空历史自动关注
+ (cindy-server#1003)。关注状态存在服务器(`POST /conversations/:id/read` 的 `following`,重述原已读位置,不改变已读),
+ 多台电脑一致;服务器不保存已读状态时不显示开关。群聊目前没有系统通知(桌面弹窗、手机推送),关注暂不触发系统通知,另行决定。
- **面板里的「新回复」分隔线**:打开时记下原来的已读位置,在它之后第一条别人的回复前画一条带蓝点的「新回复」分隔线;
新回复就是从第一条开始时不画。分隔线在面板开着期间不随已读移动。
- **同时发到主聊天**:话题输入框有「同时发到群聊」,默认不选、每次发送后恢复默认、切换话题不继承。先发话题回复,成功后再贴回主聊天;
diff --git a/packages/maker-shared/src/botGroupChat.ts b/packages/maker-shared/src/botGroupChat.ts
index aed63a2a65..a846724631 100644
--- a/packages/maker-shared/src/botGroupChat.ts
+++ b/packages/maker-shared/src/botGroupChat.ts
@@ -200,6 +200,8 @@ export interface BotGroupThreadSummary {
rootText: string;
replyCount: number;
unread: BotGroupThreadUnread;
+ /** The reader chose to follow it; absent when the server keeps no read state. */
+ following?: boolean;
lastReply: { authorName: string; text: string; createdAt: number } | null;
}
@@ -747,12 +749,15 @@ export interface ChatServerApi {
/**
* `markRead` (latest page only): the reader is looking at the Thread, so its server read state
* moves to the newest reply read here; `readBefore` is where it stood before this read.
+ * `following` first sets whether the reader follows the Thread (bot-group-chat.md §10); the
+ * result's `following` is absent when the server keeps no read state.
*/
- thread(input: { groupId: string; rootId: string; before?: number; sourceMessageIds?: string[]; markRead?: boolean }): Promise<ChatServerResult<{
+ thread(input: { groupId: string; rootId: string; before?: number; sourceMessageIds?: string[]; markRead?: boolean; following?: boolean }): Promise<ChatServerResult<{
root: BotGroupMessageView; replies: BotGroupMessageView[]; hasMore: boolean;
/** Same authoritative state as the main timeline; root and replies use one projection. */
executionFailures?: BotGroupExecutionFailureView[];
readBefore?: number;
+ following?: boolean;
}>>;
reply(input: { groupId: string; rootId: string; text: string; clientId: string; mentions: BotGroupMention }): Promise<ChatServerResult<{ messageId: string }>>;
/**