Improve messaging and dashboard reliability

This commit is contained in:
jjbrunton committed 2026-08-08 21:09:20 +01:00
1 parent 345ec99348
commit 5a5a30a1d4
20 files changed
+406 -56

No files matched your search

+32 -19
View File
@@ -7,7 +7,12 @@ import type {
} from '../../database/repositories.js';
import type { MediaService } from '../media.js';
import { ChatCache } from './cache.js';
import { MatrixClient, MatrixAuthError, MatrixRateLimitError } from './matrix/client.js';
import {
MatrixClient,
MatrixAuthError,
MatrixFeatureDisabledError,
MatrixRateLimitError,
} from './matrix/client.js';
import type { MatrixJoinedRoom, MatrixTimelineEvent } from './matrix/types.js';
import type { ActiveChat, ChatMessage, ScrapedChatMessage, InvitationCooldown } from './types.js';
@@ -128,6 +133,7 @@ export class ChatService {
private readonly t2ToUsername = new Map<string, string>();
/** Rooms whose /joined_members lookup has already failed — don't retry. */
private readonly unresolvableRooms = new Set<string>();
private roomStateLookupAvailable = true;
private syncingKind: 'full' | 'delta' | null = null;
private progress: SyncProgress | null = null;
private progressListener: SyncProgressListener | null = null;
@@ -1341,25 +1347,32 @@ export class ChatService {
chat.username.startsWith('@');
if (!needsLookup) continue;
let t2: string | undefined;
try {
const state = await this.withAuth(() => this.matrix.getRoomFullState(chat.roomId!));
const otherMember = state.find((e) => {
if (e.type !== 'm.room.member') return false;
const sk = (e as { state_key?: string }).state_key;
const membership = (e.content as { membership?: string }).membership;
return (
sk &&
sk !== this.matrix.userId &&
(membership === 'join' || membership === 'invite')
);
}) as { state_key?: string } | undefined;
t2 = otherMember?.state_key?.match(/^@(t2_[^:]+):/)?.[1];
} catch (err) {
if (err instanceof MatrixAuthenticationUnavailableError) {
this.logger.warn('[chat] username enrichment paused until Reddit login is restored');
return;
if (this.roomStateLookupAvailable) {
try {
const state = await this.withAuth(() => this.matrix.getRoomFullState(chat.roomId!));
const otherMember = state.find((e) => {
if (e.type !== 'm.room.member') return false;
const sk = (e as { state_key?: string }).state_key;
const membership = (e.content as { membership?: string }).membership;
return (
sk &&
sk !== this.matrix.userId &&
(membership === 'join' || membership === 'invite')
);
}) as { state_key?: string } | undefined;
t2 = otherMember?.state_key?.match(/^@(t2_[^:]+):/)?.[1];
} catch (err) {
if (err instanceof MatrixAuthenticationUnavailableError) {
this.logger.warn('[chat] username enrichment paused until Reddit login is restored');
return;
}
if (err instanceof MatrixFeatureDisabledError) {
this.roomStateLookupAvailable = false;
this.logger.debug('[chat] room state lookup is disabled upstream; using message history instead');
} else {
this.logger.debug(`[chat] /state lookup failed for ${chat.roomId}:`, err);
}
}
this.logger.debug(`[chat] /state lookup failed for ${chat.roomId}:`, err);
}
if (!t2) {
try {