Allow for client notifications to user settings

Added functionality on successful user changes (see userNotifications
object in userServices.js)

On this commit, it will tell the user "Party order updated" when the
sorting settings change.
This commit is contained in:
Aaron Morris
2015-03-02 09:00:37 -05:00
parent 85b547196e
commit b484dd3208

View File

@@ -29,6 +29,11 @@ angular.module('habitrpg')
var settings = {}; //habit mobile settings (like auth etc.) to be stored here var settings = {}; //habit mobile settings (like auth etc.) to be stored here
var user = {}; // this is stored as a reference accessible to all controllers, that way updates propagate var user = {}; // this is stored as a reference accessible to all controllers, that way updates propagate
var userNotifications = {
"party.order" : "Party order updated.",
"party.orderAscending" : "Party order updated."
}; // this is a list of notifications to send to the user when changes are made, along with the message.
//first we populate user with schema //first we populate user with schema
user.apiToken = user._id = ''; // we use id / apitoken to determine if registered user.apiToken = user._id = ''; // we use id / apitoken to determine if registered
@@ -70,6 +75,9 @@ angular.module('habitrpg')
$http.post(ApiUrl.get() + '/api/v2/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env && $window.env.siteVersion}}) $http.post(ApiUrl.get() + '/api/v2/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env && $window.env.siteVersion}})
.success(function (data, status, heacreatingders, config) { .success(function (data, status, heacreatingders, config) {
//alert("Updating " + JSON.stringify(sent));
//alert("Response was " + status);
//user.party.
//make sure there are no pending actions to sync. If there are any it is not safe to apply model from server as we may overwrite user data. //make sure there are no pending actions to sync. If there are any it is not safe to apply model from server as we may overwrite user data.
if (!queue.length) { if (!queue.length) {
//we can't do user=data as it will not update user references in all other angular controllers. //we can't do user=data as it will not update user references in all other angular controllers.
@@ -94,6 +102,10 @@ angular.module('habitrpg')
user.ops[k] = function(req,cb){ user.ops[k] = function(req,cb){
if (cb) return op(req,cb); if (cb) return op(req,cb);
op(req,function(err,response) { op(req,function(err,response) {
for(var updatedItem in req.body) {
var itemUpdateResponse = userNotifications[updatedItem]
if(itemUpdateResponse) Notification.text(itemUpdateResponse);
}
if (err) { if (err) {
var message = err.code ? err.message : err; var message = err.code ? err.message : err;
console.log(message); console.log(message);
@@ -149,6 +161,7 @@ angular.module('habitrpg')
set: function(updates) { set: function(updates) {
user.ops.update({body:updates}); user.ops.update({body:updates});
}, },
online: function (status) { online: function (status) {
if (status===true) { if (status===true) {
settings.online = true; settings.online = true;