|
|
@@ -18,6 +18,7 @@ import { GroupsService } from '../../../core/groups.service';
|
|
|
import { LiveService } from '../../../core/live.service';
|
|
|
import { LoopGuardService } from '../../../core/loop-guard.service';
|
|
|
import { MatrixClientService } from '../../../core/matrix-client.service';
|
|
|
+import { SessionService } from '../../../core/session.service';
|
|
|
|
|
|
/**
|
|
|
* 桌面·群聊(多数字生命协作)
|
|
|
@@ -138,6 +139,7 @@ import { MatrixClientService } from '../../../core/matrix-client.service';
|
|
|
[message]="m"
|
|
|
[own]="m.sender === 'me'"
|
|
|
[showSender]="true"
|
|
|
+ [nameOf]="mxName"
|
|
|
/>
|
|
|
}
|
|
|
}
|
|
|
@@ -546,6 +548,7 @@ export class DkGroupPage {
|
|
|
private readonly live = inject(LiveService);
|
|
|
private readonly chat = inject(ChatService);
|
|
|
private readonly mx = inject(MatrixClientService);
|
|
|
+ private readonly session = inject(SessionService);
|
|
|
private readonly route = inject(ActivatedRoute);
|
|
|
private readonly router = inject(Router);
|
|
|
private readonly device = inject(DeviceService);
|
|
|
@@ -617,13 +620,34 @@ export class DkGroupPage {
|
|
|
this.scrollToBottom();
|
|
|
}
|
|
|
|
|
|
+ /** Matrix ID → 展示名(群聊气泡里把 mentions 显示成人能读的名字) */
|
|
|
+ readonly mxName = (mxId: string): string => {
|
|
|
+ for (const a of this.live.agents()) {
|
|
|
+ if (a.channels?.matrixConfig?.userId === mxId) return a.name;
|
|
|
+ }
|
|
|
+ return mxId.replace(/^@/, '').split(':')[0];
|
|
|
+ };
|
|
|
+
|
|
|
memberNames(roomId: string): string {
|
|
|
const list = this.groups.membersOf()(roomId);
|
|
|
return list.length ? list.map((a) => a.name).join('、') : '暂无数字生命';
|
|
|
}
|
|
|
|
|
|
+ /** 我自己的 Matrix ID —— 从会话服务取,不依赖 chat.provisionInfo */
|
|
|
+ private readonly myMxId = computed(() => {
|
|
|
+ // session.me() 的 id 是平台 _User.objectId(小写后即 Matrix 本地部分)
|
|
|
+ const id = this.session.me()?.id;
|
|
|
+ return id ? `@${id.toLowerCase()}:fmode.cn` : '';
|
|
|
+ });
|
|
|
+
|
|
|
private loadMessages(roomId: string): void {
|
|
|
- const my = this.chat.provisionInfo?.userMxId ?? '';
|
|
|
+ /*
|
|
|
+ * 🔴 不能用 `chat.provisionInfo.userMxId` —— 那是**打开 DM 后**才有值的,
|
|
|
+ * 群聊页从没打开过 DM → 恒为 undefined → `my` 是空串 →
|
|
|
+ * 所有消息都被判成 agent(实测:自己发的消息显示在左边、还带着名字)。
|
|
|
+ * 改为从 session.me() 推导,不依赖 chat 的状态。
|
|
|
+ */
|
|
|
+ const my = this.chat.provisionInfo?.userMxId || this.myMxId();
|
|
|
const raw = this.mx.timelineToMessages(roomId);
|
|
|
/*
|
|
|
* 🔴 发送者名字优先用**平台数据**(agent 的 botName),不用 Matrix 的 displayName。
|
|
|
@@ -638,6 +662,12 @@ export class DkGroupPage {
|
|
|
const mx = a.channels?.matrixConfig?.userId;
|
|
|
if (mx) nameByMx.set(mx, a.name);
|
|
|
}
|
|
|
+ /*
|
|
|
+ * 自己的名字:用平台昵称(`用户9836`),不用 Matrix 的 displayName。
|
|
|
+ * Matrix 里那个名字可能是账号创建时随手设的(实测带着 emoji 尾巴),
|
|
|
+ * 在群里显示出来很奇怪。
|
|
|
+ */
|
|
|
+ if (my) nameByMx.set(my, this.session.me()?.name ?? '我');
|
|
|
this.messages.set(
|
|
|
raw
|
|
|
.filter((m) => !!m.body?.trim())
|
|
|
@@ -646,12 +676,12 @@ export class DkGroupPage {
|
|
|
conversationId: roomId,
|
|
|
sender: m.sender === my ? ('me' as const) : ('agent' as const),
|
|
|
senderId: m.sender,
|
|
|
- senderName:
|
|
|
- m.sender === my ? '我' : (nameByMx.get(m.sender) ?? m.senderName ?? m.sender),
|
|
|
+ senderName: nameByMx.get(m.sender) ?? m.senderName ?? m.sender,
|
|
|
kind: m.kind,
|
|
|
text: m.body,
|
|
|
ts: new Date(m.ts).toISOString(),
|
|
|
state: 'sent' as const,
|
|
|
+ mentions: m.mentions,
|
|
|
})),
|
|
|
);
|
|
|
}
|