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。

fix(mobile): preserve exact server sequences for unread groups

zqchris831edf02faac
diff --git a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
index a44d248a9b..4f12bd4e1e 100644
--- a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
@@ -826,12 +826,15 @@ describe('direct server group presentation', () => {
it('acknowledges other humans only once their messages reach the measured visible tail', async () => {
h.chat.server = true;
+ h.chat.markRead = vi.fn(async () => {});
await render(group({ messages: [message('incoming-human', 12, { authorKind: 'user', isSelf: false, content: 'hello' }),
message('mine', 13, { authorKind: 'user', isSelf: true, content: 'reply' })], plans: [], openPlan: null }));
expect(h.markRead).not.toHaveBeenCalled();
+ expect(h.chat.markRead).not.toHaveBeenCalled();
await act(async () => {
h.scroll.onLayout({ nativeEvent: { layout: { height: 500 } } });
h.scroll.onContentSizeChange(400, 400);
});
- expect(h.markRead).toHaveBeenLastCalledWith('owner', 'mac', 'g1', 12000);
+ expect(h.chat.markRead).toHaveBeenLastCalledWith(['incoming-human']);
+ expect(h.markRead).not.toHaveBeenCalled();
});
diff --git a/apps/mobile/src/__tests__/BotGroupListUnread.test.tsx b/apps/mobile/src/__tests__/BotGroupListUnread.test.tsx
new file mode 100644
index 0000000000..5684281019
--- /dev/null
+++ b/apps/mobile/src/__tests__/BotGroupListUnread.test.tsx
@@ -0,0 +1,39 @@
+// @vitest-environment jsdom
+import { act, createElement } from 'react';
+import { createRoot } from 'react-dom/client';
+import { expect, it, vi } from 'vitest';
+vi.mock('@react-native-async-storage/async-storage', () => ({ default: { getItem: async () => null, setItem: async () => {} } }));
+vi.mock('react-native', async () => { const { createElement } = await import('react'); return { View: ({ children }: any) => createElement('div', null, children) }; });
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, i18n: { language: 'en' } }) }));
+vi.mock('@/auth/AuthContext', () => ({ useAuth: () => ({ user: { id: 'owner' } }) }));
+vi.mock('@/session/BotGroupAvatars', () => ({ BotGroupDuoAvatar: () => null, useBotGroupIdentities: () => () => ({}) }));
+vi.mock('@/session/messageMarkdown', () => ({ parseMobileMarkdownInlines: () => [] }));
+vi.mock('@/session/sessionList', () => ({ formatRemoteSessionSidebarTime: () => 'now' }));
+vi.mock('@/session/CompanionListRow', async () => { const { createElement } = await import('react'); return {
+ CompanionListRow: ({ unread, accessibilityLabel }: any) => createElement('button', { 'data-unread': String(unread), 'aria-label': accessibilityLabel }),
+}; });
+import { chatRoomRow, chatReadAt, chatReadSequence, type ChatSnapshot } from '@/chat/chatServerClient';
+import { markRemoteResourceRead } from '@/device-link/remoteResourceCache';
+import { BotGroupListRow } from '@/session/BotGroupList';
+Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
+
+it('shows the unacknowledged same-millisecond reply in the actual group list row and clears it after reading', async () => {
+ const first = '9007199254740992', second = '9007199254740993';
+ const snapshot: ChatSnapshot = { room: { id: 'group', name: 'Discussion', kind: 'group', archived: false, revision: 1,
+ created_at: '2026-10-09', updated_at: '2026-10-09', response_mode: 'all', speaking_mode: 'auto' }, cursor: second,
+ reads: [{ thread_key: 'main', read_seq: first }], members: [], messages: [first, second].map((seq, index) => ({
+ id: `incoming-${index}`, seq, authorId: 'other', author: { kind: 'bot', name: 'Teammate' },
+ createdAt: '2026-10-09T10:00:00.123Z', deleted: false, threadRootId: null, content: [{ type: 'text', text: 'hello' }],
+ })) };
+ const row = chatRoomRow(snapshot.room, snapshot, 'self');
+ await markRemoteResourceRead('owner', '', 'group', chatReadAt(snapshot, 'self'), chatReadSequence(snapshot));
+ const node = document.createElement('div'), root = createRoot(node);
+ try {
+ await act(async () => root.render(createElement(BotGroupListRow, { row, online: true, onPress: () => {} })));
+ expect(node.querySelector('button')?.getAttribute('data-unread')).toBe('true');
+ expect(node.querySelector('button')?.getAttribute('aria-label')).toContain('devices.companions.unread');
+ await act(async () => { await markRemoteResourceRead('owner', '', 'group', row.item.display.lastReplyAt!, second); });
+ expect(node.querySelector('button')?.getAttribute('data-unread')).toBe('false');
+ expect(node.querySelector('button')?.getAttribute('aria-label')).not.toContain('devices.companions.unread');
+ } finally { act(() => root.unmount()); }
+});
diff --git a/apps/mobile/src/__tests__/chatServerClient.test.ts b/apps/mobile/src/__tests__/chatServerClient.test.ts
index 54d542cf52..6f48f62e1a 100644
--- a/apps/mobile/src/__tests__/chatServerClient.test.ts
+++ b/apps/mobile/src/__tests__/chatServerClient.test.ts
@@ -94,6 +94,7 @@ describe('direct Chat Server client', () => {
const notice = { ...message(103), origin: 'system', createdAt: '2026-10-09T03:00:00Z' };
const value = { ...snapshot(), messages: [notice, mine, incoming], reads: [{ thread_key: 'main', read_seq: message(100).seq }] };
expect(chatRoomRow(value.room, value, id(11)).item.display.lastReplyAt).toBe(Date.parse(incoming.createdAt));
+ expect(chatRoomRow(value.room, value, id(11)).lastReplySequence).toBe(incoming.seq);
expect(chatReadAt(value, id(11))).toBe(0);
value.reads[0].read_seq = incoming.seq;
expect(chatReadAt(value, id(11))).toBe(Date.parse(incoming.createdAt));
diff --git a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
index 867e7dc6c9..caf100b319 100644
--- a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
+++ b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
@@ -10,7 +10,7 @@ const h = vi.hoisted(() => ({
targets: [] as { deviceId: string; deviceName: string }[],
foreground: new Set<(state: string) => void>(),
}));
-vi.mock('@react-native-async-storage/async-storage', () => ({ default: { getItem: vi.fn(async () => null), setItem: vi.fn(async () => {}), removeItem: vi.fn(async () => {}) } }));
+vi.mock('@react-native-async-storage/async-storage', () => ({ default: { getItem: vi.fn(async () => null), setItem: vi.fn(async () => {}), removeItem: vi.fn(async () => {}), getAllKeys: vi.fn(async () => []), multiRemove: vi.fn(async () => {}) } }));
vi.mock('react-native', () => ({ AppState: { currentState: 'active', addEventListener: (_: string, fn: (state: string) => void) => { h.foreground.add(fn); return { remove: () => h.foreground.delete(fn) }; } } }));
vi.mock('expo-router', async () => { const { useEffect } = await import('react'); return { useFocusEffect: (fn: any) => useEffect(fn, [fn]) }; });
vi.mock('react-i18next', () => ({ useTranslation: () => ({ i18n: { language: 'en' } }) }));
@@ -23,6 +23,7 @@ vi.mock('@/device-link/remoteStatus', () => ({ formatRemoteError: String }));
import { useBotGroupChat } from '@/session/useBotGroupChat';
import { useBotGroupRoster } from '@/session/useBotGroupRoster';
import { botGroupRoute } from '@/session/botGroupNavigation';
+import { isRemoteResourceUnread, clearRemoteResourceCache } from '@/device-link/remoteResourceCache';
const id = '00000000-0000-4000-8000-000000000001';
const self = '00000000-0000-4000-8000-000000000002';
const room = { id, name: 'Discussion', kind: 'group', state: 'joined', revision: 1, archived: false,
@@ -76,6 +77,29 @@ it('never includes the current human actor in explicit or everyone server mentio
expect(h.auth.apiFetch).toHaveBeenCalledWith(`/v1/conversations/${id}/messages`, expect.objectContaining({ method: 'POST', body: { operationId: `fixture-${all}`, content: [{ type: 'text', text: 'hello' }], mentions: [other] } }));
}
});
+it('imports read_seq and acknowledges only displayed incoming messages with their exact sequences', async () => {
+ await clearRemoteResourceCache();
+ const first = '9007199254740992', second = '9007199254740993';
+ const messages = [first, second].map((seq, index) => ({ id: `incoming-${index}`, seq, authorId: id,
+ author: { kind: 'human', name: 'Other' }, content: [{ type: 'text', text: 'hello' }],
+ createdAt: '2026-10-09T10:00:00.123Z', deleted: false, threadRootId: null }));
+ const original = h.auth.apiFetch.getMockImplementation()!;
+ h.auth.apiFetch.mockImplementation(async (path, options) => {
+ if (path.includes('/messages?')) return messages;
+ const value = await original(path, options);
+ return path.endsWith('/snapshot') ? { ...value, messages, cursor: second, reads: [{ thread_key: 'main', read_seq: first }] } : value;
+ });
+ await render();
+ const row = roster.items[0];
+ const unread = () => isRemoteResourceUnread('owner', '', id, row.item.display.lastReplyAt, row.lastReplySequence);
+ expect(unread()).toBe(true);
+ showChat = true; await render();
+ await act(async () => { await chat.markRead!(['incoming-0', 'unseen-id']); });
+ expect(unread()).toBe(true);
+ await act(async () => { await chat.markRead!(['incoming-0', 'incoming-1']); });
+ expect(unread()).toBe(false);
+ expect(h.auth.apiFetch.mock.calls.some(([, options]) => options.method === 'POST')).toBe(false);
+});
it('resolves everyone using authorized members at send time instead of the displayed snapshot', async () => {
const joined = '00000000-0000-4000-8000-000000000003';
const invited = '00000000-0000-4000-8000-000000000004';
diff --git a/apps/mobile/src/__tests__/remoteResourceCache.test.ts b/apps/mobile/src/__tests__/remoteResourceCache.test.ts
index feea0e6565..b5c54fe70f 100644
--- a/apps/mobile/src/__tests__/remoteResourceCache.test.ts
+++ b/apps/mobile/src/__tests__/remoteResourceCache.test.ts
@@ -8,6 +8,7 @@ vi.mock('@react-native-async-storage/async-storage', () => ({ default: {
multiRemove: vi.fn(async (keys: string[]) => { keys.forEach((key) => disk.delete(key)); }),
} }));
import { cacheRemoteResourceHome, cacheRemoteResourceItems, clearRemoteResourceCache, isRemoteResourceUnread, markRemoteResourceRead, readRemoteResourceSnapshot, remoteResourceCacheRevision, subscribeRemoteResourceCache } from '@/device-link/remoteResourceCache';
+import { chatReadAt, chatRoomRow, type ChatSnapshot } from '@/chat/chatServerClient';
const rows = (deviceId: string, lastReplyAt: number) => [{
key: `${deviceId}:bot:writer`, host: { deviceId, deviceName: deviceId },
item: { ref: { collectionId: 'teammates', kind: 'bot', id: 'writer' }, display: { title: 'Writer', lastReplyAt }, revision: '1', links: [] },
@@ -44,6 +45,26 @@ it('keeps device-qualified read positions and treats only later host replies as
expect(isRemoteResourceUnread('alice', 'home', 'writer', 200)).toBe(false);
expect((await readRemoteResourceSnapshot('bob')).items).toEqual({});
});
+it('preserves unread replies in the same millisecond using exact server sequences', async () => {
+ const first = '9007199254740992', second = '9007199254740993';
+ const data: ChatSnapshot = { room: { id: 'group', name: 'Discussion', kind: 'group', archived: false, revision: 1,
+ created_at: '2026-10-09', updated_at: '2026-10-09', response_mode: 'all', speaking_mode: 'auto' }, cursor: second,
+ reads: [{ thread_key: 'main', read_seq: first }], members: [], messages: [first, second].map((seq, index) => ({
+ id: `incoming-${index}`, seq, authorId: 'other', author: { kind: 'human', name: 'Other' },
+ createdAt: '2026-10-09T10:00:00.123Z', deleted: false, threadRootId: null, content: [{ type: 'text', text: 'hello' }],
+ })) };
+ const row = chatRoomRow(data.room, data, 'self');
+ await markRemoteResourceRead('alice', '', 'group', chatReadAt(data, 'self'), first);
+ expect(isRemoteResourceUnread('alice', '', 'group', row.item.display.lastReplyAt, second)).toBe(true);
+ await markRemoteResourceRead('alice', '', 'group', row.item.display.lastReplyAt!, second);
+ await markRemoteResourceRead('alice', '', 'group', chatReadAt(data, 'self'), first);
+ expect(isRemoteResourceUnread('alice', '', 'group', row.item.display.lastReplyAt, second)).toBe(false);
+ expect(isRemoteResourceUnread('bob', '', 'group', row.item.display.lastReplyAt, second)).toBe(true);
+ vi.resetModules();
+ const restored = await import('@/device-link/remoteResourceCache');
+ await restored.readRemoteResourceSnapshot('alice');
+ expect(restored.isRemoteResourceUnread('alice', '', 'group', row.item.display.lastReplyAt, second)).toBe(false);
+});
it('stays silent when a read mark or roster refresh leaves the cache unchanged', async () => {
const { default: storage } = await import('@react-native-async-storage/async-storage');
await cacheRemoteResourceItems('alice', 'teammates', rows('home', 100));
diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.ts
index 2cd9aa5bcf..ffc3d4a757 100644
--- a/apps/mobile/src/chat/chatServerClient.ts
+++ b/apps/mobile/src/chat/chatServerClient.ts
@@ -48,7 +48,8 @@ export function chatRoomRow(room: ChatRoom, snapshot?: ChatSnapshot, selfId?: st
const members = snapshot?.members.filter(member => member.state === 'joined') ?? [];
const last = snapshot?.messages.filter(message => !message.threadRootId && !message.deleted)
.sort((a, b) => BigInt(chatCursor(a.seq)) < BigInt(chatCursor(b.seq)) ? 1 : -1)[0];
- return { key: `chat:${room.id}`, host: { deviceId: '', deviceName: '' }, item: {
+ return { key: `chat:${room.id}`, host: { deviceId: '', deviceName: '' },
+ lastReplySequence: snapshot && selfId ? chatLastReplySequence(snapshot.messages, selfId) : undefined, item: {
ref: { collectionId: 'bot-groups', kind: 'bot-group', id: room.id },
revision: String(room.head ?? room.revision), display: { title: room.name,
subtitle: members.map(memberName).join(' · '),
@@ -61,15 +62,26 @@ export function chatRoomRow(room: ChatRoom, snapshot?: ChatSnapshot, selfId?: st
}
/** Only incoming main-timeline messages count; a system notice or our own send is not a reply. */
+const incomingReply = (message: ChatMessage, selfId: string) => !message.deleted && !message.threadRootId
+ && message.origin !== 'system' && message.authorId !== selfId;
+
export function chatLastReplyAt(messages: readonly ChatMessage[], selfId: string): number {
- return messages.reduce((latest, message) => !message.deleted && !message.threadRootId
- && message.origin !== 'system' && message.authorId !== selfId
+ return messages.reduce((latest, message) => incomingReply(message, selfId)
? Math.max(latest, Date.parse(message.createdAt)) : latest, 0);
}
+export function chatLastReplySequence(messages: readonly ChatMessage[], selfId: string): string {
+ return messages.reduce((latest, message) => incomingReply(message, selfId) && BigInt(chatCursor(message.seq)) > BigInt(latest)
+ ? message.seq : latest, '0');
+}
+
+export function chatReadSequence(snapshot: ChatSnapshot): string {
+ return chatCursor(snapshot.reads?.find(read => read.thread_key === 'main')?.read_seq ?? '0');
+}
+
/** Import only the server's acknowledged position, never mark an unseen reply as read. */
export function chatReadAt(snapshot: ChatSnapshot, selfId: string): number {
- const sequence = snapshot.reads?.find(read => read.thread_key === 'main')?.read_seq ?? '0';
+ const sequence = chatReadSequence(snapshot);
return chatLastReplyAt(snapshot.messages.filter(message => BigInt(chatCursor(message.seq)) <= BigInt(chatCursor(sequence))), selfId);
}
diff --git a/apps/mobile/src/chat/useChatServer.ts b/apps/mobile/src/chat/useChatServer.ts
index 5b35879263..76d858ef7a 100644
--- a/apps/mobile/src/chat/useChatServer.ts
+++ b/apps/mobile/src/chat/useChatServer.ts
@@ -8,7 +8,7 @@ import { getActiveMobileSessionRealm, getMobileEndpointForRealm, loadMobileEndpo
import { markRemoteResourceRead } from '@/device-link/remoteResourceCache';
import { useRemoteSyncCoordinator } from '@/device-link/remoteSyncTask';
import type { BotGroupChatState } from '@/session/useBotGroupChat';
-import { chatAccessLost, chatCursor, chatGroupView, chatHttpsUrl, chatRoomRow, chatReadAt, createChatServerClient, type ChatPage, type ChatRequest, type ChatSnapshot } from './chatServerClient';
+import { chatAccessLost, chatCursor, chatGroupView, chatHttpsUrl, chatRoomRow, chatReadAt, chatReadSequence, chatLastReplyAt, chatLastReplySequence, createChatServerClient, type ChatPage, type ChatRequest, type ChatSnapshot } from './chatServerClient';
import { subscribeChatServer } from './chatServerSubscription';
function useChatClient() {
@@ -84,7 +84,7 @@ export function useChatServerRoster(enabled: boolean) {
// or making a server read-state mutation just because the roster was fetched.
for (const [id, snapshot] of fresh) {
if (run.isStale() || !api.current()) return;
- await markRemoteResourceRead(api.userId, '', id, chatReadAt(snapshot.value, self));
+ await markRemoteResourceRead(api.userId, '', id, chatReadAt(snapshot.value, self), chatReadSequence(snapshot.value));
}
if (run.isStale() || !api.current()) return;
snapshots.current = fresh;
@@ -250,6 +250,14 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {
throw error;
}
};
+ const markRead = useCallback(async (messageIds: readonly string[]) => {
+ const latest = page.current;
+ if (!api.current() || active.current !== identity || !latest || latest.identity !== identity) return;
+ // Only the measured UI's messages are acknowledged, even if a newer read is settling.
+ const seen = new Set(messageIds);
+ const messages = latest.page.messages.filter(message => seen.has(message.id));
+ await markRemoteResourceRead(api.userId, '', groupId, chatLastReplyAt(messages, latest.self), chatLastReplySequence(messages, latest.self));
+ }, [api, groupId, identity]);
return { state: state.identity === identity ? state.value : { kind: 'loading' } as BotGroupChatState,
- online: state.identity === identity && state.online, reload, act, loadOlder, loadingOlder: state.loadingOlder, media };
+ online: state.identity === identity && state.online, reload, act, loadOlder, loadingOlder: state.loadingOlder, media, markRead };
}
diff --git a/apps/mobile/src/device-link/remoteResourceCache.ts b/apps/mobile/src/device-link/remoteResourceCache.ts
index cfaabc906f..8d1c904b23 100644
--- a/apps/mobile/src/device-link/remoteResourceCache.ts
+++ b/apps/mobile/src/device-link/remoteResourceCache.ts
@@ -3,8 +3,9 @@ import { isMobileRemoteCollectionSupported, normalizeRemoteCollectionItems, pars
const PREFIX = 'cindy.remoteResources.v1.';
const MAX_CHARS = 256 * 1024;
-type Snapshot = { home: RemoteHomeCollection[]; items: Record<string, HostedRemoteCollectionItem[]>; read: Record<string, number> };
-const empty = (): Snapshot => ({ home: [], items: {}, read: {} });
+type Snapshot = { home: RemoteHomeCollection[]; items: Record<string, HostedRemoteCollectionItem[]>; read: Record<string, number>; readSequences?: Record<string, string> };
+const empty = (): Snapshot => ({ home: [], items: {}, read: {}, readSequences: {} });
+const validSequence = (value: unknown): value is string => typeof value === 'string' && /^\d{1,30}$/.test(value);
let epoch = 0;
const writes = new Map<string, Promise<void>>();
const snapshots = new Map<string, Snapshot>();
@@ -38,6 +39,9 @@ function normalize(raw: unknown): Snapshot {
if (value.read && typeof value.read === 'object') for (const [key, at] of Object.entries(value.read).slice(-2000)) {
if (key.length <= 600 && typeof at === 'number' && Number.isFinite(at) && at >= 0) out.read[key] = at;
}
+ if (value.readSequences && typeof value.readSequences === 'object') for (const [key, sequence] of Object.entries(value.readSequences).slice(-2000)) {
+ if (key.length <= 600 && validSequence(sequence)) out.readSequences![key] = sequence;
+ }
return out;
}
@@ -87,12 +91,19 @@ export const cacheRemoteResourceItems = (userId: string, collectionId: string, i
if ((row.item.ref.kind === 'bot' || row.item.ref.kind === 'bot-group') && s.read[key] === undefined) s.read[key] = row.item.display.lastReplyAt ?? 0;
}
});
-export const markRemoteResourceRead = (userId: string, deviceId: string, resourceId: string, at: number) => update(userId, (s) => {
+export const markRemoteResourceRead = (userId: string, deviceId: string, resourceId: string, at: number, sequence?: string) => update(userId, (s) => {
const key = remoteResourceReadKey(deviceId, resourceId);
if (Number.isFinite(at) && at >= 0) s.read[key] = Math.max(s.read[key] ?? 0, at);
+ if (validSequence(sequence)) {
+ const sequences = s.readSequences ??= {};
+ if (sequences[key] === undefined || BigInt(sequence) > BigInt(sequences[key])) sequences[key] = sequence;
+ }
});
-export function isRemoteResourceUnread(userId: string, deviceId: string, resourceId: string, at?: number): boolean {
- const read = snapshots.get(userId)?.read[remoteResourceReadKey(deviceId, resourceId)];
+export function isRemoteResourceUnread(userId: string, deviceId: string, resourceId: string, at?: number, sequence?: string): boolean {
+ const snapshot = snapshots.get(userId);
+ const key = remoteResourceReadKey(deviceId, resourceId);
+ if (validSequence(sequence)) return BigInt(sequence) > BigInt(snapshot?.readSequences?.[key] ?? '0');
+ const read = snapshot?.read[key];
return at !== undefined && read !== undefined && at > read;
}
/** Name the cached Bot whose conversation link is this task. Presentation only; access stays live. */
diff --git a/apps/mobile/src/device-link/remoteResources.ts b/apps/mobile/src/device-link/remoteResources.ts
index 34811ea972..cb03537512 100644
--- a/apps/mobile/src/device-link/remoteResources.ts
+++ b/apps/mobile/src/device-link/remoteResources.ts
@@ -462,6 +462,8 @@ export interface HostedRemoteCollectionItem {
key: string;
host: RemoteResourceHostTarget;
item: RemoteCollectionItem;
+ /** Local direct Chat Server projection; never changes the device-link wire display. */
+ lastReplySequence?: string;
}
/** Replace successful host shards while retaining stale rows for transiently failed hosts. */
diff --git a/apps/mobile/src/session/BotGroupChatScreen.tsx b/apps/mobile/src/session/BotGroupChatScreen.tsx
index 1aba12611a..e1820a25eb 100644
--- a/apps/mobile/src/session/BotGroupChatScreen.tsx
+++ b/apps/mobile/src/session/BotGroupChatScreen.tsx
@@ -142,11 +142,13 @@ export function BotGroupChatScreen({ deviceId, deviceName, groupId }: { deviceId
if (measured.owner !== viewportOwner || measured.measuredGroup !== group
|| measured.viewportHeight <= 0 || measured.contentHeight <= 0
|| measured.contentHeight - measured.offsetY - measured.viewportHeight >= STICK_TO_BOTTOM_PX) return;
- const at = group.messages.reduce((latest, message) => message.kind === 'message' && message.isSelf !== true
+ const incoming = group.messages.filter(message => message.kind === 'message' && message.isSelf !== true
&& (message.authorKind === 'bot' || (message.authorKind === 'user' && message.isSelf === false))
- ? Math.max(latest, message.createdAt) : latest, 0);
+ );
+ if (chat.server && chat.markRead) { void chat.markRead(incoming.map(message => message.id)); return; }
+ const at = incoming.reduce((latest, message) => Math.max(latest, message.createdAt), 0);
if (at > 0) void markRemoteResourceRead(user?.id ?? '', deviceId, groupId, at);
- }, [focused, group, user?.id, deviceId, groupId, viewportOwner]);
+ }, [focused, group, user?.id, deviceId, groupId, viewportOwner, chat.server, chat.markRead]);
useEffect(() => {
const frame = requestAnimationFrame(acknowledge);
const subscription = AppState.addEventListener('change', state => { if (state === 'active') acknowledge(); });
diff --git a/apps/mobile/src/session/BotGroupList.tsx b/apps/mobile/src/session/BotGroupList.tsx
index f700a3d5d2..6cf3d1e3f7 100644
--- a/apps/mobile/src/session/BotGroupList.tsx
+++ b/apps/mobile/src/session/BotGroupList.tsx
@@ -30,7 +30,7 @@ export function BotGroupListRow({ row, online, last = false, onPress }: {
const { user } = useAuth();
useSyncExternalStore(subscribeRemoteResourceCache, remoteResourceCacheRevision);
const display = row.item.display;
- const unread = isRemoteResourceUnread(user?.id ?? '', row.host.deviceId, row.item.ref.id, display.lastReplyAt);
+ const unread = isRemoteResourceUnread(user?.id ?? '', row.host.deviceId, row.item.ref.id, display.lastReplyAt, row.lastReplySequence);
const title = resolveRemoteText(display.title, i18n.language);
const preview = display.preview ? parseMobileMarkdownInlines(resolveRemoteText(display.preview, i18n.language))
.map((inline) => inline.type === 'image' ? inline.alt : inline.text).join('').replace(/\s+/g, ' ').trim() : '';
diff --git a/apps/mobile/src/session/useBotGroupChat.ts b/apps/mobile/src/session/useBotGroupChat.ts
index 4f203ad66d..2aa4b9c83d 100644
--- a/apps/mobile/src/session/useBotGroupChat.ts
+++ b/apps/mobile/src/session/useBotGroupChat.ts
@@ -109,5 +109,5 @@ export function useBotGroupChat(host: RemoteResourceHostTarget, groupId: string)
void presenceVersion;
// Unknown presence still allows actions; the host answers or the link reports offline.
const online = status === 'online' && !!host.deviceId && getPresenceAvailability(host.deviceId) !== false;
- return !host.deviceId ? { ...server, server: true } : { state: value, reload, act, online, server: false, loadOlder: undefined, loadingOlder: false, media: undefined };
+ return !host.deviceId ? { ...server, server: true } : { state: value, reload, act, online, server: false, loadOlder: undefined, loadingOlder: false, media: undefined, markRead: undefined };
}
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 5e5a1cf0db..60405a6e8b 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -266,7 +266,7 @@
用字符串游标 ack,断线/前后台切换重连并重读授权快照。离开页面或切换账号即停止订阅。
群详情分页读取主时间线;通知使已展示的历史窗口重新核权读取,撤权清空页面,恢复成员权限后重新建立订阅。
实时订阅断线仅触发重连与定时核对,HTTP 可用时仍可发言;HTTP 读写失败进入读取恢复,发送被撤权拒绝时立即清空群页。
- 列表从当前账号投影其他成员消息的未读时间;复用本地已读镜像与可见尾部确认,读取列表不向服务器提交已读。
+ 列表从当前账号投影其他成员消息的未读序号,用字符串序号精确比较本地已读镜像与服务器 `read_seq`,不以时间戳代替序号;前台可见尾部确认只推进已显示消息的已读位置,读取列表不向服务器提交已读。
- 直连页支持已有群的列表、成员查看、主时间线与旧历史、文字及 @ 发言;
`@所有人` 在发送前读取当前授权成员,只展开已加入且非本人的 actor,避免使用旧页面快照漏掉新成员。
私有附件点击时重新授权,图片走已有看图器,其他文件打开短期签名 HTTPS URL,不转交账号 token。