Skip to content

Commit 7ecfbed

Browse files
committed
Hide reactions from guests
1 parent c1417a5 commit 7ecfbed

1 file changed

Lines changed: 69 additions & 63 deletions

File tree

library.js

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -118,76 +118,82 @@ reactions.getPluginConfig = function(config, callback) {
118118
};
119119

120120
reactions.getReactions = function(data, callback) {
121-
async.eachSeries(data.posts, function(post, next) {
122-
123-
async.series({
124-
maximumReactions: function(cb) {
125-
meta.settings.get('reactions', function(err, settings) {
126-
var maximumReactions = settings.maximumReactions || 5;
127-
cb(null, maximumReactions);
128-
});
129-
},
130-
totalReactions: function(cb) {
131-
db.setCount('pid:' + post.pid + ':reactions', cb);
132-
},
133-
reactions: function(cb) {
134-
async.waterfall([
135-
function(callback) {
136-
db.getSetMembers('pid:' + post.pid + ":reactions", function(err, reactions) {
137-
callback(null, reactions);
138-
});
139-
},
140-
function(reactions, callback) {
141-
var reactionData = [];
142-
143-
async.each(reactions, function(reaction, next) {
144-
db.getSetMembers('pid:' + post.pid + ':reaction:' + reaction, function(err, uids) {
145-
user.getUsersFields(uids, ['uid', 'username'], function(err, userdata) {
146-
reactionData.push({reaction, userdata, memberCount: uids.length, reacted: uids.indexOf(data.uid.toString()) >= 0});
147-
next();
148-
});
149-
});
150-
}, function(err) {
151-
callback(null, reactionData);
152-
});
153-
},
154-
function(uidData, callback) {
155-
callback(null, uidData);
156-
}
157-
], function (err, result) {
158-
cb(null, result);
121+
if (data.uid === 0) {
122+
callback(null, data);
123+
} else {
124+
async.eachSeries(data.posts, function(post, next) {
125+
126+
async.series({
127+
maximumReactions: function(cb) {
128+
meta.settings.get('reactions', function(err, settings) {
129+
var maximumReactions = settings.maximumReactions || 5;
130+
cb(null, maximumReactions);
131+
});
132+
},
133+
totalReactions: function(cb) {
134+
db.setCount('pid:' + post.pid + ':reactions', cb);
135+
},
136+
reactions: function(cb) {
137+
async.waterfall([
138+
function(callback) {
139+
db.getSetMembers('pid:' + post.pid + ":reactions", function(err, reactions) {
140+
callback(null, reactions);
141+
});
142+
},
143+
function(reactions, callback) {
144+
var reactionData = [];
145+
146+
async.each(reactions, function(reaction, next) {
147+
db.getSetMembers('pid:' + post.pid + ':reaction:' + reaction, function(err, uids) {
148+
user.getUsersFields(uids, ['uid', 'username'], function(err, userdata) {
149+
reactionData.push({reaction, userdata, memberCount: uids.length, reacted: uids.indexOf(data.uid.toString()) >= 0});
150+
next();
151+
});
152+
});
153+
}, function(err) {
154+
callback(null, reactionData);
155+
});
156+
},
157+
function(uidData, callback) {
158+
callback(null, uidData);
159+
}
160+
], function (err, result) {
161+
cb(null, result);
162+
});
163+
}
164+
}, function(err, results) {
165+
var reactionInfo = '<span class="reactions" component="post/reactions" data-pid="' + post.pid + '">';
166+
var maxReactionsReached = results.totalReactions >= results.maximumReactions ? ' max-reactions': '';
167+
reactionInfo = reactionInfo + '<span class="reaction-add' + maxReactionsReached + '" component="post/reaction/add" data-pid="' + post.pid + '" title="Add reaction"><i class="fa fa-plus-square-o"></i></span>';
168+
169+
results.reactions.forEach(function(reaction, index) {
170+
var usernames = reaction.userdata.map(function(user) {
171+
return user.username
172+
}).join(', ');
173+
174+
var reactionImage = emojiParser.parse(':' + reaction.reaction + ':').replace('title="' + reaction + '"', '');
175+
var reacted = reaction.reacted ? 'reacted' : '';
176+
reactionInfo = reactionInfo + '<span class="reaction ' + reacted + '" component="post/reaction" data-pid="' + post.pid + '" data-reaction="' + reaction.reaction + '" title="' + usernames + '">' + reactionImage + '<span class="reaction-emoji-count" data-count="' + reaction.memberCount + '"></span></span>';
159177
});
160-
}
161-
}, function(err, results) {
162-
var reactionInfo = '<span class="reactions" component="post/reactions" data-pid="' + post.pid + '">';
163-
var maxReactionsReached = results.totalReactions >= results.maximumReactions ? ' max-reactions': '';
164-
reactionInfo = reactionInfo + '<span class="reaction-add' + maxReactionsReached + '" component="post/reaction/add" data-pid="' + post.pid + '" title="Add reaction"><i class="fa fa-plus-square-o"></i></span>';
165-
166-
results.reactions.forEach(function(reaction, index) {
167-
var usernames = reaction.userdata.map(function(user) {
168-
return user.username
169-
}).join(', ');
170178

171-
var reactionImage = emojiParser.parse(':' + reaction.reaction + ':').replace('title="' + reaction + '"', '');
172-
var reacted = reaction.reacted ? 'reacted' : '';
173-
reactionInfo = reactionInfo + '<span class="reaction ' + reacted + '" component="post/reaction" data-pid="' + post.pid + '" data-reaction="' + reaction.reaction + '" title="' + usernames + '">' + reactionImage + '<span class="reaction-emoji-count" data-count="' + reaction.memberCount + '"></span></span>';
179+
post.reactions = reactionInfo + '</span>';
180+
next();
174181
});
175-
176-
post.reactions = reactionInfo + '</span>';
177-
next();
182+
}, function (err) {
183+
if (err) {
184+
console.log(err.message);
185+
}
186+
callback(null, data);
178187
});
179-
}, function (err) {
180-
if (err) {
181-
console.log(err.message);
182-
}
183-
callback(null, data);
184-
});
188+
}
185189
}
186190

187191
reactions.onReply = function(data, callback) {
188-
var reactionInfo = '<span class="reactions" component="post/reactions" data-pid="' + data.pid + '">';
189-
reactionInfo = reactionInfo + '<span class="reaction-add" component="post/reaction/add" data-pid="' + data.pid + '" title="Add reaction"><i class="fa fa-plus-square-o"></i></span>';
190-
data.reactions = reactionInfo + '</span>';
192+
if (data.uid !== 0) {
193+
var reactionInfo = '<span class="reactions" component="post/reactions" data-pid="' + data.pid + '">';
194+
reactionInfo = reactionInfo + '<span class="reaction-add" component="post/reaction/add" data-pid="' + data.pid + '" title="Add reaction"><i class="fa fa-plus-square-o"></i></span>';
195+
data.reactions = reactionInfo + '</span>';
196+
}
191197
callback(null, data);
192198
}
193199

0 commit comments

Comments
 (0)