|
|
|
@ -2,7 +2,9 @@
|
|
|
|
|
|
|
|
|
|
const user = require('../../user');
|
|
|
|
|
const groups = require('../../groups');
|
|
|
|
|
const plugins = require('../../plugins');
|
|
|
|
|
const privileges = require('../../privileges');
|
|
|
|
|
const notifications = require('../../notifications');
|
|
|
|
|
const meta = require('../../meta');
|
|
|
|
|
const events = require('../../events');
|
|
|
|
|
const helpers = require('../helpers');
|
|
|
|
@ -119,3 +121,37 @@ Users.changePassword = async (req, res) => {
|
|
|
|
|
|
|
|
|
|
helpers.formatApiResponse(200, res);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Users.follow = async (req, res) => {
|
|
|
|
|
await user.follow(req.user.uid, req.params.uid);
|
|
|
|
|
plugins.fireHook('action:user.follow', {
|
|
|
|
|
fromUid: req.user.uid,
|
|
|
|
|
toUid: req.params.uid,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const userData = await user.getUserFields(req.user.uid, ['username', 'userslug']);
|
|
|
|
|
const notifObj = await notifications.create({
|
|
|
|
|
type: 'follow',
|
|
|
|
|
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
|
|
|
|
|
nid: 'follow:' + req.params.uid + ':uid:' + req.user.uid,
|
|
|
|
|
from: req.user.uid,
|
|
|
|
|
path: '/uid/' + req.params.uid + '/followers',
|
|
|
|
|
mergeId: 'notifications:user_started_following_you',
|
|
|
|
|
});
|
|
|
|
|
if (!notifObj) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
notifObj.user = userData;
|
|
|
|
|
await notifications.push(notifObj, [req.params.uid]);
|
|
|
|
|
|
|
|
|
|
helpers.formatApiResponse(200, res);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Users.unfollow = async (req, res) => {
|
|
|
|
|
await user.unfollow(req.user.uid, req.params.uid);
|
|
|
|
|
plugins.fireHook('action:user.unfollow', {
|
|
|
|
|
fromUid: req.user.uid,
|
|
|
|
|
toUid: req.params.uid,
|
|
|
|
|
});
|
|
|
|
|
helpers.formatApiResponse(200, res);
|
|
|
|
|
};
|
|
|
|
|