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:
1 parent
2260388dc8
commit
05c95db6bd
10 files changed
+197
-6
No files matched your search
@@ -98,6 +98,43 @@ export function runMigrations(db: Database.Database): void {
|
||||
// Add subreddit column to successful_messages for smarter example selection
|
||||
addColumnIfNotExists('successful_messages', 'subreddit', 'TEXT');
|
||||
|
||||
// Track chats sent via chat.reddit.com so dashboard stats include them.
|
||||
addColumnIfNotExists('sent_messages', 'chat_room_id', 'TEXT');
|
||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_sent_messages_chat_room ON sent_messages(chat_room_id)`);
|
||||
|
||||
// Migration: Make post_id nullable in sent_messages (chat-originated rows
|
||||
// have no associated processed_post). SQLite can't ALTER COLUMN, so recreate.
|
||||
const sentMsgColumns = db.prepare(`PRAGMA table_info(sent_messages)`).all() as { name: string; notnull: number }[];
|
||||
const postIdCol = sentMsgColumns.find((c) => c.name === 'post_id');
|
||||
if (postIdCol && postIdCol.notnull === 1) {
|
||||
db.exec(`
|
||||
CREATE TABLE sent_messages_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id TEXT,
|
||||
recipient TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
sent_at INTEGER NOT NULL,
|
||||
got_response INTEGER DEFAULT 0,
|
||||
response_checked_at INTEGER,
|
||||
strategy_id TEXT,
|
||||
chat_room_id TEXT,
|
||||
FOREIGN KEY (post_id) REFERENCES processed_posts(id)
|
||||
);
|
||||
|
||||
INSERT INTO sent_messages_new (id, post_id, recipient, subject, message, sent_at, got_response, response_checked_at, strategy_id, chat_room_id)
|
||||
SELECT id, post_id, recipient, subject, message, sent_at, got_response, response_checked_at, strategy_id, chat_room_id
|
||||
FROM sent_messages;
|
||||
|
||||
DROP TABLE sent_messages;
|
||||
ALTER TABLE sent_messages_new RENAME TO sent_messages;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sent_messages_response ON sent_messages(got_response);
|
||||
CREATE INDEX IF NOT EXISTS idx_sent_messages_recipient ON sent_messages(recipient);
|
||||
CREATE INDEX IF NOT EXISTS idx_sent_messages_chat_room ON sent_messages(chat_room_id);
|
||||
`);
|
||||
}
|
||||
|
||||
// Migration: Make sent_message_id nullable in successful_messages
|
||||
// SQLite doesn't support ALTER COLUMN, so we need to recreate the table
|
||||
const successfulMsgColumns = db.prepare(`PRAGMA table_info(successful_messages)`).all() as { name: string; notnull: number }[];
|
||||
|
||||
Reference in new issue
Block a user