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:
DrSmoothl committed 2026-09-14 19:34:42 +08:00
1 parent 60c9669abd
commit dac3deb7bd
16 files changed
+692 -17

No files matched your search

+33 -11
View File
@@ -1,6 +1,7 @@
import { mapWithConcurrency } from '@snowluma/common/concurrency';
import { createLogger } from '@snowluma/common/logger';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { datalineFriendListEntries, findDatalineDeviceByUin } from '@snowluma/protocol/dataline/device-contacts';
import {
formatGroupRequestFlag,
type GroupMemberInfo,
@@ -45,21 +46,31 @@ async function fetchSingleGroupMembers(
}
}
function toFriendRow(friend: { uin: number; nickname: string; remark: string }): JsonObject {
return {
user_id: friend.uin,
nickname: friend.nickname,
remark: friend.remark,
};
}
export async function getFriendList(bridge: BridgeInterface): Promise<JsonObject[]> {
let rows: JsonObject[];
try {
const friends = await bridge.apis.contacts.fetchFriendList();
return friends.map(f => ({
user_id: f.uin,
nickname: f.nickname,
remark: f.remark,
}));
rows = (await bridge.apis.contacts.fetchFriendList()).map(toFriendRow);
} catch {
return bridge.identity.friends.map(f => ({
user_id: f.uin,
nickname: f.nickname,
remark: f.remark,
}));
rows = bridge.identity.friends.map(toFriendRow);
}
const occupied = new Set(rows.map((row) => Number(row.user_id)));
for (const extra of datalineFriendListEntries()) {
if (occupied.has(extra.user_id)) continue;
rows.push({
user_id: extra.user_id,
nickname: extra.nickname,
remark: extra.remark,
});
}
return rows;
}
export async function getGroupList(
@@ -332,6 +343,17 @@ export async function getStrangerInfo(
bridge: BridgeInterface,
userId: number,
): Promise<JsonObject | null> {
const device = findDatalineDeviceByUin(userId);
if (device) {
return {
user_id: device.uin,
nickname: device.name,
remark: device.name,
sex: 'unknown',
age: 0,
long_nick: '',
};
}
try {
const p = await bridge.apis.contacts.fetchUserProfile(userId);
const corp = await strangerCorpInfo(bridge, p);
@@ -1,5 +1,6 @@
import { createLogger } from '@snowluma/common/logger';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { findDatalineDeviceByUin } from '@snowluma/protocol/dataline/device-contacts';
import type { ForwardNodePayload, FriendMessage, GroupMessage, MessageElement, MessageElementOf, QQEventVariant } from '@snowluma/protocol/events';
import { getVideoSourceSize, MAX_VIDEO_SIZE } from '@snowluma/protocol/highway/video-upload';
import { guessFileNameFromUrl } from '@snowluma/protocol/highway/utils';
@@ -870,6 +871,17 @@ export async function sendPrivateMessage(
);
}
if (findDatalineDeviceByUin(userId)) {
const unsupported = elements.find((element) => element.type !== 'text');
if (unsupported) {
throw new MessageElementValidationError(
'UNSENDABLE_TYPE',
`message element "${unsupported.type}" cannot be sent to this contact`,
unsupported.type,
);
}
}
// Temp sessions only have the message-element transport. File elements use
// the friend c2c upload path, so reject them before sending any preceding
// text/media batch; discovering this after sendText would create a partial