mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Added force cache update when fetching new messages (#7360)
This commit is contained in:
committed by
Matteo Pagliazzi
parent
f0f67e1e88
commit
9a32a01a3e
@@ -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) {
|
$scope.sync = function(group) {
|
||||||
//@TODO: We need to use chat service here
|
if (group.name === Groups.TAVERN_NAME) {
|
||||||
Groups.Group.get(group._id)
|
Groups.tavern(true).then(handleGroupResponse);
|
||||||
.then(function (response) {
|
} else if (group._id === User.user.party._id) {
|
||||||
$scope.group = response.data.data;
|
Groups.party(true).then(handleGroupResponse);
|
||||||
})
|
} else {
|
||||||
|
Groups.Group.get(group._id).then(handleGroupResponse);
|
||||||
|
}
|
||||||
|
|
||||||
Chat.markChatSeen(group._id);
|
Chat.markChatSeen(group._id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ angular.module('habitrpg')
|
|||||||
function($location, $rootScope, $http, Analytics, ApiUrl, Challenges, $q, User, Members) {
|
function($location, $rootScope, $http, Analytics, ApiUrl, Challenges, $q, User, Members) {
|
||||||
var data = {party: undefined, myGuilds: undefined, publicGuilds: undefined, tavern: undefined };
|
var data = {party: undefined, myGuilds: undefined, publicGuilds: undefined, tavern: undefined };
|
||||||
var groupApiURLPrefix = "/api/v3/groups";
|
var groupApiURLPrefix = "/api/v3/groups";
|
||||||
|
var TAVERN_NAME = 'HabitRPG';
|
||||||
|
|
||||||
var Group = {};
|
var Group = {};
|
||||||
|
|
||||||
@@ -104,8 +105,8 @@ angular.module('habitrpg')
|
|||||||
//On page load, multiple controller request the party.
|
//On page load, multiple controller request the party.
|
||||||
//So, we cache the promise until the first result is returned
|
//So, we cache the promise until the first result is returned
|
||||||
var _cachedPartyPromise;
|
var _cachedPartyPromise;
|
||||||
function party () {
|
function party (forceUpdate) {
|
||||||
if (_cachedPartyPromise) return _cachedPartyPromise.promise;
|
if (_cachedPartyPromise && !forceUpdate) return _cachedPartyPromise.promise;
|
||||||
_cachedPartyPromise = $q.defer();
|
_cachedPartyPromise = $q.defer();
|
||||||
|
|
||||||
if (!User.user.party._id) {
|
if (!User.user.party._id) {
|
||||||
@@ -113,7 +114,7 @@ angular.module('habitrpg')
|
|||||||
_cachedPartyPromise.reject(data.party);
|
_cachedPartyPromise.reject(data.party);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.party) {
|
if (!data.party || forceUpdate) {
|
||||||
Group.get('party')
|
Group.get('party')
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
data.party = response.data.data;
|
data.party = response.data.data;
|
||||||
@@ -125,7 +126,8 @@ angular.module('habitrpg')
|
|||||||
}, function (response) {
|
}, function (response) {
|
||||||
data.party = { type: 'party' };
|
data.party = { type: 'party' };
|
||||||
_cachedPartyPromise.reject(data.party);
|
_cachedPartyPromise.reject(data.party);
|
||||||
}).finally(function(){
|
})
|
||||||
|
.finally(function() {
|
||||||
_cachePartyPromise = null;
|
_cachePartyPromise = null;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -172,10 +174,10 @@ angular.module('habitrpg')
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tavern () {
|
function tavern (forceUpdate) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
if (!data.tavern) {
|
if (!data.tavern || forceUpdate) {
|
||||||
Group.get('habitrpg')
|
Group.get('habitrpg')
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
data.tavern = response.data.data;
|
data.tavern = response.data.data;
|
||||||
@@ -206,6 +208,7 @@ angular.module('habitrpg')
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
TAVERN_NAME: TAVERN_NAME,
|
||||||
party: party,
|
party: party,
|
||||||
publicGuilds: publicGuilds,
|
publicGuilds: publicGuilds,
|
||||||
myGuilds: myGuilds,
|
myGuilds: myGuilds,
|
||||||
|
|||||||
Reference in New Issue
Block a user