Files
NodeBB/src/social.js

83 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
2016-02-25 14:05:48 -05:00
var async = require('async');
2016-02-25 14:05:48 -05:00
var plugins = require('./plugins');
var db = require('./database');
2017-05-23 20:43:09 -04:00
var social = module.exports;
2016-02-25 14:05:48 -05:00
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 = [
{
2017-02-18 01:56:23 -07:00
id: 'facebook',
name: 'Facebook',
class: 'fa-facebook',
2016-02-25 14:05:48 -05:00
},
{
2017-02-18 01:56:23 -07:00
id: 'twitter',
name: 'Twitter',
class: 'fa-twitter',
2016-02-25 14:05:48 -05:00
},
{
2017-02-18 01:56:23 -07:00
id: 'google',
name: 'Google+',
class: 'fa-google-plus',
2017-02-17 19:31:21 -07:00
},
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) {
2017-05-23 20:43:09 -04:00
db.getSetMembers('social:posts.activated', next);
},
function (activated, next) {
networks.forEach(function (network) {
network.activated = activated.includes(network.id);
2016-02-25 14:05:48 -05:00
});
2017-05-23 20:43:09 -04:00
social.postSharing = networks;
next(null, networks);
2017-02-17 19:31:21 -07:00
},
2016-02-25 14:05:48 -05:00
], callback);
};
social.getActivePostSharing = function (callback) {
2017-05-23 20:43:09 -04:00
async.waterfall([
function (next) {
social.getPostSharing(next);
},
function (networks, next) {
networks = networks.filter(function (network) {
return network && network.activated;
});
next(null, networks);
},
], callback);
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);
};