Skip to content

Instantly share code, notes, and snippets.

@jmcguirk
Last active December 10, 2015 10:58
Show Gist options
  • Save jmcguirk/4424109 to your computer and use it in GitHub Desktop.
Save jmcguirk/4424109 to your computer and use it in GitHub Desktop.
/**
* 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