|
|
@@ -69,6 +69,13 @@ export class MatrixClientService implements OnDestroy {
|
|
|
private readonly _syncState = signal<MxSyncState>('disconnected');
|
|
|
readonly syncState = this._syncState.asReadonly();
|
|
|
|
|
|
+ /**
|
|
|
+ * 本地 store 版本号(每次 sync 完成 +1)。
|
|
|
+ * 聊天页 `effect` 订阅它 → 重读 timeline,解决「同步晚于首读 → 历史空白」。
|
|
|
+ */
|
|
|
+ private readonly _storeVersion = signal(0);
|
|
|
+ readonly storeVersion = this._storeVersion.asReadonly();
|
|
|
+
|
|
|
private readonly _userId = signal<string>('');
|
|
|
/** 当前登录的 Matrix 用户 id(`@xxx:fmode.cn`) */
|
|
|
readonly userId = this._userId.asReadonly();
|
|
|
@@ -160,7 +167,20 @@ export class MatrixClientService implements OnDestroy {
|
|
|
else if (state === 'ERROR') this._syncState.set('disconnected');
|
|
|
else if (state === 'RECONNECTING') this._syncState.set('connecting');
|
|
|
// 🔴 首个 SYNCING = 初次同步完成 → 之后的消息才算「实时」
|
|
|
- if (state === 'SYNCING') this.initialSyncDone = true;
|
|
|
+ if (state === 'SYNCING') {
|
|
|
+ this.initialSyncDone = true;
|
|
|
+ /*
|
|
|
+ * 🔴 通知「timeline 已就绪」。
|
|
|
+ *
|
|
|
+ * `startClient()` 是异步的:`openReal()` 里紧接着读 `timelineToMessages()`
|
|
|
+ * 时,房间的历史事件**往往还没落到本地 store** → 拿到空数组;
|
|
|
+ * 而后续只依赖 realtime 事件补消息,历史内容永远补不上
|
|
|
+ * (表现为:刷新后会话空白、重开看不到之前的内容)。
|
|
|
+ *
|
|
|
+ * 每次 SYNCING 递增版本号,聊天页据此重读一次 timeline。
|
|
|
+ */
|
|
|
+ this._storeVersion.update((n) => n + 1);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 收到邀请自动接受(Agent 侧建房的场景)
|
|
|
@@ -174,7 +194,7 @@ export class MatrixClientService implements OnDestroy {
|
|
|
// 全局消息流(未读计数 + 聊天页复用)
|
|
|
this.bindGlobalMessageStream();
|
|
|
|
|
|
- this.client.startClient({ initialSyncLimit: 20 });
|
|
|
+ this.client.startClient({ initialSyncLimit: 50 });
|
|
|
}
|
|
|
|
|
|
/** 断开并清理(**仅退出登录时**调用) */
|
|
|
@@ -459,7 +479,22 @@ export class MatrixClientService implements OnDestroy {
|
|
|
|
|
|
/** 动态导入 SDK(NFR-02:不进主包) */
|
|
|
private async load(): Promise<typeof import('matrix-js-sdk')> {
|
|
|
- if (!this.sdk) this.sdk = await import('matrix-js-sdk');
|
|
|
+ if (!this.sdk) {
|
|
|
+ this.sdk = await import('matrix-js-sdk');
|
|
|
+ /*
|
|
|
+ * 🔴 SDK 日志降噪(否则控制台卡顿)。
|
|
|
+ *
|
|
|
+ * matrix-js-sdk 的 logger 默认输出 **warn 及以上**,且每条都带完整调用栈
|
|
|
+ * (push rule 缺失的告警会在每次 startClient 时批量刷屏,
|
|
|
+ * 叠加 zone.js 的调度栈,一次上百行)。
|
|
|
+ * 这些告警不影响收发:push rule 是服务端推送规则,浏览器端本就不用。
|
|
|
+ * 故收敛为只保留 error;取不到 logger 时静默跳过,绝不影响连接。
|
|
|
+ */
|
|
|
+ const sdkAny = this.sdk as { logger?: { setLevel?: (l: string) => void } };
|
|
|
+ if (sdkAny.logger && typeof sdkAny.logger.setLevel === 'function') {
|
|
|
+ sdkAny.logger.setLevel('error');
|
|
|
+ }
|
|
|
+ }
|
|
|
return this.sdk;
|
|
|
}
|
|
|
}
|