Files
NodeBB/src/social.js

85 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-02-25 14:05:48 -05:00
"use strict";
var plugins = require('./plugins');
var db = require('./database');
var async = require('async');
var social = {};
2016-03-21 17:49:44 +02:00
social.postSharing = null;
social.getPostSharing = function (callback) {
2016-03-21 17:49:44 +02:00
if (social.postSharing) {
return callback(null, social.postSharing);
}
2016-02-25 14:05:48 -05:00
var networks = [
{
id: "facebook",
name: "Facebook",
2017-02-17 19:31:21 -07:00
class: "fa-facebook",
2016-02-25 14:05:48 -05:00
},
{
id: "twitter",
name: "Twitter",
2017-02-17 19:31:21 -07:00
class: "fa-twitter",
2016-02-25 14:05:48 -05:00
},
{
id: "google",
name: "Google+",
2017-02-17 19:31:21 -07:00
class: "fa-google-plus",
},
2016-02-25 14:05:48 -05:00
];
async.waterfall([
function (next) {
2016-02-25 14:05:48 -05:00
plugins.fireHook('filter:social.posts', networks, next);
},
function (networks, next) {
db.getSetMembers('social:posts.activated', function (err, activated) {
2016-02-25 14:05:48 -05:00
if (err) {
return next(err);
}
networks.forEach(function (network, i) {
2016-02-25 14:05:48 -05:00
networks[i].activated = (activated.indexOf(network.id) !== -1);
});
2016-03-21 17:49:44 +02:00
social.postSharing = networks;
2016-02-25 14:05:48 -05:00
next(null, networks);
});
2017-02-17 19:31:21 -07:00
},
2016-02-25 14:05:48 -05:00
], callback);
};
social.getActivePostSharing = function (callback) {
social.getPostSharing(function (err, networks) {
2016-03-21 17:49:44 +02:00
if (err) {
2016-02-25 14:05:48 -05:00
return callback(err);
}
networks = networks.filter(function (network) {
2016-03-21 17:49:44 +02:00
return network && network.activated;
});
callback(null, networks);
2016-02-25 14:05:48 -05:00
});
};
social.setActivePostSharingNetworks = function (networkIDs, callback) {
2016-03-21 17:49:44 +02:00
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();
2017-02-17 19:31:21 -07:00
},
2016-03-21 17:49:44 +02:00
], callback);
};
2016-02-25 14:05:48 -05:00
module.exports = social;