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

+26 -6
View File
@@ -85,6 +85,7 @@ export async function runMainLoop(app: AppContainer): Promise<void> {
accountAuth,
postsRepo,
messagesRepo,
recipientDeduplicator,
redditApi,
monitorService,
processorService,
@@ -290,17 +291,35 @@ export async function runMainLoop(app: AppContainer): Promise<void> {
await rateLimiter.throttle(
async () => {
if (!recipientDeduplicator.tryReserve(post.author)) {
const reason = 'User already contacted across accounts';
logger.info(`Skipping u/${post.author} - ${reason.toLowerCase()}`);
postsRepo.setError(post.id, reason);
webServer?.logActivity(
'skipped',
`Skipped u/${post.author} (already contacted across accounts)`,
post.author,
);
return false;
}
logger.info(`Sending message to u/${post.author}...`);
webServer?.pushLog('info', `Sending message to u/${post.author}...`);
const chat = await chatService.startConversation(
post.author,
processed.generatedMessage,
post.author_fullname,
);
let chat;
try {
chat = await chatService.startConversation(
post.author,
processed.generatedMessage,
post.author_fullname,
);
} catch (error) {
recipientDeduplicator.release(post.author);
throw error;
}
const success = chat !== null;
if (success) {
if (chat) {
postsRepo.markMessageSent(post.id);
// Refresh top chats in background so dashboard is up-to-date.
@@ -340,6 +359,7 @@ export async function runMainLoop(app: AppContainer): Promise<void> {
});
}
} else {
recipientDeduplicator.release(post.author);
postsRepo.setError(post.id, 'Failed to send message');
webServer?.logActivity(
'error',