You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/topics/follow.js

70 lines
1.7 KiB
JavaScript

'use strict';
var async = require('async'),
nconf = require('nconf'),
db = require('../database'),
user = require('../user'),
11 years ago
posts = require('../posts'),
postTools = require('../postTools'),
notifications = require('../notifications');
module.exports = function(Topics) {
Topics.isFollowing = function(tid, uid, callback) {
db.isSetMember('tid:' + tid + ':followers', uid, callback);
};
Topics.getFollowers = function(tid, callback) {
db.getSetMembers('tid:' + tid + ':followers', callback);
};
Topics.notifyFollowers = function(tid, pid, exceptUid) {
11 years ago
Topics.getFollowers(tid, function(err, followers) {
if (err || !Array.isArray(followers) || !followers.length) {
return;
}
11 years ago
var index = followers.indexOf(exceptUid.toString());
if (index !== -1) {
followers.splice(index, 1);
}
if (!followers.length) {
return;
}
11 years ago
async.parallel({
11 years ago
title: async.apply(Topics.getTopicField, tid, 'title'),
11 years ago
username: async.apply(user.getUserField, exceptUid, 'username'),
postContent: function(next) {
async.waterfall([
async.apply(posts.getPostField, pid, 'content'),
function(content, next) {
postTools.parse(content, next);
}
], next);
}
}, function(err, results) {
if (err) {
return;
}
11 years ago
notifications.create({
11 years ago
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.title + ']]',
11 years ago
bodyLong: results.postContent,
11 years ago
pid: pid,
nid: 'topic:' + tid + ':uid:' + exceptUid,
11 years ago
tid: tid,
from: exceptUid
}, function(err, notification) {
if (!err && notification) {
notifications.push(notification, followers);
11 years ago
}
});
});
});
};
};