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/social.js

86 lines
1.6 KiB
JavaScript

8 years ago
'use strict';
9 years ago
var plugins = require('./plugins');
var db = require('./database');
var async = require('async');
var social = {};
9 years ago
social.postSharing = null;
social.getPostSharing = function (callback) {
9 years ago
if (social.postSharing) {
return callback(null, social.postSharing);
}
9 years ago
var networks = [
{
8 years ago
id: 'facebook',
name: 'Facebook',
class: 'fa-facebook',
9 years ago
},
{
8 years ago
id: 'twitter',
name: 'Twitter',
class: 'fa-twitter',
9 years ago
},
{
8 years ago
id: 'google',
name: 'Google+',
class: 'fa-google-plus',
},
9 years ago
];
async.waterfall([
function (next) {
9 years ago
plugins.fireHook('filter:social.posts', networks, next);
},
function (networks, next) {
db.getSetMembers('social:posts.activated', function (err, activated) {
9 years ago
if (err) {
return next(err);
}
networks.forEach(function (network, i) {
9 years ago
networks[i].activated = (activated.indexOf(network.id) !== -1);
});
9 years ago
social.postSharing = networks;
9 years ago
next(null, networks);
});
},
9 years ago
], callback);
};
social.getActivePostSharing = function (callback) {
social.getPostSharing(function (err, networks) {
9 years ago
if (err) {
9 years ago
return callback(err);
}
networks = networks.filter(function (network) {
9 years ago
return network && network.activated;
});
callback(null, networks);
9 years ago
});
};
social.setActivePostSharingNetworks = function (networkIDs, callback) {
9 years ago
async.waterfall([
function (next) {
db.delete('social:posts.activated', next);
},
function (next) {
if (!networkIDs.length) {
return next();
}
db.setAdd('social:posts.activated', networkIDs, next);
},
function (next) {
social.postSharing = null;
next();
},
9 years ago
], callback);
};
8 years ago
module.exports = social;