Added force cache update when fetching new messages (#7360)

This commit is contained in:
Keith Holliday
2016-05-18 20:49:58 +01:00
committed by Matteo Pagliazzi
parent f0f67e1e88
commit 9a32a01a3e
2 changed files with 21 additions and 11 deletions

View File

@@ -114,12 +114,19 @@ habitrpg.controller('ChatCtrl', ['$scope', 'Groups', 'Chat', 'User', '$http', 'A
});
};
function handleGroupResponse (response) {
$scope.group = response;
if (!$scope.group._id) $scope.group = response.data.data;
};
$scope.sync = function(group) {
//@TODO: We need to use chat service here
Groups.Group.get(group._id)
.then(function (response) {
$scope.group = response.data.data;
})
if (group.name === Groups.TAVERN_NAME) {
Groups.tavern(true).then(handleGroupResponse);
} else if (group._id === User.user.party._id) {
Groups.party(true).then(handleGroupResponse);
} else {
Groups.Group.get(group._id).then(handleGroupResponse);
}
Chat.markChatSeen(group._id);
}

View File

@@ -5,6 +5,7 @@ angular.module('habitrpg')
function($location, $rootScope, $http, Analytics, ApiUrl, Challenges, $q, User, Members) {
var data = {party: undefined, myGuilds: undefined, publicGuilds: undefined, tavern: undefined };
var groupApiURLPrefix = "/api/v3/groups";
var TAVERN_NAME = 'HabitRPG';
var Group = {};
@@ -104,8 +105,8 @@ angular.module('habitrpg')
//On page load, multiple controller request the party.
//So, we cache the promise until the first result is returned
var _cachedPartyPromise;
function party () {
if (_cachedPartyPromise) return _cachedPartyPromise.promise;
function party (forceUpdate) {
if (_cachedPartyPromise && !forceUpdate) return _cachedPartyPromise.promise;
_cachedPartyPromise = $q.defer();
if (!User.user.party._id) {
@@ -113,7 +114,7 @@ angular.module('habitrpg')
_cachedPartyPromise.reject(data.party);
}
if (!data.party) {
if (!data.party || forceUpdate) {
Group.get('party')
.then(function (response) {
data.party = response.data.data;
@@ -125,7 +126,8 @@ angular.module('habitrpg')
}, function (response) {
data.party = { type: 'party' };
_cachedPartyPromise.reject(data.party);
}).finally(function(){
})
.finally(function() {
_cachePartyPromise = null;
});
} else {
@@ -172,10 +174,10 @@ angular.module('habitrpg')
return deferred.promise;
}
function tavern () {
function tavern (forceUpdate) {
var deferred = $q.defer();
if (!data.tavern) {
if (!data.tavern || forceUpdate) {
Group.get('habitrpg')
.then(function (response) {
data.tavern = response.data.data;
@@ -206,6 +208,7 @@ angular.module('habitrpg')
}
return {
TAVERN_NAME: TAVERN_NAME,
party: party,
publicGuilds: publicGuilds,
myGuilds: myGuilds,