feat: track received image outcomes

This commit is contained in:
jjbrunton committed 2026-08-08 18:53:11 +01:00
1 parent 50de1c180d
commit d819a0f1e6
15 files changed
+145 -21

No files matched your search

+23
View File
@@ -737,6 +737,9 @@ export class ChatService {
try {
const withMedia = await this.mediaService.attachMedia(chat, mediaMessages);
this.mergeNewMessages(chat, withMedia);
if (withMedia.some((message) => !message.isSelf && (message.media?.length ?? 0) > 0)) {
this.recordReceivedImage(chat);
}
} catch (err) {
this.logger.warn(
`[chat] delta media attach failed for ${roomId}: ${(err as Error).message}`,
@@ -848,6 +851,9 @@ export class ChatService {
if (firstSelf) chat.originMessage = firstSelf.text;
const hasReply = chat.messages.some((m) => !m.isSelf);
const hasReceivedImage = chat.messages.some(
(message) => !message.isSelf && (message.media?.length ?? 0) > 0,
);
let performanceMessage: SentMessageRecord | undefined;
if (firstSelf && chat.roomId && this.messagesRepo) {
@@ -861,6 +867,9 @@ export class ChatService {
if (hasReply && !existing.gotResponse) {
this.messagesRepo.markGotResponse(existing.id);
}
if (hasReceivedImage && !existing.gotImage) {
this.messagesRepo.markGotImage(existing.id);
}
}
} catch (err) {
this.logger.warn('[chat] failed to associate reply with performance context:', err);
@@ -897,6 +906,20 @@ export class ChatService {
}
}
private recordReceivedImage(chat: ActiveChat): void {
if (!chat.roomId || !this.messagesRepo) return;
try {
const existing = this.messagesRepo.getByChatRoomId(chat.roomId);
const hasPerformanceContext = Boolean(
existing?.postId || existing?.strategyId || existing?.subreddit,
);
if (!existing || !hasPerformanceContext) return;
if (!existing.gotImage) this.messagesRepo.markGotImage(existing.id);
} catch (err) {
this.logger.warn('[chat] failed to associate received image with performance context:', err);
}
}
/**
* Project a Matrix room (from /sync) into an ActiveChat. If `prev` is
* supplied, fields it carries (messages, pendingReply, originMessage)
+2
View File
@@ -83,6 +83,8 @@ export class StrategySelector {
totalSent: s?.totalSent || 0,
totalResponses: s?.totalResponses || 0,
responseRate: s?.responseRate || 0,
totalImages: s?.totalImages || 0,
imageRate: s?.imageRate || 0,
configured: true,
});
}