Fix cross-account candidate delivery
This commit is contained in:
1 parent
df35648920
commit
deaf86c364
2 files changed
+64
No files matched your search
@@ -52,6 +52,25 @@ export interface ConcreteRuntimeFactoryOptions {
|
||||
isBotRunning?: () => boolean;
|
||||
}
|
||||
|
||||
export function materializePreparedPostForAccount(
|
||||
resources: Pick<RedditAccountRuntimeResources, 'postsRepo' | 'redditApi'>,
|
||||
processed: ProcessedPost,
|
||||
now: number = Date.now(),
|
||||
): void {
|
||||
const { post } = processed;
|
||||
resources.postsRepo.insertIfAbsent({
|
||||
id: post.id,
|
||||
subreddit: post.subreddit,
|
||||
author: post.author,
|
||||
title: post.title,
|
||||
postUrl: resources.redditApi.getPostUrl(post),
|
||||
imageUrl: processed.sourceType === 'image' ? resources.redditApi.getImageUrl(post) : null,
|
||||
postCreatedAt: post.created_utc * 1_000,
|
||||
processedAt: now,
|
||||
});
|
||||
resources.postsRepo.updateAnalysis(post.id, processed.imageAnalysis, processed.generatedMessage);
|
||||
}
|
||||
|
||||
export function createConcreteRedditAccountRuntimeFactory(
|
||||
options: ConcreteRuntimeFactoryOptions,
|
||||
): RedditAccountRuntimeFactory {
|
||||
@@ -326,6 +345,13 @@ class AccountRuntimeLoop {
|
||||
if (signal?.aborted) {
|
||||
return { status: 'retryable', reason: 'Delivery interrupted by shutdown', retryAt: Date.now() + 5_000 };
|
||||
}
|
||||
|
||||
// Preparation may have been performed by a different authenticated
|
||||
// scanner. Sent messages are account-scoped and reference that account's
|
||||
// processed-post row, so materialise the prepared candidate locally before
|
||||
// performing the irreversible remote chat creation.
|
||||
materializePreparedPostForAccount(this.resources, processed);
|
||||
|
||||
return rateLimiter.throttle(async (): Promise<PreparedDeliveryResult> => {
|
||||
if (this.config.browser.dryRun) {
|
||||
const reason = 'Dry run: message prepared but not sent';
|
||||
|
||||
Reference in new issue
Block a user