refactor: move plugin hook methods to plugin.hooks.*

This commit is contained in:
Julian Lam
2020-11-20 16:06:26 -05:00
parent 3b1c03ed50
commit 6e2da9966e
136 changed files with 550 additions and 541 deletions

View File

@@ -54,7 +54,7 @@ Messaging.getMessages = async (params) => {
};
async function canGet(hook, callerUid, uid) {
const data = await plugins.fireHook(hook, {
const data = await plugins.hooks.fire(hook, {
callerUid: callerUid,
uid: uid,
canGet: parseInt(callerUid, 10) === parseInt(uid, 10),
@@ -64,7 +64,7 @@ async function canGet(hook, callerUid, uid) {
}
Messaging.parse = async (message, fromuid, uid, roomId, isNew) => {
const parsed = await plugins.fireHook('filter:parse.raw', message);
const parsed = await plugins.hooks.fire('filter:parse.raw', message);
let messageData = {
message: message,
parsed: parsed,
@@ -75,7 +75,7 @@ Messaging.parse = async (message, fromuid, uid, roomId, isNew) => {
parsedMessage: parsed,
};
messageData = await plugins.fireHook('filter:messaging.parse', messageData);
messageData = await plugins.hooks.fire('filter:messaging.parse', messageData);
return messageData ? messageData.parsedMessage : '';
};
@@ -129,7 +129,7 @@ Messaging.getRecentChats = async (callerUid, uid, start, stop) => {
results.roomData = results.roomData.filter(Boolean);
const ref = { rooms: results.roomData, nextStart: stop + 1 };
return await plugins.fireHook('filter:messaging.getRecentChats', {
return await plugins.hooks.fire('filter:messaging.getRecentChats', {
rooms: ref.rooms,
nextStart: ref.nextStart,
uid: uid,
@@ -160,7 +160,7 @@ Messaging.getTeaser = async (uid, roomId) => {
teaser.content = validator.escape(String(teaser.content));
}
const payload = await plugins.fireHook('filter:messaging.getTeaser', { teaser: teaser });
const payload = await plugins.hooks.fire('filter:messaging.getTeaser', { teaser: teaser });
return payload.teaser;
};
@@ -222,7 +222,7 @@ Messaging.canMessageUser = async (uid, toUid) => {
throw new Error('[[error:chat-restricted]]');
}
await plugins.fireHook('static:messaging.canMessageUser', {
await plugins.hooks.fire('static:messaging.canMessageUser', {
uid: uid,
toUid: toUid,
});
@@ -247,7 +247,7 @@ Messaging.canMessageRoom = async (uid, roomId) => {
throw new Error('[[error:no-privileges]]');
}
await plugins.fireHook('static:messaging.canMessageRoom', {
await plugins.hooks.fire('static:messaging.canMessageRoom', {
uid: uid,
roomId: roomId,
});