feat(worker): handleStarReaction returns ApprovalResult with indexDoc

This commit is contained in:
2026-05-27 23:56:14 +05:30
parent 1d6e1fb4da
commit 6f71e5aee9
2 changed files with 92 additions and 110 deletions
+21 -6
View File
@@ -1,10 +1,15 @@
import { NormalizedReaction, ForwardJobData } from '@tower/types';
import { NormalizedReaction, ForwardJobData, IndexJobData } from '@tower/types';
export interface ApprovalResult {
forwardJobs: ForwardJobData[];
indexDoc: IndexJobData;
}
export async function handleStarReaction(
reaction: NormalizedReaction,
adminJids: string[],
prisma: any,
): Promise<ForwardJobData[] | null> {
): Promise<ApprovalResult | null> {
if (reaction.emoji !== '⭐') return null;
if (!adminJids.includes(reaction.reactorJid)) return null;
@@ -36,7 +41,7 @@ export async function handleStarReaction(
where: { id: message.id, status: 'PENDING' },
data: { status: 'APPROVED' },
});
if (updated.count === 0) return; // another admin approved first — idempotent
if (updated.count === 0) return;
approved = true;
await tx.approval.create({
data: {
@@ -49,7 +54,7 @@ export async function handleStarReaction(
if (!approved) return null;
const jobs: ForwardJobData[] = message.sourceGroup.syncRoutesFrom
const forwardJobs: ForwardJobData[] = message.sourceGroup.syncRoutesFrom
.filter((route: any) => route.targetGroup != null)
.map((route: any) => ({
messageId: message.id,
@@ -57,9 +62,19 @@ export async function handleStarReaction(
sourceGroupName: message.sourceGroup.name,
senderName: message.senderName ?? undefined,
toGroupJid: route.targetGroup.platformId,
// fallback: use the account that received the reaction when target group has no assigned account
fromAccountId: route.targetGroup.accountId ?? reaction.accountId,
}));
return jobs;
const indexDoc: IndexJobData = {
messageId: message.id,
content: message.content,
senderName: message.senderName ?? null,
sourceGroupId: message.sourceGroupId,
sourceGroupName: message.sourceGroup.name,
tags: message.tags,
platform: message.platform,
approvedAt: new Date().toISOString(),
};
return { forwardJobs, indexDoc };
}