2017-02-18 01:56:23 -07:00
|
|
|
'use strict';
|
2016-02-25 14:05:48 -05:00
|
|
|
|
2021-11-15 18:21:52 -05:00
|
|
|
const _ = require('lodash');
|
2020-10-07 11:47:34 -04:00
|
|
|
const plugins = require('./plugins');
|
|
|
|
|
const db = require('./database');
|
2023-05-31 11:54:48 -04:00
|
|
|
const meta = require('./meta');
|
2016-02-25 14:05:48 -05:00
|
|
|
|
2020-10-07 11:47:34 -04:00
|
|
|
const social = module.exports;
|
2016-02-25 14:05:48 -05:00
|
|
|
|
2016-03-21 17:49:44 +02:00
|
|
|
social.postSharing = null;
|
|
|
|
|
|
2019-07-09 12:46:49 -04:00
|
|
|
social.getPostSharing = async function () {
|
2016-03-21 17:49:44 +02:00
|
|
|
if (social.postSharing) {
|
2021-11-15 18:21:52 -05:00
|
|
|
return _.cloneDeep(social.postSharing);
|
2016-03-21 17:49:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-07 11:47:34 -04:00
|
|
|
let networks = [
|
2016-02-25 14:05:48 -05:00
|
|
|
{
|
2017-02-18 01:56:23 -07:00
|
|
|
id: 'facebook',
|
|
|
|
|
name: 'Facebook',
|
2023-11-15 11:01:30 -05:00
|
|
|
class: 'fa-brands fa-facebook',
|
2016-02-25 14:05:48 -05:00
|
|
|
},
|
|
|
|
|
{
|
2017-02-18 01:56:23 -07:00
|
|
|
id: 'twitter',
|
2023-11-15 11:01:30 -05:00
|
|
|
name: 'X (Twitter)',
|
|
|
|
|
class: 'fa-brands fa-x-twitter',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'whatsapp',
|
|
|
|
|
name: 'Whatsapp',
|
|
|
|
|
class: 'fa-brands fa-whatsapp',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'telegram',
|
|
|
|
|
name: 'Telegram',
|
|
|
|
|
class: 'fa-brands fa-telegram',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'linkedin',
|
|
|
|
|
name: 'LinkedIn',
|
|
|
|
|
class: 'fa-brands fa-linkedin',
|
2016-02-25 14:05:48 -05:00
|
|
|
},
|
|
|
|
|
];
|
2020-11-20 16:06:26 -05:00
|
|
|
networks = await plugins.hooks.fire('filter:social.posts', networks);
|
2021-02-04 00:01:39 -07:00
|
|
|
networks.forEach((network) => {
|
2023-05-31 11:54:48 -04:00
|
|
|
network.activated = parseInt(meta.config[`post-sharing-${network.id}`], 10) === 1;
|
2019-07-09 12:46:49 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
social.postSharing = networks;
|
2021-11-15 18:21:52 -05:00
|
|
|
return _.cloneDeep(networks);
|
2016-02-25 14:05:48 -05:00
|
|
|
};
|
|
|
|
|
|
2019-07-09 12:46:49 -04:00
|
|
|
social.getActivePostSharing = async function () {
|
|
|
|
|
const networks = await social.getPostSharing();
|
|
|
|
|
return networks.filter(network => network && network.activated);
|
2016-02-25 14:05:48 -05:00
|
|
|
};
|
|
|
|
|
|
2019-07-09 12:46:49 -04:00
|
|
|
social.setActivePostSharingNetworks = async function (networkIDs) {
|
2023-05-31 11:54:48 -04:00
|
|
|
// keeping for 1.0.0 upgrade script that uses this function
|
2022-07-20 08:42:08 +07:00
|
|
|
social.postSharing = null;
|
2019-07-09 12:46:49 -04:00
|
|
|
if (!networkIDs.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-05-31 11:54:48 -04:00
|
|
|
const data = {};
|
|
|
|
|
networkIDs.forEach((id) => {
|
|
|
|
|
data[`post-sharing-${id}`] = 1;
|
|
|
|
|
});
|
|
|
|
|
await db.setObject('config', data);
|
2016-03-21 17:49:44 +02:00
|
|
|
};
|
2019-07-09 12:46:49 -04:00
|
|
|
|
|
|
|
|
require('./promisify')(social);
|