Record sent chats in messages repo and blur gallery by default

Threads MessagesRepository through ChatService so first outgoing chat
messages are persisted for stats, and extends the repo + DB client to
support chat-room-keyed lookups. Adds tests covering the new behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jjbruntonandClaude Opus 4.7 committed 2026-05-22 18:48:14 +01:00
1 parent 2260388dc8
commit 05c95db6bd
10 files changed
+197 -6

No files matched your search

+23 -1
View File
@@ -1,5 +1,5 @@
import type { Logger } from '../../utils/logger.js';
import type { SuccessfulMessagesRepository } from '../../database/repositories.js';
import type { MessagesRepository, SuccessfulMessagesRepository } from '../../database/repositories.js';
import type { MediaService } from '../media.js';
import { ChatCache } from './cache.js';
import { MatrixClient, MatrixAuthError, MatrixRateLimitError } from './matrix/client.js';
@@ -114,6 +114,7 @@ export class ChatService {
private tokenRefresher?: TokenRefresher,
private usernameResolver?: UsernameResolver,
cache?: ChatCache,
private messagesRepo?: MessagesRepository,
) {
this.cache = cache ?? new ChatCache(logger);
}
@@ -701,6 +702,27 @@ export class ChatService {
if (firstSelf) chat.originMessage = firstSelf.text;
const hasReply = chat.messages.some((m) => !m.isSelf);
if (firstSelf && chat.roomId && this.messagesRepo) {
try {
const existing = this.messagesRepo.getByChatRoomId(chat.roomId);
const id = existing
? existing.id
: this.messagesRepo.insertChat({
recipient: chat.username,
subject: chat.username,
message: firstSelf.text,
sentAt: firstSelf.timestamp,
chatRoomId: chat.roomId,
});
if (hasReply && !existing?.gotResponse) {
this.messagesRepo.markGotResponse(id);
}
} catch (err) {
this.logger.warn('[chat] failed to record sent_message for stats:', err);
}
}
if (firstSelf && hasReply && this.successfulMessagesRepo) {
if (!this.successfulMessagesRepo.existsByMessage(firstSelf.text)) {
const firstReply = chat.messages.find((m) => !m.isSelf);