mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 01:56:12 +01:00
refactor: change password/user follow to use api lib
This commit is contained in:
@@ -5,9 +5,9 @@ const async = require('async');
|
||||
const util = require('util');
|
||||
const sleep = util.promisify(setTimeout);
|
||||
|
||||
const api = require('../api');
|
||||
const user = require('../user');
|
||||
const topics = require('../topics');
|
||||
const notifications = require('../notifications');
|
||||
const messaging = require('../messaging');
|
||||
const plugins = require('../plugins');
|
||||
const meta = require('../meta');
|
||||
@@ -159,45 +159,14 @@ SocketUser.isFollowing = async function (socket, data) {
|
||||
|
||||
SocketUser.follow = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'POST /api/v3/users/follow');
|
||||
|
||||
if (!socket.uid || !data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
await toggleFollow('follow', socket.uid, data.uid);
|
||||
const userData = await user.getUserFields(socket.uid, ['username', 'userslug']);
|
||||
const notifObj = await notifications.create({
|
||||
type: 'follow',
|
||||
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
|
||||
nid: 'follow:' + data.uid + ':uid:' + socket.uid,
|
||||
from: socket.uid,
|
||||
path: '/uid/' + data.uid + '/followers',
|
||||
mergeId: 'notifications:user_started_following_you',
|
||||
});
|
||||
if (!notifObj) {
|
||||
return;
|
||||
}
|
||||
notifObj.user = userData;
|
||||
await notifications.push(notifObj, [data.uid]);
|
||||
await api.users.follow(socket, data);
|
||||
};
|
||||
|
||||
SocketUser.unfollow = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'DELETE /api/v3/users/unfollow');
|
||||
|
||||
if (!socket.uid || !data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
await toggleFollow('unfollow', socket.uid, data.uid);
|
||||
await api.users.unfollow(socket, data);
|
||||
};
|
||||
|
||||
async function toggleFollow(method, uid, theiruid) {
|
||||
await user[method](uid, theiruid);
|
||||
plugins.fireHook('action:user.' + method, {
|
||||
fromUid: uid,
|
||||
toUid: theiruid,
|
||||
});
|
||||
}
|
||||
|
||||
SocketUser.saveSettings = async function (socket, data) {
|
||||
if (!socket.uid || !data || !data.settings) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
|
||||
Reference in New Issue
Block a user