3 var _ = require('lodash');
4 var TWEET_MAX_CHARACTER_LIMIT = 140;
6 function countMaxUsernamesForTweet(mentionList, size) {
9 while (count < mentionList.length) {
10 var nextTwitterUserLength = mentionList[count].length;
13 characters += nextTwitterUserLength + 1; // Need to include a space separator
15 characters += nextTwitterUserLength;
18 if (characters >= size) {
28 function composeTweetAndDequeue(invitingUserName, mentionList, name, url) {
29 var baseMessagePre = 'Hey ';
31 " you've been invited to the " + name + ' community by ' + invitingUserName + '.\n' + url;
32 var baseMessageLength = baseMessagePre.length + baseMessagePost.length;
34 var count = countMaxUsernamesForTweet(mentionList, TWEET_MAX_CHARACTER_LIMIT - baseMessageLength);
35 var usernames = mentionList.slice(0, count);
36 mentionList.splice(0, count);
38 return baseMessagePre + usernames.join(' ') + baseMessagePost;
41 function badgerMessageComposer(invitingUserName, mentionList, name, url) {
42 if (!mentionList.length) return [];
43 mentionList = _.uniq(mentionList);
46 while (mentionList.length) {
47 var tweet = composeTweetAndDequeue(invitingUserName, mentionList, name, url);
56 module.exports = badgerMessageComposer;