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);
}
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) {
translator.translate(html, function(html) {

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

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

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

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

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

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

@ -1,16 +1,15 @@
'use strict';
var async = require('async'),
_ = require('underscore'),
validator = require('validator'),
var async = require('async');
var _ = require('underscore');
var validator = require('validator');
db = require('../database'),
user = require('../user'),
favourites = require('../favourites'),
posts = require('../posts'),
meta = require('../meta');
var db = require('../database');
var user = require('../user');
var favourites = require('../favourites');
var posts = require('../posts');
var meta = require('../meta');
module.exports = function(Topics) {
@ -138,12 +137,13 @@ module.exports = function(Topics) {
});
};
Topics.modifyPostsByPrivilege = function(postData, topicPrivileges) {
postData.forEach(function(post) {
Topics.modifyPostsByPrivilege = function(topicData, topicPrivileges) {
var loggedIn = !!parseInt(topicPrivileges.uid, 10);
topicData.posts.forEach(function(post) {
if (post) {
post.display_moderator_tools = topicPrivileges.isAdminOrMod || post.selfPost;
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;
if (post.deleted && !(topicPrivileges.isAdminOrMod || post.selfPost)) {

Loading…
Cancel
Save