Skip to content

Instantly share code, notes, and snippets.

@jmcguirk
Last active December 10, 2015 10:58
Show Gist options
  • Save jmcguirk/4424123 to your computer and use it in GitHub Desktop.
Save jmcguirk/4424123 to your computer and use it in GitHub Desktop.
/**
* Gets a collection of new inbox items, if any
*
* @param userId The user id of the user whos list is being processed
* @param listName The name of the list being processed
* @param playerInbox The players current inbox
* @param callback The callback to make when the list is fully processed. Passes error indic
*/
this.getNewInboxItems = function(userId, listName, playerInbox, callback){
var client = this._getClientForKey(userId);
var fullKey = this._formKey(userId, listName);
client.lrange(fullKey, -10000, 10000, function(err, val){
var newRecords = [];
for(var i = 0; i < val.length; i++){
var msg = JSON.parse(val[i]);
var messageId = msg.messageId;
if(!playerInbox.hasOwnProperty(messageId)){
var message = {};
message.receivedOn = new Date().getTime();
message.acked = false;
message.processed = false;
message.contents = msg;
playerInbox[messageId] = message;
newRecords.push(message);
}
}
ServiceLocator.DataStore.pruneReceivedInboxItems(playerInbox);
callback(err, newRecords);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment