mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 11:45:48 +02:00
refactor: move plugin hook methods to plugin.hooks.*
This commit is contained in:
@@ -31,7 +31,7 @@ module.exports = function (User) {
|
||||
User.getUsersCSV = async function () {
|
||||
winston.verbose('[user/getUsersCSV] Compiling User CSV data');
|
||||
|
||||
const data = await plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] });
|
||||
const data = await plugins.hooks.fire('filter:user.csvFields', { fields: ['uid', 'email', 'username'] });
|
||||
let csvContent = data.fields.join(',') + '\n';
|
||||
await batch.processSortedSet('users:joindate', async (uids) => {
|
||||
const usersData = await User.getUsersFields(uids, data.fields);
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = function (User) {
|
||||
ip: userData.ip,
|
||||
hashedPassword: hashedPassword,
|
||||
};
|
||||
const results = await plugins.fireHook('filter:user.addToApprovalQueue', { data: data, userData: userData });
|
||||
const results = await plugins.hooks.fire('filter:user.addToApprovalQueue', { data: data, userData: userData });
|
||||
await db.setObject('registration:queue:name:' + userData.username, results.data);
|
||||
await db.sortedSetAdd('registration:queue', Date.now(), userData.username);
|
||||
await sendNotificationToAdmins(userData.username);
|
||||
@@ -69,7 +69,7 @@ module.exports = function (User) {
|
||||
await User.setUserField(uid, 'password', userData.hashedPassword);
|
||||
await removeFromQueue(username);
|
||||
await markNotificationRead(username);
|
||||
await plugins.fireHook('filter:register.complete', { uid: uid });
|
||||
await plugins.hooks.fire('filter:register.complete', { uid: uid });
|
||||
await emailer.send('registration_accepted', uid, {
|
||||
username: username,
|
||||
subject: '[[email:welcome-to, ' + (meta.config.title || meta.config.browserTitle || 'NodeBB') + ']]',
|
||||
@@ -140,7 +140,7 @@ module.exports = function (User) {
|
||||
*/
|
||||
}));
|
||||
|
||||
const results = await plugins.fireHook('filter:user.getRegistrationQueue', { users: users });
|
||||
const results = await plugins.hooks.fire('filter:user.getRegistrationQueue', { users: users });
|
||||
return results.users;
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ module.exports = function (User) {
|
||||
await User.incrementUserFieldBy(uid, 'blocksCount', 1);
|
||||
User.blocks._cache.del(parseInt(uid, 10));
|
||||
pubsub.publish('user:blocks:cache:del', parseInt(uid, 10));
|
||||
plugins.fireHook('action:user.blocks.add', { uid: uid, targetUid: targetUid });
|
||||
plugins.hooks.fire('action:user.blocks.add', { uid: uid, targetUid: targetUid });
|
||||
};
|
||||
|
||||
User.blocks.remove = async function (targetUid, uid) {
|
||||
@@ -73,7 +73,7 @@ module.exports = function (User) {
|
||||
await User.decrementUserFieldBy(uid, 'blocksCount', 1);
|
||||
User.blocks._cache.del(parseInt(uid, 10));
|
||||
pubsub.publish('user:blocks:cache:del', parseInt(uid, 10));
|
||||
plugins.fireHook('action:user.blocks.remove', { uid: uid, targetUid: targetUid });
|
||||
plugins.hooks.fire('action:user.blocks.remove', { uid: uid, targetUid: targetUid });
|
||||
};
|
||||
|
||||
User.blocks.applyChecks = async function (type, targetUid, uid) {
|
||||
@@ -111,7 +111,7 @@ module.exports = function (User) {
|
||||
set = set.filter(function (item) {
|
||||
return !blockedSet.has(parseInt(isPlain ? item : (item && item[property]), 10));
|
||||
});
|
||||
const data = await plugins.fireHook('filter:user.blocks.filter', { set: set, property: property, uid: uid, blockedSet: blockedSet });
|
||||
const data = await plugins.hooks.fire('filter:user.blocks.filter', { set: set, property: property, uid: uid, blockedSet: blockedSet });
|
||||
|
||||
return data.set;
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@ module.exports = function (User) {
|
||||
userData.userslug = slugify(renamedUsername);
|
||||
}
|
||||
|
||||
const results = await plugins.fireHook('filter:user.create', { user: userData, data: data });
|
||||
const results = await plugins.hooks.fire('filter:user.create', { user: userData, data: data });
|
||||
userData = results.user;
|
||||
|
||||
const uid = await db.incrObjectField('global', 'nextUid');
|
||||
@@ -118,7 +118,7 @@ module.exports = function (User) {
|
||||
if (userNameChanged) {
|
||||
await User.notifications.sendNameChangeNotification(userData.uid, userData.username);
|
||||
}
|
||||
plugins.fireHook('action:user.create', { user: userData, data: data });
|
||||
plugins.hooks.fire('action:user.create', { user: userData, data: data });
|
||||
return userData.uid;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ module.exports = function (User) {
|
||||
|
||||
const uniqueUids = _.uniq(uids).filter(uid => uid > 0);
|
||||
|
||||
const results = await plugins.fireHook('filter:user.whitelistFields', { uids: uids, whitelist: fieldWhitelist.slice() });
|
||||
const results = await plugins.hooks.fire('filter:user.whitelistFields', { uids: uids, whitelist: fieldWhitelist.slice() });
|
||||
if (!fields.length) {
|
||||
fields = results.whitelist;
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ module.exports = function (User) {
|
||||
}
|
||||
|
||||
let users = await db.getObjectsFields(uniqueUids.map(uid => 'user:' + uid), fields);
|
||||
const result = await plugins.fireHook('filter:user.getFields', {
|
||||
const result = await plugins.hooks.fire('filter:user.getFields', {
|
||||
uids: uniqueUids,
|
||||
users: users,
|
||||
fields: fields,
|
||||
@@ -231,7 +231,7 @@ module.exports = function (User) {
|
||||
}
|
||||
}));
|
||||
|
||||
return await plugins.fireHook('filter:users.get', users);
|
||||
return await plugins.hooks.fire('filter:users.get', users);
|
||||
}
|
||||
|
||||
function parseDisplayName(user, uidToSettings) {
|
||||
@@ -289,7 +289,7 @@ module.exports = function (User) {
|
||||
await db.setObject('user:' + uid, data);
|
||||
for (const field in data) {
|
||||
if (data.hasOwnProperty(field)) {
|
||||
plugins.fireHook('action:user.set', { uid: uid, field: field, value: data[field], type: 'set' });
|
||||
plugins.hooks.fire('action:user.set', { uid: uid, field: field, value: data[field], type: 'set' });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -304,7 +304,7 @@ module.exports = function (User) {
|
||||
|
||||
async function incrDecrUserFieldBy(uid, field, value, type) {
|
||||
const newValue = await db.incrObjectFieldBy('user:' + uid, field, value);
|
||||
plugins.fireHook('action:user.set', { uid: uid, field: field, value: newValue, type: type });
|
||||
plugins.hooks.fire('action:user.set', { uid: uid, field: field, value: newValue, type: type });
|
||||
return newValue;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -102,7 +102,7 @@ module.exports = function (User) {
|
||||
throw new Error('[[error:no-user]]');
|
||||
}
|
||||
|
||||
await plugins.fireHook('static:user.delete', { uid: uid });
|
||||
await plugins.hooks.fire('static:user.delete', { uid: uid });
|
||||
await deleteVotes(uid);
|
||||
await deleteChats(uid);
|
||||
await User.auth.revokeAllSessions(uid);
|
||||
|
||||
@@ -87,7 +87,7 @@ Digest.getSubscribers = async function (interval) {
|
||||
batch: 500,
|
||||
});
|
||||
|
||||
const results = await plugins.fireHook('filter:digest.subscribers', {
|
||||
const results = await plugins.hooks.fire('filter:digest.subscribers', {
|
||||
interval: interval,
|
||||
subscribers: subscribers,
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
||||
}
|
||||
await db.set('uid:' + uid + ':confirm:email:sent', 1);
|
||||
await db.pexpireAt('uid:' + uid + ':confirm:email:sent', Date.now() + (emailInterval * 60 * 1000));
|
||||
confirm_code = await plugins.fireHook('filter:user.verify.code', confirm_code);
|
||||
confirm_code = await plugins.hooks.fire('filter:user.verify.code', confirm_code);
|
||||
|
||||
await db.setObject('confirm:' + confirm_code, {
|
||||
email: options.email.toLowerCase(),
|
||||
@@ -79,8 +79,8 @@ UserEmail.sendValidationEmail = async function (uid, options) {
|
||||
uid: uid,
|
||||
};
|
||||
|
||||
if (plugins.hasListeners('action:user.verify')) {
|
||||
plugins.fireHook('action:user.verify', { uid: uid, data: data });
|
||||
if (plugins.hooks.hasListeners('action:user.verify')) {
|
||||
plugins.hooks.fire('action:user.verify', { uid: uid, data: data });
|
||||
} else {
|
||||
await emailer.send(data.template, uid, data);
|
||||
}
|
||||
@@ -101,5 +101,5 @@ UserEmail.confirm = async function (code) {
|
||||
await groups.leave('unverified-users', confirmObj.uid);
|
||||
await db.delete('confirm:' + code);
|
||||
await db.delete('uid:' + confirmObj.uid + ':confirm:email:sent');
|
||||
await plugins.fireHook('action:user.email.confirmed', { uid: confirmObj.uid, email: confirmObj.email });
|
||||
await plugins.hooks.fire('action:user.email.confirmed', { uid: confirmObj.uid, email: confirmObj.email });
|
||||
};
|
||||
|
||||
@@ -72,7 +72,7 @@ module.exports = function (User) {
|
||||
return [];
|
||||
}
|
||||
const uids = await db.getSortedSetRevRange(type + ':' + uid, start, stop);
|
||||
const data = await plugins.fireHook('filter:user.' + type, {
|
||||
const data = await plugins.hooks.fire('filter:user.' + type, {
|
||||
uids: uids,
|
||||
uid: uid,
|
||||
start: start,
|
||||
|
||||
@@ -64,10 +64,10 @@ User.getUsersFromSet = async function (set, uid, start, stop) {
|
||||
};
|
||||
|
||||
User.getUsersWithFields = async function (uids, fields, uid) {
|
||||
let results = await plugins.fireHook('filter:users.addFields', { fields: fields });
|
||||
let results = await plugins.hooks.fire('filter:users.addFields', { fields: fields });
|
||||
results.fields = _.uniq(results.fields);
|
||||
const userData = await User.getUsersFields(uids, results.fields);
|
||||
results = await plugins.fireHook('filter:userlist.get', { users: userData, uid: uid });
|
||||
results = await plugins.hooks.fire('filter:userlist.get', { users: userData, uid: uid });
|
||||
return results.users;
|
||||
};
|
||||
|
||||
@@ -219,7 +219,7 @@ User.getModeratedCids = async function (uid) {
|
||||
};
|
||||
|
||||
User.addInterstitials = function (callback) {
|
||||
plugins.registerHook('core', {
|
||||
plugins.hooks.register('core', {
|
||||
hook: 'filter:register.interstitial',
|
||||
method: [
|
||||
// GDPR information collection/processing consent + email consent
|
||||
@@ -272,7 +272,7 @@ User.addInterstitials = function (callback) {
|
||||
}
|
||||
}
|
||||
|
||||
const termsOfUse = await plugins.fireHook('filter:parse.post', {
|
||||
const termsOfUse = await plugins.hooks.fire('filter:parse.post', {
|
||||
postData: {
|
||||
content: meta.config.termsOfUse || '',
|
||||
},
|
||||
|
||||
@@ -96,7 +96,7 @@ UserNotifications.getNotifications = async function (nids, uid) {
|
||||
|
||||
await deleteUserNids(deletedNids, uid);
|
||||
notificationData = await notifications.merge(notificationData);
|
||||
const result = await plugins.fireHook('filter:user.notifications.getNotifications', {
|
||||
const result = await plugins.hooks.fire('filter:user.notifications.getNotifications', {
|
||||
uid: uid,
|
||||
notifications: notificationData,
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ module.exports = function (User) {
|
||||
}
|
||||
await db.sortedSetAdd('users:online', now, uid);
|
||||
topics.pushUnreadCount(uid);
|
||||
plugins.fireHook('action:user.online', { uid: uid, timestamp: now });
|
||||
plugins.hooks.fire('action:user.online', { uid: uid, timestamp: now });
|
||||
};
|
||||
|
||||
User.isOnline = async function (uid) {
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = function (User) {
|
||||
|
||||
User.getAllowedImageTypes = function () {
|
||||
const allowedTypes = ['image/png', 'image/jpeg', 'image/bmp'];
|
||||
if (plugins.hasListeners('filter:image.isFileTypeAllowed')) {
|
||||
if (plugins.hooks.hasListeners('filter:image.isFileTypeAllowed')) {
|
||||
allowedTypes.push('image/gif');
|
||||
}
|
||||
return allowedTypes;
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = function (User) {
|
||||
}
|
||||
const updateUid = data.uid;
|
||||
|
||||
const result = await plugins.fireHook('filter:user.updateProfile', {
|
||||
const result = await plugins.hooks.fire('filter:user.updateProfile', {
|
||||
uid: uid,
|
||||
data: data,
|
||||
fields: fields,
|
||||
@@ -52,7 +52,7 @@ module.exports = function (User) {
|
||||
await User.setUserField(updateUid, field, data[field]);
|
||||
});
|
||||
|
||||
plugins.fireHook('action:user.updateProfile', {
|
||||
plugins.hooks.fire('action:user.updateProfile', {
|
||||
uid: uid,
|
||||
data: data,
|
||||
fields: fields,
|
||||
@@ -332,6 +332,6 @@ module.exports = function (User) {
|
||||
User.auth.revokeAllSessions(data.uid),
|
||||
]);
|
||||
|
||||
plugins.fireHook('action:password.change', { uid: uid, targetUid: data.uid });
|
||||
plugins.hooks.fire('action:password.change', { uid: uid, targetUid: data.uid });
|
||||
};
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ module.exports = function (User) {
|
||||
}
|
||||
|
||||
uids = await filterAndSortUids(uids, data);
|
||||
const result = await plugins.fireHook('filter:users.search', { uids: uids, uid: uid });
|
||||
const result = await plugins.hooks.fire('filter:users.search', { uids: uids, uid: uid });
|
||||
uids = result.uids;
|
||||
|
||||
const searchResult = {
|
||||
|
||||
@@ -36,7 +36,7 @@ module.exports = function (User) {
|
||||
};
|
||||
|
||||
async function onSettingsLoaded(uid, settings) {
|
||||
const data = await plugins.fireHook('filter:user.getSettings', { uid: uid, settings: settings });
|
||||
const data = await plugins.hooks.fire('filter:user.getSettings', { uid: uid, settings: settings });
|
||||
settings = data.settings;
|
||||
|
||||
const defaultTopicsPerPage = meta.config.topicsPerPage;
|
||||
@@ -101,7 +101,7 @@ module.exports = function (User) {
|
||||
}
|
||||
data.userLang = data.userLang || meta.config.defaultLang;
|
||||
|
||||
plugins.fireHook('action:user.saveSettings', { uid: uid, settings: data });
|
||||
plugins.hooks.fire('action:user.saveSettings', { uid: uid, settings: data });
|
||||
|
||||
const settings = {
|
||||
showemail: data.showemail,
|
||||
@@ -132,7 +132,7 @@ module.exports = function (User) {
|
||||
settings[notificationType] = data[notificationType];
|
||||
}
|
||||
});
|
||||
const result = await plugins.fireHook('filter:user.saveSettings', { settings: settings, data: data });
|
||||
const result = await plugins.hooks.fire('filter:user.saveSettings', { settings: settings, data: data });
|
||||
await db.setObject('user:' + uid + ':settings', result.settings);
|
||||
await User.updateDigestSetting(uid, data.dailyDigestFreq);
|
||||
return await User.getSettings(uid);
|
||||
|
||||
Reference in New Issue
Block a user