From 00a68a954895b450933e738058b9b8f6c225333a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 2 Mar 2021 10:08:07 -0500 Subject: [PATCH] feat: add additional flag hooks [breaking] `action:flags.create` on initial flag creation `action:flags.notify` on notification to admins and moderators `action:flags.addReport` on flag report addition (called during initial flag create, too) --- src/flags.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/flags.js b/src/flags.js index 60e3654040..3a8e88b3bd 100644 --- a/src/flags.js +++ b/src/flags.js @@ -443,7 +443,10 @@ Flags.create = async function (type, id, uid, reason, timestamp) { Flags.update(flagId, uid, { state: 'open' }); } - return await Flags.get(flagId); + const flagObj = await Flags.get(flagId); + + plugins.hooks.fire('action:flags.create', { flag: flagObj }); + return flagObj; }; Flags.getReports = async function (flagId) { @@ -474,6 +477,8 @@ Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) { ['flags:hash', flagId, [type, id, uid].join(':')], ]); + + plugins.fireHook('action:flags.addReport', { flagId, type, id, uid, reason, timestamp }); }; Flags.exists = async function (type, id, uid) { @@ -743,9 +748,11 @@ Flags.notify = async function (flagObj, uid) { throw new Error('[[error:invalid-data]]'); } - plugins.hooks.fire('action:flags.create', { + plugins.hooks.fire('action:flags.notify', { flag: flagObj, - uid: uid, + notification: notifObj, + from: uid, + to: uids, }); uids = uids.filter(_uid => parseInt(_uid, 10) !== parseInt(uid, 10)); await notifications.push(notifObj, uids);