fix: separate Reddit and Matrix runtime identities

This commit is contained in:
jjbrunton committed 2026-08-08 20:25:06 +01:00
1 parent 5623100e93
commit a44768c089
2 files changed
+32 -7

No files matched your search

+20 -7
View File
@@ -17,7 +17,12 @@ import { MonitorService } from './monitor.js';
import { ProcessorService, isSkip } from './processor.js';
import { ResponseCheckerService } from './response-checker.js';
import { StrategySelector } from './strategy-selector.js';
import { AccountAuthContext } from './account-auth-context.js';
import {
AccountAuthContext,
normalizeRedditAccountId,
type AuthenticatedAccount,
type RedditAccountIdentity,
} from './account-auth-context.js';
import { ChatCache } from './chat/cache.js';
import {
ChatService, MatrixClient, MatrixMediaDownloader, MatrixTokenRefresher,
@@ -75,16 +80,12 @@ async function buildRuntime(
}
const accountAuth = new AccountAuthContext(logger);
accountAuth.markAuthenticated({
accountId: session.accountId,
redditUsername: identity.username,
matrixUserId: session.matrixUserId,
});
accountAuth.markAuthenticated(runtimeAuthenticatedAccount(session, identity));
accountAuth.setAuthenticator(async () => {
const current = await browserClient.getAuthenticatedIdentity();
if (!current || matrixRedditId(session.matrixUserId) !== current.accountId.toLowerCase().replace(/^t2_/, '')) return null;
return await matrixClient.whoami() === session.matrixUserId
? { accountId: session.accountId, redditUsername: current.username, matrixUserId: session.matrixUserId }
? runtimeAuthenticatedAccount(session, current)
: null;
});
@@ -153,6 +154,18 @@ async function buildRuntime(
}
}
/** Keeps the Reddit auth fullname separate from the Matrix-shaped runtime/database key. */
export function runtimeAuthenticatedAccount(
session: Pick<VerifiedAccountSession, 'matrixUserId'>,
identity: RedditAccountIdentity,
): AuthenticatedAccount {
return {
accountId: normalizeRedditAccountId(identity.accountId),
redditUsername: identity.username,
matrixUserId: session.matrixUserId,
};
}
class AccountRuntimeLoop {
private controller: AbortController | null = null;
private loop: Promise<void> | null = null;