fix(mobile): exclude own actor from group mentions

Signed-off-by: zqchris <chrisz83@gmail.com>
This commit is contained in:
zqchris
2026-10-09 17:25:14 +08:00
parent 786b2e0def
commit a95144d4cb
4 changed files with 36 additions and 5 deletions

View File

@@ -471,6 +471,19 @@ describe('group composer', () => {
expect(h.row.value).toBe('');
});
it('keeps the current human in the group but excludes it from mention choices and typed mentions', async () => {
h.chat.server = true;
const data = group({ openPlan: null });
data.members.unshift({ ...data.members[0]!, botId: 'self', name: 'Me', actorKind: 'human', isSelf: true });
await render(data);
await type('@');
expect(byId('botGroup.mention.self')).toBeNull();
expect(byId('botGroup.mention.mimi')).not.toBeNull();
await type('@Me @阿布 hello');
await click('botGroup.composer.send');
expect(h.chat.act).toHaveBeenLastCalledWith('send', expect.objectContaining({ mentions: { all: false, botIds: ['abu'] } }));
});
it('sends a 分工 message and keeps the clientId and tag for a retry', async () => {
await render(group({ openPlan: null }));
expect(byId('botGroup.divisionTag')).toBeNull();

View File

@@ -61,6 +61,19 @@ it('lists and opens an existing joined server group with all computers and the r
await act(async () => { await chat.act('send', { text: 'hello', clientId: 'fixture-operation', mentions: { all: false, botIds: [] } }); });
expect(h.auth.apiFetch).toHaveBeenCalledWith(`/v1/conversations/${id}/messages`, expect.objectContaining({ method: 'POST', body: { operationId: 'fixture-operation', content: [{ type: 'text', text: 'hello' }], mentions: [] } }));
});
it('never includes the current human actor in explicit or everyone server mentions', async () => {
const other = '00000000-0000-4000-8000-000000000003';
const original = h.auth.apiFetch.getMockImplementation()!;
h.auth.apiFetch.mockImplementation(async (path, options) => {
const value = await original(path, options);
return path.endsWith('/snapshot') ? { ...value, members: [...value.members, { ...value.members[0], id: other, name: 'Other', ownerActorId: other }] } : value;
});
showChat = true; await render();
for (const all of [false, true]) {
await act(async () => { await chat.act('send', { text: 'hello', clientId: `fixture-${all}`, mentions: { all, botIds: [self, other] } }); });
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('deduplicates server copies from multiple computers while retaining a local legacy group', async () => {
h.legacy.items = ['mac', 'pc'].map(deviceId => ({ key: deviceId, host: { deviceId, deviceName: deviceId }, item: { ref: { collectionId: 'bot-groups', kind: 'bot-group', id }, revision: '1', display: { title: 'Discussion' }, links: [] } }));
h.legacy.isOnline.mockReturnValue(true);

View File

@@ -213,8 +213,11 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {
const latest = page.current;
if (!latest || latest.identity !== identity) throw new Error('CHAT_READ_FAILED');
const mentions = input.mentions as { all: boolean; botIds: string[] };
const recipients = mentions.all
? latest.page.snapshot.members.filter(member => member.state === 'joined').map(member => member.id)
: mentions.botIds;
await api.client.send(groupId, { clientId: String(input.clientId), text: String(input.text),
mentions: { all: false, botIds: mentions.all ? latest.page.snapshot.members.filter(member => member.state === 'joined' && member.id !== latest.self).map(member => member.id) : mentions.botIds } });
mentions: { all: false, botIds: recipients.filter(id => id !== latest.self) } });
reload(); return { effects: [] };
};
const media = async (mediaId: string): Promise<BotGroupAttachment> => {

View File

@@ -118,17 +118,19 @@ export function BotGroupComposer({
const mediaLibraryEnabled = canBrowsePhotoLibraryDirectly(Platform.OS);
const activeMembers = useMemo(() => members.filter(isActiveBotGroupMember), [members]);
const mentionMembers = useMemo(() => members.filter(member => member.isSelf !== true), [members]);
const mentionCandidates = useMemo(() => mentionMembers.filter(isActiveBotGroupMember), [mentionMembers]);
const allLabel = t('groupChat.mention.all');
const query = focused ? findBotGroupMentionQuery(text, caret) : null;
const options = useMemo<MentionOption[]>(() => {
if (!query || activeMembers.length === 0) return [];
if (!query || mentionCandidates.length === 0) return [];
const everyone: MentionOption[] = filterBotGroupMentionCandidates(query.query, [{ name: allLabel }]).length > 0
? [{ kind: 'all', label: allLabel }]
: [];
const people = filterBotGroupMentionCandidates(query.query, activeMembers)
const people = filterBotGroupMentionCandidates(query.query, mentionCandidates)
.map((member): MentionOption => ({ kind: 'member', label: member.name, member }));
return [...everyone, ...people];
}, [activeMembers, allLabel, query]);
}, [mentionCandidates, allLabel, query]);
const pickerOpen = query !== null && options.length > 0;
const trimmed = text.trim();
@@ -193,7 +195,7 @@ export function BotGroupComposer({
const attempt = nextBotGroupSendAttempt(attemptRef.current, draftText, draftDivision, randomUUID, attachmentIds);
attemptRef.current = attempt;
const mentions = resolveBotGroupMentions(draftText, {
members: members.map((member) => ({ botId: member.botId, name: member.name })),
members: mentionMembers.map((member) => ({ botId: member.botId, name: member.name })),
allLabels: [allLabel],
tracked: draftTracked,
});