Last active
December 10, 2015 10:58
-
-
Save jmcguirk/4424123 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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