Show Reddit post age in conversations

This commit is contained in:
jjbrunton committed 2026-08-09 09:54:53 +01:00
1 parent 7db60e8839
commit 50f9f8a6aa
14 files changed
+65 -11

No files matched your search

+4
View File
@@ -36,6 +36,7 @@ export function runMigrations(db: Database.Database): void {
image_url TEXT,
image_analysis TEXT,
generated_message TEXT,
post_created_at INTEGER,
processed_at INTEGER NOT NULL,
message_sent INTEGER DEFAULT 0,
error TEXT
@@ -272,6 +273,9 @@ export function runMigrations(db: Database.Database): void {
CREATE INDEX IF NOT EXISTS idx_ai_usage_model ON ai_usage(actual_model, requested_model, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_ai_usage_account ON ai_usage(account_id, created_at DESC);
`),
() => {
addColumnIfNotExists(db, 'processed_posts', 'post_created_at', 'INTEGER');
},
];
let currentVersion = db.pragma('user_version', { simple: true }) as number;
+13 -5
View File
@@ -16,6 +16,7 @@ export interface ProcessedPostRecord {
imageUrl: string | null;
imageAnalysis: string | null;
generatedMessage: string | null;
postCreatedAt: number | null;
processedAt: number;
messageSent: boolean;
error: string | null;
@@ -43,6 +44,7 @@ export interface SentMessageRecord {
postUrl?: string;
postImageUrl?: string;
postImageAnalysis?: string;
postCreatedAt?: number;
}
export interface SuccessfulMessageRecord {
@@ -418,8 +420,9 @@ export class PostsRepository {
private readonly accountId: string = LEGACY_UNASSIGNED_ACCOUNT_ID,
) {
this.insertStmt = db.prepare(`
INSERT INTO processed_posts (account_id, id, subreddit, author, title, post_url, image_url, processed_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO processed_posts (
account_id, id, subreddit, author, title, post_url, image_url, post_created_at, processed_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`);
this.existsStmt = db.prepare(`SELECT 1 FROM processed_posts WHERE account_id = ? AND id = ?`);
@@ -462,6 +465,7 @@ export class PostsRepository {
title: string;
postUrl?: string | null;
imageUrl: string | null;
postCreatedAt?: number | null;
processedAt: number;
}): void {
this.insertStmt.run(
@@ -472,6 +476,7 @@ export class PostsRepository {
post.title,
post.postUrl ?? null,
post.imageUrl,
post.postCreatedAt ?? null,
post.processedAt
);
}
@@ -501,6 +506,7 @@ export class PostsRepository {
imageUrl: row.image_url as string | null,
imageAnalysis: row.image_analysis as string | null,
generatedMessage: row.generated_message as string | null,
postCreatedAt: (row.post_created_at as number | null) ?? null,
processedAt: row.processed_at as number,
messageSent: Boolean(row.message_sent),
error: row.error as string | null,
@@ -518,6 +524,7 @@ export class PostsRepository {
imageUrl: row.image_url as string | null,
imageAnalysis: row.image_analysis as string | null,
generatedMessage: row.generated_message as string | null,
postCreatedAt: (row.post_created_at as number | null) ?? null,
processedAt: row.processed_at as number,
messageSent: Boolean(row.message_sent),
error: row.error as string | null,
@@ -556,7 +563,7 @@ export class MessagesRepository {
this.getByChatRoomIdStmt = db.prepare(`
SELECT sm.*, pp.subreddit, pp.title AS post_title, pp.post_url, pp.image_url AS post_image_url,
pp.image_analysis AS post_image_analysis
pp.image_analysis AS post_image_analysis, pp.post_created_at AS post_created_at
FROM sent_messages sm
LEFT JOIN processed_posts pp ON sm.account_id = pp.account_id AND sm.post_id = pp.id
WHERE sm.account_id = ? AND sm.chat_room_id = ?
@@ -568,7 +575,7 @@ export class MessagesRepository {
this.getLatestByRecipientStmt = db.prepare(`
SELECT sm.*, pp.subreddit, pp.title AS post_title, pp.post_url, pp.image_url AS post_image_url,
pp.image_analysis AS post_image_analysis
pp.image_analysis AS post_image_analysis, pp.post_created_at AS post_created_at
FROM sent_messages sm
LEFT JOIN processed_posts pp ON sm.account_id = pp.account_id AND sm.post_id = pp.id
WHERE sm.account_id = ? AND sm.recipient = ? COLLATE NOCASE
@@ -578,7 +585,7 @@ export class MessagesRepository {
this.getRecentStmt = db.prepare(`
SELECT sm.*, pp.subreddit, pp.title AS post_title, pp.post_url, pp.image_url AS post_image_url,
pp.image_analysis AS post_image_analysis
pp.image_analysis AS post_image_analysis, pp.post_created_at AS post_created_at
FROM sent_messages sm
LEFT JOIN processed_posts pp ON sm.account_id = pp.account_id AND sm.post_id = pp.id
WHERE sm.account_id = ?
@@ -909,6 +916,7 @@ export class MessagesRepository {
postUrl: (row.post_url as string) || undefined,
postImageUrl: (row.post_image_url as string) || undefined,
postImageAnalysis: (row.post_image_analysis as string) || undefined,
postCreatedAt: (row.post_created_at as number) || undefined,
};
}
}