Last active
December 10, 2015 10:58
-
-
Save jmcguirk/4424109 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
/** | |
* Appends a new item into the given users inbox | |
* | |
* @param userId The recipient of this message | |
* @param listName The name of the list being processed | |
* @param data The data to include with this message | |
* @param callback The callback to make when the list is fully processed. Passes error indicator and a buffer | |
*/ | |
this.appendInboxItem = function(userId, listName, data, callback){ | |
var client = this._getClientForKey(userId); | |
var fullKey = this._formKey(userId, listName); | |
var msg = {}; | |
msg.messageId = ServiceLocator.IdGen('36', '0123456789abcdef'); | |
msg.sentOn = new Date().getTime(); | |
msg.body = data; | |
client.lpush(fullKey, JSON.stringify(msg), function(err){ | |
if(!err){ | |
client.ltrim(fullKey, 0, ServiceLocator.Constants.PLAYER_INBOX_MAX_LENGTH, function(err){ | |
callback(err); | |
}); | |
} else{ | |
callback(err); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment