From f307f5593c9937fc4f15cf94622905e090b23db3 Mon Sep 17 00:00:00 2001 From: Alice Harris Date: Sat, 23 Aug 2014 12:19:41 +1000 Subject: [PATCH 1/2] add migration script to remove undefined guild notifications and false guild notifications --- ...0823_remove_undefined_and_false_notifications.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 migrations/20140823_remove_undefined_and_false_notifications.js diff --git a/migrations/20140823_remove_undefined_and_false_notifications.js b/migrations/20140823_remove_undefined_and_false_notifications.js new file mode 100644 index 0000000000..77882c4be7 --- /dev/null +++ b/migrations/20140823_remove_undefined_and_false_notifications.js @@ -0,0 +1,13 @@ +db.users.find({}).forEach(function(user){ + var newNewMessages = {}; + + for(var key in user.newMessages) { + var val = user.newMessages[key]; + // print("\n" + key + " " + val); + if(key != "undefined" && val['value']){ + newNewMessages[key] = val; + } + } + + db.users.update({_id: user._id}, {$set: {'newMessages': newNewMessages}}); +}); From 1ca981d90a75d4ed32ece7f000bc1bbaff1830e3 Mon Sep 17 00:00:00 2001 From: Alice Harris Date: Sat, 23 Aug 2014 14:51:34 +1000 Subject: [PATCH 2/2] allow notification icon to go grey by deleting seen message data instead of setting to false --- public/js/services/groupServices.js | 2 +- src/controllers/groups.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/js/services/groupServices.js b/public/js/services/groupServices.js index ebfcc56319..85214eba79 100644 --- a/public/js/services/groupServices.js +++ b/public/js/services/groupServices.js @@ -47,7 +47,7 @@ angular.module('groupServices', ['ngResource']). // On enter, set chat message to "seen" seenMessage: function(gid){ $http.post('/api/v2/groups/'+gid+'/chat/seen'); - if (User.user.newMessages) User.user.newMessages[gid] = false; + if (User.user.newMessages) delete User.user.newMessages[gid]; }, // Pass reference to party, myGuilds, publicGuilds, tavern; inside data in order to diff --git a/src/controllers/groups.js b/src/controllers/groups.js index d867f0048d..c126373484 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -257,8 +257,8 @@ api.seenMessage = function(req,res,next){ // Skip the auth step, we want this to be fast. If !found with uuid/token, then it just doesn't save // Check for req.params.gid to exist if(req.params.gid){ - var update = {$set:{}}; - update['$set']['newMessages.'+req.params.gid+'.value'] = false; + var update = {$unset:{}}; + update['$unset']['newMessages.'+req.params.gid] = ''; User.update({_id:req.headers['x-api-user'], apiToken:req.headers['x-api-key']},update).exec(); } res.send(200);