Created
January 1, 2013 00:29
-
-
Save jmcguirk/4424156 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
/*! | |
* Inbox service. Responsible for sending messages and receiving new ones | |
*/ | |
function InboxService(){ | |
this.fetchNewItems = function(args, context, callback){ | |
var callResponse = {}; | |
ServiceLocator.PlayerManager.getOrCreatePlayer(context.UserId, context, function(player){ | |
ServiceLocator.DataStore.getNewInboxItems(context.UserId, ServiceLocator.Constants.PLAYER_INBOX_MAIN_INBOX_NAME, player.data.inbox, function(err, newItems){ | |
callResponse.newItems = newItems; | |
player.save(context); | |
callback(callResponse); | |
}); | |
}); | |
} | |
this.ackItems = function(args, context, callback){ | |
var callResponse = {}; | |
ServiceLocator.PlayerManager.getOrCreatePlayer(context.UserId, context, function(player){ | |
ServiceLocator.DataStore.ackInboxItems(context.UserId, ServiceLocator.Constants.PLAYER_INBOX_MAIN_INBOX_NAME, player.data.inbox, function(err){ | |
if(!err){ | |
callResponse.result = "OK"; | |
player.save(context); | |
} else{ | |
callResponse.error = 1; | |
callResponse.errorMessage = "Failed to ack messages " + err; | |
} | |
callback(callResponse); | |
}); | |
}); | |
} | |
this.sendItem = function(args, context, callback){ | |
var callResponse = {}; | |
var recipient = args.recipientId; | |
var msgBody = {}; | |
msgBody.text = "Be sure to drink your Ovaltine"; | |
msgBody.senderId = context.UserId; | |
ServiceLocator.DataStore.appendInboxItem(recipient, ServiceLocator.Constants.PLAYER_INBOX_MAIN_INBOX_NAME, msgBody, function(err){ | |
if(!err){ | |
callResponse.result = "OK"; | |
} else{ | |
callResponse.error = 1; | |
callResponse.errorMessage = "Failed to ack messages " + err; | |
} | |
callback(callResponse); | |
}); | |
} | |
} | |
exports.instance = new InboxService(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment