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

+2 -1
View File
@@ -130,7 +130,8 @@ describe('Database Client', () => {
expect(columnMap.get('subject')?.notnull).toBe(1);
expect(columnMap.get('message')?.notnull).toBe(1);
expect(columnMap.get('sent_at')?.notnull).toBe(1);
expect(columnMap.get('post_id')?.notnull).toBe(1);
expect(columnMap.get('post_id')?.notnull).toBe(0); // nullable — chat rows have no post
expect(columnMap.get('chat_room_id')).toBeDefined();
});
it('successful_messages has correct schema', () => {
+34
View File
@@ -171,6 +171,40 @@ describe('MessagesRepository', () => {
db = repos.db;
});
it('insertChat stores a chat-originated send and getByChatRoomId returns it', () => {
const id = messagesRepo.insertChat({
recipient: 'alice',
subject: 'alice',
message: 'hey there',
sentAt: 1700000000000,
chatRoomId: '!room123:reddit.com',
});
expect(id).toBeGreaterThan(0);
const row = messagesRepo.getByChatRoomId('!room123:reddit.com');
expect(row).toBeDefined();
expect(row!.postId).toBeNull();
expect(row!.chatRoomId).toBe('!room123:reddit.com');
expect(row!.recipient).toBe('alice');
expect(row!.gotResponse).toBe(false);
messagesRepo.markGotResponse(id);
const updated = messagesRepo.getByChatRoomId('!room123:reddit.com');
expect(updated!.gotResponse).toBe(true);
});
it('chat-originated rows appear in getRecent and contribute to stats', () => {
messagesRepo.insertChat({
recipient: 'bob',
subject: 'bob',
message: 'hi',
sentAt: Date.now(),
chatRoomId: '!r1:reddit.com',
});
const recent = messagesRepo.getRecent(10);
expect(recent.some((m) => m.chatRoomId === '!r1:reddit.com')).toBe(true);
});
it('inserts and retrieves a message', () => {
const messageId = messagesRepo.insert({
postId: 'post1',