Step 5 + Review

This commit is contained in:
Tyler Yust
2026-01-19 20:16:14 -08:00
committed by Peter Steinberger
parent 2cf444be02
commit 1eab8fa9b0
10 changed files with 219 additions and 15 deletions

View File

@@ -11,6 +11,14 @@ export const MESSAGE_ACTION_TARGET_MODE: Record<ChannelMessageActionName, Messag
reactions: "to",
read: "to",
edit: "to",
unsend: "to",
reply: "to",
sendWithEffect: "to",
renameGroup: "to",
addParticipant: "to",
removeParticipant: "to",
leaveGroup: "to",
sendAttachment: "to",
delete: "to",
pin: "to",
unpin: "to",
@@ -45,6 +53,32 @@ export const MESSAGE_ACTION_TARGET_MODE: Record<ChannelMessageActionName, Messag
ban: "none",
};
const ACTION_TARGET_ALIASES: Partial<Record<ChannelMessageActionName, string[]>> = {
unsend: ["messageId"],
renameGroup: ["chatGuid", "chatIdentifier", "chatId"],
addParticipant: ["chatGuid", "chatIdentifier", "chatId"],
removeParticipant: ["chatGuid", "chatIdentifier", "chatId"],
leaveGroup: ["chatGuid", "chatIdentifier", "chatId"],
};
export function actionRequiresTarget(action: ChannelMessageActionName): boolean {
return MESSAGE_ACTION_TARGET_MODE[action] !== "none";
}
export function actionHasTarget(
action: ChannelMessageActionName,
params: Record<string, unknown>,
): boolean {
const to = typeof params.to === "string" ? params.to.trim() : "";
if (to) return true;
const channelId = typeof params.channelId === "string" ? params.channelId.trim() : "";
if (channelId) return true;
const aliases = ACTION_TARGET_ALIASES[action];
if (!aliases) return false;
return aliases.some((alias) => {
const value = params[alias];
if (typeof value === "string") return value.trim().length > 0;
if (typeof value === "number") return Number.isFinite(value);
return false;
});
}