Update
This commit is contained in:
1 parent
b780bff850
commit
7b3ea37127
1752 files changed
+1341
-166
No files matched your search
@@ -22,6 +22,7 @@ export interface SentMessageRecord {
|
||||
sentAt: number;
|
||||
gotResponse: boolean;
|
||||
responseCheckedAt: number | null;
|
||||
subreddit?: string;
|
||||
}
|
||||
|
||||
export interface SuccessfulMessageRecord {
|
||||
@@ -123,6 +124,7 @@ export class MessagesRepository {
|
||||
private getUncheckedStmt: Database.Statement;
|
||||
private markResponseStmt: Database.Statement;
|
||||
private markCheckedStmt: Database.Statement;
|
||||
private hasSentToStmt: Database.Statement;
|
||||
|
||||
constructor(private db: Database.Database) {
|
||||
this.insertStmt = db.prepare(`
|
||||
@@ -133,7 +135,11 @@ export class MessagesRepository {
|
||||
this.getByPostIdStmt = db.prepare(`SELECT * FROM sent_messages WHERE post_id = ?`);
|
||||
|
||||
this.getRecentStmt = db.prepare(`
|
||||
SELECT * FROM sent_messages ORDER BY sent_at DESC LIMIT ?
|
||||
SELECT sm.*, pp.subreddit
|
||||
FROM sent_messages sm
|
||||
LEFT JOIN processed_posts pp ON sm.post_id = pp.id
|
||||
ORDER BY sm.sent_at DESC
|
||||
LIMIT ?
|
||||
`);
|
||||
|
||||
this.getUncheckedStmt = db.prepare(`
|
||||
@@ -152,6 +158,10 @@ export class MessagesRepository {
|
||||
this.markCheckedStmt = db.prepare(`
|
||||
UPDATE sent_messages SET response_checked_at = ? WHERE id = ?
|
||||
`);
|
||||
|
||||
this.hasSentToStmt = db.prepare(`
|
||||
SELECT 1 FROM sent_messages WHERE recipient = ? LIMIT 1
|
||||
`);
|
||||
}
|
||||
|
||||
insert(message: {
|
||||
@@ -198,6 +208,10 @@ export class MessagesRepository {
|
||||
this.markCheckedStmt.run(Date.now(), messageId);
|
||||
}
|
||||
|
||||
hasSentTo(recipient: string): boolean {
|
||||
return this.hasSentToStmt.get(recipient) !== undefined;
|
||||
}
|
||||
|
||||
private mapRow(row: Record<string, unknown>): SentMessageRecord {
|
||||
return {
|
||||
id: row.id as number,
|
||||
@@ -208,6 +222,7 @@ export class MessagesRepository {
|
||||
sentAt: row.sent_at as number,
|
||||
gotResponse: Boolean(row.got_response),
|
||||
responseCheckedAt: row.response_checked_at as number | null,
|
||||
subreddit: (row.subreddit as string) || undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -216,6 +231,7 @@ export class SuccessfulMessagesRepository {
|
||||
private insertStmt: Database.Statement;
|
||||
private getRecentStmt: Database.Statement;
|
||||
private countStmt: Database.Statement;
|
||||
private existsByMessageStmt: Database.Statement;
|
||||
|
||||
constructor(private db: Database.Database) {
|
||||
this.insertStmt = db.prepare(`
|
||||
@@ -228,10 +244,14 @@ export class SuccessfulMessagesRepository {
|
||||
`);
|
||||
|
||||
this.countStmt = db.prepare(`SELECT COUNT(*) as count FROM successful_messages`);
|
||||
|
||||
this.existsByMessageStmt = db.prepare(`
|
||||
SELECT 1 FROM successful_messages WHERE original_message = ? LIMIT 1
|
||||
`);
|
||||
}
|
||||
|
||||
insert(data: {
|
||||
sentMessageId: number;
|
||||
sentMessageId: number | null;
|
||||
originalMessage: string;
|
||||
imageAnalysis: string | null;
|
||||
postTitle: string | null;
|
||||
@@ -247,6 +267,10 @@ export class SuccessfulMessagesRepository {
|
||||
);
|
||||
}
|
||||
|
||||
existsByMessage(originalMessage: string): boolean {
|
||||
return this.existsByMessageStmt.get(originalMessage) !== undefined;
|
||||
}
|
||||
|
||||
getRecent(limit: number = 5): SuccessfulMessageRecord[] {
|
||||
const rows = this.getRecentStmt.all(limit) as Record<string, unknown>[];
|
||||
return rows.map((row) => ({
|
||||
|
||||
Reference in new issue
Block a user