v1.18.x
barisusakli 9 years ago
parent 041531a2e3
commit f665a1e353

@ -34,7 +34,6 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return app.alertError(err); return app.alertError(err);
} }
data.posts.display_move_tools = data.posts.display_move_tools && index !== 0; data.posts.display_move_tools = data.posts.display_move_tools && index !== 0;
data.postSharing = data.postSharing.filter(function(share) { return share.activated === true; });
templates.parse('partials/topic/post-menu-list', data, function(html) { templates.parse('partials/topic/post-menu-list', data, function(html) {
translator.translate(html, function(html) { translator.translate(html, function(html) {

@ -124,7 +124,7 @@ topicsController.get = function(req, res, callback) {
return callback(); return callback();
} }
topics.modifyPostsByPrivilege(topicData.posts, userPrivileges); topics.modifyPostsByPrivilege(topicData, userPrivileges);
plugins.fireHook('filter:controllers.topic.get', {topicData: topicData, uid: req.uid}, next); plugins.fireHook('filter:controllers.topic.get', {topicData: topicData, uid: req.uid}, next);
}, },

@ -49,7 +49,7 @@ function generateForTopic(req, res, callback) {
return callback(err); return callback(err);
} }
topics.modifyPostsByPrivilege(topicData.posts, userPrivileges); topics.modifyPostsByPrivilege(topicData, userPrivileges);
var description = topicData.posts.length ? topicData.posts[0].content : ''; var description = topicData.posts.length ? topicData.posts[0].content : '';
var image_url = topicData.posts.length ? topicData.posts[0].picture : ''; var image_url = topicData.posts.length ? topicData.posts[0].picture : '';

@ -6,7 +6,13 @@ var async = require('async');
var social = {}; var social = {};
social.postSharing = null;
social.getPostSharing = function(callback) { social.getPostSharing = function(callback) {
if (social.postSharing) {
return callback(null, social.postSharing);
}
var networks = [ var networks = [
{ {
id: "facebook", id: "facebook",
@ -39,20 +45,41 @@ social.getPostSharing = function(callback) {
networks[i].activated = (activated.indexOf(network.id) !== -1); networks[i].activated = (activated.indexOf(network.id) !== -1);
}); });
social.postSharing = networks;
next(null, networks); next(null, networks);
}); });
} }
], callback); ], callback);
}; };
social.setActivePostSharingNetworks = function(networkIDs, callback) { social.getActivePostSharing = function(callback) {
db.delete('social:posts.activated', function(err) { social.getPostSharing(function(err, networks) {
if (!networkIDs.length) { if (err) {
return callback(err); return callback(err);
} }
networks = networks.filter(function(network) {
db.setAdd('social:posts.activated', networkIDs, callback); return network && network.activated;
});
callback(null, networks);
}); });
}; };
social.setActivePostSharingNetworks = function(networkIDs, callback) {
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();
}
], callback);
};
module.exports = social; module.exports = social;

@ -32,7 +32,7 @@ module.exports = function(SocketPosts) {
plugins.fireHook('filter:post.tools', {pid: data.pid, uid: socket.uid, tools: []}, next); plugins.fireHook('filter:post.tools', {pid: data.pid, uid: socket.uid, tools: []}, next);
}, },
postSharing: function(next) { postSharing: function(next) {
social.getPostSharing(next); social.getActivePostSharing(next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {

@ -6,6 +6,7 @@ var topics = require('../../topics');
var privileges = require('../../privileges'); var privileges = require('../../privileges');
var meta = require('../../meta'); var meta = require('../../meta');
var utils = require('../../../public/src/utils'); var utils = require('../../../public/src/utils');
var social = require('../../social');
module.exports = function(SocketTopics) { module.exports = function(SocketTopics) {
@ -68,6 +69,9 @@ module.exports = function(SocketTopics) {
}, },
posts: function(next) { posts: function(next) {
topics.getTopicPosts(data.tid, set, start, stop, socket.uid, reverse, next); topics.getTopicPosts(data.tid, set, start, stop, socket.uid, reverse, next);
},
postSharing: function (next) {
social.getActivePostSharing(next);
} }
}, function(err, topicData) { }, function(err, topicData) {
if (err) { if (err) {
@ -81,7 +85,7 @@ module.exports = function(SocketTopics) {
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1; topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1; topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
topics.modifyPostsByPrivilege(topicData.posts, results.privileges); topics.modifyPostsByPrivilege(topicData, results.privileges);
callback(null, topicData); callback(null, topicData);
}); });
}); });

