Created
July 16, 2016 22:17
-
-
Save tance77/8b3b66707a7837dc05dcd65ad3a3563a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get active channels | |
//see what channels have follower notifications enabled | |
//see if that follower already exists for that channel | |
//add followers for that channel to db | |
//announce follower | |
exports.announceFollowers = function (db, done) { | |
//See which channels have the follower announcements turned on | |
db.getChannelsWithFollowFeature(function (err, channels) { | |
var channelsWithFollows = []; | |
for (var i = 0; i < channels.length; i++) { | |
channelsWithFollows.push(new Promise(function (resolve) { | |
assembleFollowerList(channels[i], function (err, followObj) { | |
if (err) { | |
return done(err, followObj); | |
} | |
resolve(followObj); | |
}); | |
})); | |
} | |
var followersToAnnounce = []; | |
//Wait for all the channels with follower announcements turned on | |
Promise.all(channelsWithFollows).then(function (channelObj) { | |
console.log((channelObj[0]).followers.follows[0]); | |
//Compile of list of followers that are new | |
for (var i = 0; i < channelObj.length; i++) { | |
for (var j = 0; j < channelObj[i].followers.follows.length; j++) { | |
pushFollowers(channelObj[i].channel_name, | |
channelObj[i].followers.follows[j].user.name, | |
channelObj[i].followers.follows[j].user.updated_at, | |
followersToAnnounce, db, function (err) { | |
if (err) { | |
return done(err, null); | |
} | |
}); | |
} | |
} | |
}); | |
//Wait for all the followers to be added to the db then compile the list for announcing | |
Promise.all(followersToAnnounce).then(function (followersAry) { | |
return done(null, followersAry); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment