mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
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:
@@ -29,6 +29,11 @@ angular.module('habitrpg')
|
||||
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 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
|
||||
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}})
|
||||
.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.
|
||||
if (!queue.length) {
|
||||
//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){
|
||||
if (cb) return op(req,cb);
|
||||
op(req,function(err,response) {
|
||||
for(var updatedItem in req.body) {
|
||||
var itemUpdateResponse = userNotifications[updatedItem]
|
||||
if(itemUpdateResponse) Notification.text(itemUpdateResponse);
|
||||
}
|
||||
if (err) {
|
||||
var message = err.code ? err.message : err;
|
||||
console.log(message);
|
||||
@@ -149,6 +161,7 @@ angular.module('habitrpg')
|
||||
set: function(updates) {
|
||||
user.ops.update({body:updates});
|
||||
},
|
||||
|
||||
online: function (status) {
|
||||
if (status===true) {
|
||||
settings.online = true;
|
||||
|
||||
Reference in New Issue
Block a user