Added mark pms read route. Fixed error checking and extra code.

This commit is contained in:
Keith Holliday
2016-05-06 09:45:04 -05:00
parent b037ddd14c
commit c88cae4ddb
4 changed files with 56 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
module.exports = function clearPMs (user) { module.exports = function clearPMs (user) {
user.inbox.messages = {}; user.inbox.messages = {};
// user.markModified('inbox.messages'); user.markModified('inbox.messages');
return [ return [
user.inbox.messages, user.inbox.messages,
]; ];

View File

@@ -21,8 +21,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
if (!!fromState.name) Analytics.track({'hitType':'pageview','eventCategory':'navigation','eventAction':'navigate','page':'/#/'+toState.name}); if (!!fromState.name) Analytics.track({'hitType':'pageview','eventCategory':'navigation','eventAction':'navigate','page':'/#/'+toState.name});
// clear inbox when entering or exiting inbox tab // clear inbox when entering or exiting inbox tab
if (fromState.name=='options.social.inbox' || toState.name=='options.social.inbox') { if (fromState.name=='options.social.inbox' || toState.name=='options.social.inbox') {
//@TODO: Protected path. We need a url User.clearNewMessages();
User.set({'inbox.newMessages': 0});
} }
}); });

View File

@@ -14,8 +14,8 @@ angular.module('habitrpg')
/** /**
* Services that persists and retrieves user from localStorage. * Services that persists and retrieves user from localStorage.
*/ */
.factory('User', ['$rootScope', '$http', '$location', '$window', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID', 'MOBILE_APP', 'Notification', 'ApiUrl', .factory('User', ['$rootScope', '$http', '$location', '$window', 'STORAGE_USER_ID', 'STORAGE_SETTINGS_ID', 'Notification', 'ApiUrl',
function($rootScope, $http, $location, $window, STORAGE_USER_ID, STORAGE_SETTINGS_ID, MOBILE_APP, Notification, ApiUrl) { function($rootScope, $http, $location, $window, STORAGE_USER_ID, STORAGE_SETTINGS_ID, Notification, ApiUrl) {
var authenticated = false; var authenticated = false;
var defaultSettings = { var defaultSettings = {
auth: { apiId: '', apiToken: ''}, auth: { apiId: '', apiToken: ''},
@@ -51,7 +51,7 @@ angular.module('habitrpg')
url: 'api/v3/user/', url: 'api/v3/user/',
}) })
.then(function (response) { .then(function (response) {
Notification.text(response.data.message); if (response.data.message) Notification.text(response.data.message);
_.extend(user, response.data.data); _.extend(user, response.data.data);
@@ -70,8 +70,7 @@ angular.module('habitrpg')
} }
if (err) { if (err) {
var message = err.code ? err.message : err; var message = err.code ? err.message : err;
if (MOBILE_APP) Notification.push({type:'text',text:message}); Notification.text(message);
else Notification.text(message);
// In the case of 200s, they're friendly alert messages like "Your pet has hatched!" - still send the op // In the case of 200s, they're friendly alert messages like "Your pet has hatched!" - still send the op
if ((err.code && err.code >= 400) || !err.code) return; if ((err.code && err.code >= 400) || !err.code) return;
} }
@@ -113,7 +112,7 @@ angular.module('habitrpg')
body: body, body: body,
}) })
.then(function (response) { .then(function (response) {
Notification.text(response.data.message); if (response.data.message) Notification.text(response.data.message);
save(); save();
}) })
} }
@@ -122,8 +121,6 @@ angular.module('habitrpg')
for (var key in updates) { for (var key in updates) {
user[key] = updates[key]; user[key] = updates[key];
} }
sync();
} }
var userServices = { var userServices = {
@@ -201,6 +198,16 @@ angular.module('habitrpg')
}) })
}, },
clearNewMessages: function () {
$http({
method: "POST",
url: 'api/v3/user/mark-pms-read',
})
.then(function (response) {
sync();
})
},
clearPMs: function () { clearPMs: function () {
callOpsFunctionAndRequest('clearPMs', 'messages', "DELETE"); callOpsFunctionAndRequest('clearPMs', 'messages', "DELETE");
}, },
@@ -259,12 +266,19 @@ angular.module('habitrpg')
}, },
unlock: function (data) { unlock: function (data) {
$window.habitrpgShared.ops['unlock'](user, data);
callOpsFunctionAndRequest('unlock', 'unlock', "POST", '', data); callOpsFunctionAndRequest('unlock', 'unlock', "POST", '', data);
}, },
set: function(updates) { set: function(updates) {
setUser(updates); setUser(updates);
$http({
method: "PUT",
url: 'api/v3/user',
data: updates,
})
.then(function (response) {
sync();
})
}, },
reroll: function () { reroll: function () {
@@ -358,11 +372,9 @@ angular.module('habitrpg')
} }
save(); save();
// syncQueue(cb);
}, },
sync: function(){ sync: function(){
user._v--;
userServices.log({}); userServices.log({});
sync(); sync();
}, },
@@ -387,10 +399,6 @@ angular.module('habitrpg')
//If user does not have ApiID that forward him to settings. //If user does not have ApiID that forward him to settings.
if (!settings.auth.apiId || !settings.auth.apiToken) { if (!settings.auth.apiId || !settings.auth.apiToken) {
if (MOBILE_APP) {
$location.path("/login");
} else {
//var search = $location.search(); // FIXME this should be working, but it's returning an empty object when at a root url /?_id=... //var search = $location.search(); // FIXME this should be working, but it's returning an empty object when at a root url /?_id=...
var search = $location.search($window.location.search.substring(1)).$$search; // so we use this fugly hack instead var search = $location.search($window.location.search.substring(1)).$$search; // so we use this fugly hack instead
if (search.err) return alert(search.err); if (search.err) return alert(search.err);
@@ -405,8 +413,6 @@ angular.module('habitrpg')
$window.location.href = '/logout'; $window.location.href = '/logout';
} }
} }
}
} else { } else {
userServices.authenticate(settings.auth.apiId, settings.auth.apiToken) userServices.authenticate(settings.auth.apiId, settings.auth.apiToken)
} }

View File

@@ -1175,6 +1175,26 @@ api.clearMessages = {
}, },
}; };
/**
* @api {post} /api/v3/user/mark-pms-read Marks Private Messages as read
* @apiVersion 3.0.0
* @apiName markPmsRead
* @apiGroup User
*
* @apiSuccess {object} data user.inbox.messages
**/
api.markPmsRead = {
method: 'POST',
middlewares: [authWithHeaders()],
url: '/user/mark-pms-read',
async handler (req, res) {
let user = res.locals.user;
user.inbox.newMessages = 0;
await user.save();
res.respond(200, user.inbox.newMessages);
},
};
/* /*
* @api {post} /api/v3/user/reroll Rerolls a user. * @api {post} /api/v3/user/reroll Rerolls a user.
* @apiVersion 3.0.0 * @apiVersion 3.0.0