refactor: reuse ack reaction helper for whatsapp
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
export type AckReactionScope = "all" | "direct" | "group-all" | "group-mentions" | "off" | "none";
|
||||
|
||||
export type WhatsAppAckReactionMode = "always" | "mentions" | "never";
|
||||
|
||||
export type AckReactionGateParams = {
|
||||
scope: AckReactionScope | undefined;
|
||||
isDirect: boolean;
|
||||
@@ -25,3 +27,29 @@ export function shouldAckReaction(params: AckReactionGateParams): boolean {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function shouldAckReactionForWhatsApp(params: {
|
||||
emoji: string;
|
||||
isDirect: boolean;
|
||||
isGroup: boolean;
|
||||
directEnabled: boolean;
|
||||
groupMode: WhatsAppAckReactionMode;
|
||||
wasMentioned: boolean;
|
||||
groupActivated: boolean;
|
||||
}): boolean {
|
||||
if (!params.emoji) return false;
|
||||
if (params.isDirect) return params.directEnabled;
|
||||
if (!params.isGroup) return false;
|
||||
if (params.groupMode === "never") return false;
|
||||
if (params.groupMode === "always") return true;
|
||||
return shouldAckReaction({
|
||||
scope: "group-mentions",
|
||||
isDirect: false,
|
||||
isGroup: true,
|
||||
isMentionableGroup: true,
|
||||
requireMention: true,
|
||||
canDetectMention: true,
|
||||
effectiveWasMentioned: params.wasMentioned,
|
||||
shouldBypassMention: params.groupActivated,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user