Skip to content

Commit

Permalink
Used all reactions - add inline and PR check(still problem with PR)
Browse files Browse the repository at this point in the history
Can't distinguish between when trying to eliminate self reactions.

Also granting to creator is not set yet
  • Loading branch information
dunaevsky authored and thatkookooguy committed Feb 25, 2017
1 parent be50b3b commit c6c1ea5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 37 deletions.
23 changes: 23 additions & 0 deletions achievements/template.achievement.js
@@ -0,0 +1,23 @@


//var template = {
// name: ,
// check: function(pullRequest, shall) {
// if (...) {
//
// var achievement = {
// / avatar : '',
// name: '',
// short: '',
// description: '',
// relatedPullRequest: pullRequest._id
// };

//shall.grant(pullRequest.creator.username, achievement);
// }
// }
//};



//module.exports = template;
89 changes: 52 additions & 37 deletions achievements/usedAllReactionsInComment.achievement.js
Expand Up @@ -6,49 +6,64 @@ var console = process.console;
var usedAllReactionsInComment = {
name: 'Gladiator',
check: function(pullRequest, shall) {
if (!_.isEmpty(pullRequest.comments)){
var topComments = commentsWithAllReactions(pullRequest.comments); //array of comments with all reactions in them
}

if ( !_.isEmpty(topComments) ) {

var achievement = {
avatar : 'images/achievements/gladiator.achievement.gif',
name: 'Gladiator',
short: 'Are You Not Entertained?',
description: 'You got all the reactions to your comment. You make everybody feel.',
relatedPullRequest: pullRequest._id
};
var topComments = objectsWithAllReactions(pullRequest); //array of comments/inline/pr with all reactions in them
if ( !_.isEmpty(topComments) ) {
var achievement = {
avatar : 'images/achievements/gladiator.achievement.gif',
name: 'Gladiator',
short: 'Are You Not Entertained?',
description: 'You got all the reactions to your comment. You make everybody feel.',
relatedPullRequest: pullRequest._id
};

_.forEach(topComments, function(comment) { //foreach comment that succeded give acheivemnt to author
shall.grant(comment.author.username, achievement);
});
}
_.forEach(topComments, function(comment) { //foreach comment that succeded give acheivemnt to author
shall.grant(comment.author.username, achievement);
});
}
}
};


function commentsWithAllReactions(comments) {
console.log("I'm inside: commentsWithAllReactions");
var allReactions = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray'];
console.log("here are all reactions: " + allReactions);
var topComments =[];

_.forEach(comments, function(comment) {//iterate over comments
if(!_.isEmpty(comment.reactions)){//if there are reactions
var localReactions = [];

_.forEach(comment.reactions, function(reaction){//if (comment has all reactions)
if (reaction.user.username != comment.author.username) { //didn't react to self
localReactions.push(reaction.reaction);
}
console.log("localReactions after run:" +localReactions);
});
if (_.difference(allReactions, localReactions).length === 0) {//all reactions used in this comment
topComments.push(comment); //add comment to topComments
function appendIfHasAllReactions (topComments, comment){
if(!_.isEmpty(comment.reactions)){//if there are reactions
var allReactions = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray'];
var localReactions = [];
console.log("I'm inside: appendIfHasAllReactions");
_.forEach(comment.reactions, function(reaction){//colect reactions
if (reaction.user.username != comment.author.username) { //didn't react to self
localReactions.push(reaction.reaction);
}
console.log("localReactions after run:" +localReactions);
});
if (_.difference(allReactions, localReactions).length === 0) {//all reactions used in this comment
topComments.push(comment); //add comment to topComments
}
});
}
}

function commentsWithAllReactions(pullRequest) {
console.log("I'm inside: commentsWithAllReactions");

var comments = pullRequest.comments;
var inlineComments = pullRequest.inlineComments
var topComments =[]; //objects with all reactions are saved here (PR/comment/inline)

//////////////If PR////////////////////////////
appendIfHasAllReactions(topComments, pullRequest);

////////Iterate over comments//////////////////
if (!_.isEmpty(comments){
_.forEach(comments, function(comment) {
appendIfHasAllReactions(topComments, comment);
});
}

///////////////////Iterate over inlineComments//////////////////
if (!_.isEmpty(comments){
_.forEach(inlineComments, function(inlineComments) {
appendIfHasAllReactions (topComments, inlineComments);
});
}

return topComments;
}

Expand Down

0 comments on commit c6c1ea5

Please sign in to comment.