@ -1,15 +1,16 @@
"use strict"; "use strict";
var async = require('async'), var async = require('async');
_ = require('underscore'), var _ = require('underscore');
db = require('./database'), var db = require('./database');
posts = require('./posts'), var posts = require('./posts');
utils = require('../public/src/utils'), var utils = require('../public/src/utils');
plugins = require('./plugins'), var plugins = require('./plugins');
user = require('./user'), var user = require('./user');
categories = require('./categories'), var categories = require('./categories');
privileges = require('./privileges'); var privileges = require('./privileges');
var social = require('./social');
(function(Topics) { (function(Topics) {
@ -179,7 +180,8 @@ var async = require('async'),
threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', {topic: topicData, uid: uid, tools: []}), threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', {topic: topicData, uid: uid, tools: []}),
tags: async.apply(Topics.getTopicTagsObjects, topicData.tid), tags: async.apply(Topics.getTopicTagsObjects, topicData.tid),
isFollowing: async.apply(Topics.isFollowing, [topicData.tid], uid), isFollowing: async.apply(Topics.isFollowing, [topicData.tid], uid),
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid) bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
postSharing: async.apply(social.getActivePostSharing)
}, next); }, next);
}, },
function (results, next) { function (results, next) {
@ -189,6 +191,7 @@ var async = require('async'),
topicData.tags = results.tags; topicData.tags = results.tags;
topicData.isFollowing = results.isFollowing[0]; topicData.isFollowing = results.isFollowing[0];
topicData.bookmark = results.bookmark; topicData.bookmark = results.bookmark;
topicData.postSharing = results.postSharing;
topicData.unreplied = parseInt(topicData.postcount, 10) === 1; topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.deleted = parseInt(topicData.deleted, 10) === 1; topicData.deleted = parseInt(topicData.deleted, 10) === 1;

@ -1,16 +1,15 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
_ = require('underscore'), var _ = require('underscore');
validator = require('validator'), var validator = require('validator');
db = require('../database'), var db = require('../database');
user = require('../user'), var user = require('../user');
favourites = require('../favourites'), var favourites = require('../favourites');
posts = require('../posts'), var posts = require('../posts');
meta = require('../meta'); var meta = require('../meta');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -138,12 +137,13 @@ module.exports = function(Topics) {
}); });
}; };
Topics.modifyPostsByPrivilege = function(postData, topicPrivileges) { Topics.modifyPostsByPrivilege = function(topicData, topicPrivileges) {
postData.forEach(function(post) { var loggedIn = !!parseInt(topicPrivileges.uid, 10);
topicData.posts.forEach(function(post) {
if (post) { if (post) {
post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost; post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost;
post.display_move_tools = topicPrivileges.isAdminOrMod && post.index !== 0; post.display_move_tools = topicPrivileges.isAdminOrMod && post.index !== 0;
post.display_post_menu = topicPrivileges.isAdminOrMod || post.selfPost || !post.deleted; post.display_post_menu = topicPrivileges.isAdminOrMod || post.selfPost || ((loggedIn || topicData.postSharing.length) && !post.deleted);
post.ip = topicPrivileges.isAdminOrMod ? post.ip : undefined; post.ip = topicPrivileges.isAdminOrMod ? post.ip : undefined;
if (post.deleted && !(topicPrivileges.isAdminOrMod || post.selfPost)) { if (post.deleted && !(topicPrivileges.isAdminOrMod || post.selfPost)) {

Loading…
Cancel
Save