Created
January 1, 2013 00:23
-
-
Save jmcguirk/4424137 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
/** | |
* Acks all outstanding inbox messages | |
* | |
* @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.ackInboxItems = function(userId, listName, playerInbox, callback){ | |
this.ackInboxItemNext(userId, listName, playerInbox, 0, callback); | |
} | |
/** | |
* Recursive loop for acknowledging inbox items | |
* | |
* @param userId The user id of the owner of this list | |
* @param listName The list name to use for this user | |
* @param playerInbox The player inbox to ack out of | |
* @param index Current index being processed | |
* @param callback The callback to use when no more items remain | |
*/ | |
this.ackInboxItemNext = function(userId, listName, playerInbox, index, callback){ | |
var client = this._getClientForKey(userId); | |
var fullKey = this._formKey(userId, listName); | |
var allkeys = Object.keys(playerInbox); | |
if(index >= allkeys.length){ | |
this.pruneReceivedInboxItems(playerInbox); | |
callback(); | |
return; | |
} | |
nextItem = playerInbox[allkeys[index]]; | |
if(!nextItem.acked){ | |
client.lrem(fullKey, 0, JSON.stringify(nextItem.contents), function(err, resp){ | |
nextItem.acked = true; | |
ServiceLocator.DataStore.ackInboxItemNext(userId, listName, playerInbox, index+1, callback); | |
}); | |
} else{ | |
this.ackInboxItemNext(userId, listName, playerInbox, index+1, callback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment