feat(protocol): send and receive official my-device chats
Pad and phone device conversations were missing from the friend list and arrived as empty private messages. They now show up as stable contacts and support text send/receive. Fixes #452
This commit is contained in:
16 files changed
+692
-17
No files matched your search
@@ -5,6 +5,7 @@
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import { datalineFriendListEntries, DATALINE_UIN_PAD } from '@snowluma/protocol/dataline/device-contacts';
|
||||
import type {
|
||||
FriendInfo, GroupMemberInfo, GroupRequestInfo, QQGroupInfo, UserProfileInfo,
|
||||
} from '@snowluma/protocol/qq-info';
|
||||
@@ -158,7 +159,10 @@ describe('onebot/contact-actions / getFriendList', () => {
|
||||
fetchFriendList: vi.fn(async () => [makeFriend(22222, 'alice', 'best-friend')]),
|
||||
});
|
||||
const out = await getFriendList(bridge);
|
||||
expect(out).toEqual([{ user_id: 22222, nickname: 'alice', remark: 'best-friend' }]);
|
||||
expect(out).toEqual([
|
||||
{ user_id: 22222, nickname: 'alice', remark: 'best-friend' },
|
||||
...datalineFriendListEntries(),
|
||||
]);
|
||||
expect(bridge.apis.contacts.fetchFriendList).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
@@ -169,7 +173,10 @@ describe('onebot/contact-actions / getFriendList', () => {
|
||||
identity: fakeIdentity({ friends: cached }),
|
||||
});
|
||||
const out = await getFriendList(bridge);
|
||||
expect(out).toEqual([{ user_id: 33333, nickname: 'bob', remark: '' }]);
|
||||
expect(out).toEqual([
|
||||
{ user_id: 33333, nickname: 'bob', remark: '' },
|
||||
...datalineFriendListEntries(),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -709,6 +716,20 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
|
||||
});
|
||||
expect(await getStrangerInfo(bridge, 99999)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns the official my-device contact without a profile fetch', async () => {
|
||||
const fetchUserProfile = vi.fn(async () => { throw new Error('should not fetch'); });
|
||||
const bridge = fakeBridge({ fetchUserProfile });
|
||||
expect(await getStrangerInfo(bridge, DATALINE_UIN_PAD)).toEqual({
|
||||
user_id: DATALINE_UIN_PAD,
|
||||
nickname: '我的Pad',
|
||||
remark: '我的Pad',
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
long_nick: '',
|
||||
});
|
||||
expect(fetchUserProfile).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onebot/contact-actions / getGroupSystemMessages', () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { datalineFriendListEntries } from '@snowluma/protocol/dataline/device-contacts';
|
||||
import type { GroupMemberInfo, GroupRequestInfo, QQGroupInfo } from '@snowluma/protocol/qq-info';
|
||||
import { buildApiContext, type OneBotInstanceContext } from '../src/instance-context';
|
||||
import {
|
||||
@@ -688,6 +689,7 @@ describe('buildApiContext contact reads', () => {
|
||||
|
||||
await expect(api.getFriendList()).resolves.toEqual([
|
||||
{ user_id: 22222, nickname: 'alice', remark: 'best-friend' },
|
||||
...datalineFriendListEntries(),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user