resolve userids

This commit is contained in:
Arjun 2026-02-26 10:01:04 +05:30
parent a8b7b0ba1a
commit 2223571f6a

View file

@ -201,12 +201,19 @@ async function performSync(): Promise<void> {
await ensureRun();
totalMessages += messages.length;
// Batch-resolve unknown user IDs
// Batch-resolve unknown user IDs (from authors + @mentions in content)
const unknownIds = new Set<string>();
const mentionPattern = /<@(U[A-Z0-9]+)>/g;
for (const msg of messages) {
if (msg.author?.user_id && !state.userCache[msg.author.user_id]) {
unknownIds.add(msg.author.user_id);
}
let match;
while ((match = mentionPattern.exec(msg.content)) !== null) {
if (!state.userCache[match[1]]) {
unknownIds.add(match[1]);
}
}
}
for (const userId of unknownIds) {
@ -219,6 +226,13 @@ async function performSync(): Promise<void> {
}
}
// Replace @mentions in message content with resolved names
for (const msg of messages) {
msg.content = msg.content.replace(/<@(U[A-Z0-9]+)>/g, (_: string, id: string) => {
return `@${state.userCache[id] || id}`;
});
}
// Build and write markdown
const wsName = workspaceNameFromUrl(workspace.url);
const md = buildMarkdown(workspace.url, workspace.name || wsName, messages, state.userCache);