Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created October 19, 2016 20:15
Show Gist options
  • Save kutyel/7c11ef44a121f949cece41178ce84b1c to your computer and use it in GitHub Desktop.
Save kutyel/7c11ef44a121f949cece41178ce84b1c to your computer and use it in GitHub Desktop.
{
shouldFlag: function(selectedIds) {
// Assume don't flag
var shouldFlagMessages = false;
// Keep track of how many are flagged and not flagged
var flaggedCount = 0;
var unFlaggedCount = 0;
// Get only the messages we care about
var messagesInQuestion = [];
for (var i = 0; i < this.messages.length; i++) {
if (selectedIds.indexOf(this.messages[i].id) !== -1) {
messagesInQuestion.push(this.messages[i]);
}
}
// Determine the number of flagged messages vs. unflagged messages in the set
for (var i = 0; i < messagesInQuestion.length; i++) {
if (messagesInQuestion[i].flagged) {
flaggedCount++;
} else {
unFlaggedCount++;
}
}
// Only flag the messages if there are no flagged messages
// OR there are messagesInQuestion present that are not flagged
if (flaggedCount === 0 || unFlaggedCount !== 0) {
shouldFlagMessages = true;
}
return shouldFlagMessages;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment