mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-20 00:31:35 +02:00
refactor: move plugin hook methods to plugin.hooks.*
This commit is contained in:
@@ -40,7 +40,7 @@ module.exports = function (Groups) {
|
||||
disableLeave: disableLeave,
|
||||
};
|
||||
|
||||
await plugins.fireHook('filter:group.create', { group: groupData, data: data });
|
||||
await plugins.hooks.fire('filter:group.create', { group: groupData, data: data });
|
||||
|
||||
await db.sortedSetAdd('groups:createtime', groupData.createtime, groupData.name);
|
||||
await db.setObject('group:' + groupData.name, groupData);
|
||||
@@ -61,7 +61,7 @@ module.exports = function (Groups) {
|
||||
await db.setObjectField('groupslug:groupname', groupData.slug, groupData.name);
|
||||
|
||||
groupData = await Groups.getGroupData(groupData.name);
|
||||
plugins.fireHook('action:group.create', { group: groupData });
|
||||
plugins.hooks.fire('action:group.create', { group: groupData });
|
||||
return groupData;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ module.exports = function (Groups) {
|
||||
|
||||
groupData.forEach(group => modifyGroup(group, fields));
|
||||
|
||||
const results = await plugins.fireHook('filter:groups.get', { groups: groupData });
|
||||
const results = await plugins.hooks.fire('filter:groups.get', { groups: groupData });
|
||||
return results.groups;
|
||||
};
|
||||
|
||||
@@ -61,7 +61,7 @@ module.exports = function (Groups) {
|
||||
|
||||
Groups.setGroupField = async function (groupName, field, value) {
|
||||
await db.setObjectField('group:' + groupName, field, value);
|
||||
plugins.fireHook('action:group.set', { field: field, value: value, type: 'set' });
|
||||
plugins.hooks.fire('action:group.set', { field: field, value: value, type: 'set' });
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ module.exports = function (Groups) {
|
||||
removeGroupsFromPrivilegeGroups(groupNames),
|
||||
]);
|
||||
Groups.cache.reset();
|
||||
plugins.fireHook('action:groups.destroy', { groups: groupsData });
|
||||
plugins.hooks.fire('action:groups.destroy', { groups: groupsData });
|
||||
};
|
||||
|
||||
async function removeGroupsFromPrivilegeGroups(groupNames) {
|
||||
|
||||
@@ -135,7 +135,7 @@ Groups.get = async function (groupName, options) {
|
||||
if (!groupData) {
|
||||
return null;
|
||||
}
|
||||
const descriptionParsed = await plugins.fireHook('filter:parse.raw', groupData.description);
|
||||
const descriptionParsed = await plugins.hooks.fire('filter:parse.raw', groupData.description);
|
||||
groupData.descriptionParsed = descriptionParsed;
|
||||
groupData.categories = selectCategories.map((category) => {
|
||||
category.selected = groupData.memberPostCids.includes(category.cid);
|
||||
@@ -149,7 +149,7 @@ Groups.get = async function (groupName, options) {
|
||||
groupData.isPending = isPending;
|
||||
groupData.isInvited = isInvited;
|
||||
groupData.isOwner = isOwner;
|
||||
const results = await plugins.fireHook('filter:group.get', { group: groupData });
|
||||
const results = await plugins.hooks.fire('filter:group.get', { group: groupData });
|
||||
return results.group;
|
||||
};
|
||||
|
||||
@@ -194,7 +194,7 @@ Groups.getOwnersAndMembers = async function (groupName, uid, start, stop) {
|
||||
}
|
||||
}
|
||||
returnUsers = countToReturn > 0 ? returnUsers.slice(0, countToReturn) : returnUsers;
|
||||
const result = await plugins.fireHook('filter:group.getOwnersAndMembers', {
|
||||
const result = await plugins.hooks.fire('filter:group.getOwnersAndMembers', {
|
||||
users: returnUsers,
|
||||
uid: uid,
|
||||
start: start,
|
||||
|
||||
@@ -83,7 +83,7 @@ module.exports = function (Groups) {
|
||||
const set = type === 'invite' ? 'group:' + groupName + ':invited' : 'group:' + groupName + ':pending';
|
||||
await db.setAdd(set, uids);
|
||||
const hookName = type === 'invite' ? 'action:group.inviteMember' : 'action:group.requestMembership';
|
||||
plugins.fireHook(hookName, {
|
||||
plugins.hooks.fire(hookName, {
|
||||
groupName: groupName,
|
||||
uids: uids,
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ module.exports = function (Groups) {
|
||||
|
||||
await setGroupTitleIfNotSet(groupsToJoin, uid);
|
||||
|
||||
plugins.fireHook('action:group.join', {
|
||||
plugins.hooks.fire('action:group.join', {
|
||||
groupNames: groupsToJoin,
|
||||
uid: uid,
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ module.exports = function (Groups) {
|
||||
|
||||
await clearGroupTitleIfSet(groupsToLeave, uid);
|
||||
|
||||
plugins.fireHook('action:group.leave', {
|
||||
plugins.hooks.fire('action:group.leave', {
|
||||
groupNames: groupsToLeave,
|
||||
uid: uid,
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = function (Groups) {
|
||||
Groups.ownership.grant = async function (toUid, groupName) {
|
||||
// Note: No ownership checking is done here on purpose!
|
||||
await db.setAdd('group:' + groupName + ':owners', toUid);
|
||||
plugins.fireHook('action:group.grantOwnership', { uid: toUid, groupName: groupName });
|
||||
plugins.hooks.fire('action:group.grantOwnership', { uid: toUid, groupName: groupName });
|
||||
};
|
||||
|
||||
Groups.ownership.rescind = async function (toUid, groupName) {
|
||||
@@ -35,6 +35,6 @@ module.exports = function (Groups) {
|
||||
throw new Error('[[error:group-needs-owner]]');
|
||||
}
|
||||
await db.setRemove('group:' + groupName + ':owners', toUid);
|
||||
plugins.fireHook('action:group.rescindOwnership', { uid: toUid, groupName: groupName });
|
||||
plugins.hooks.fire('action:group.rescindOwnership', { uid: toUid, groupName: groupName });
|
||||
};
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ module.exports = function (Groups) {
|
||||
throw new Error('[[error:no-group]]');
|
||||
}
|
||||
|
||||
({ values } = await plugins.fireHook('filter:group.update', {
|
||||
({ values } = await plugins.hooks.fire('filter:group.update', {
|
||||
groupName: groupName,
|
||||
values: values,
|
||||
}));
|
||||
@@ -75,7 +75,7 @@ module.exports = function (Groups) {
|
||||
await db.setObject('group:' + groupName, payload);
|
||||
await Groups.renameGroup(groupName, values.name);
|
||||
|
||||
plugins.fireHook('action:group.update', {
|
||||
plugins.hooks.fire('action:group.update', {
|
||||
name: groupName,
|
||||
values: values,
|
||||
});
|
||||
@@ -199,7 +199,7 @@ module.exports = function (Groups) {
|
||||
await renameGroupsMember(['groups:createtime', 'groups:visible:createtime', 'groups:visible:memberCount'], oldName, newName);
|
||||
await renameGroupsMember(['groups:visible:name'], oldName.toLowerCase() + ':' + oldName, newName.toLowerCase() + ':' + newName);
|
||||
|
||||
plugins.fireHook('action:group.rename', {
|
||||
plugins.hooks.fire('action:group.rename', {
|
||||
old: oldName,
|
||||
new: newName,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user