Synced challenge tasks after leave and join.
This commit is contained in:
@@ -293,7 +293,12 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
Challenges.joinChallenge(challenge._id)
|
||||
.then(function (response) {
|
||||
User.user.challenges.push(challenge._id);
|
||||
_getChallenges()
|
||||
_getChallenges();
|
||||
return Tasks.getUserTasks();
|
||||
})
|
||||
.then(function (response) {
|
||||
var tasks = response.data.data;
|
||||
User.syncUserTasks(tasks);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -305,7 +310,12 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
.then(function (response) {
|
||||
var index = User.user.challenges.indexOf($scope.selectedChal._id);
|
||||
delete User.user.challenges[index];
|
||||
_getChallenges()
|
||||
_getChallenges();
|
||||
return Tasks.getUserTasks();
|
||||
})
|
||||
.then(function (response) {
|
||||
var tasks = response.data.data;
|
||||
User.syncUserTasks(tasks);
|
||||
});
|
||||
}
|
||||
$scope.popoverEl.popover('destroy');
|
||||
|
||||
@@ -45,6 +45,16 @@ angular.module('habitrpg')
|
||||
|
||||
user._wrapped = false;
|
||||
|
||||
function syncUserTasks (tasks) {
|
||||
user.habits = [];
|
||||
user.todos = [];
|
||||
user.dailys = [];
|
||||
user.rewards = [];
|
||||
tasks.forEach(function (element, index, array) {
|
||||
user[element.type + 's'].push(element)
|
||||
});
|
||||
}
|
||||
|
||||
function sync() {
|
||||
return $http({
|
||||
method: "GET",
|
||||
@@ -84,14 +94,7 @@ angular.module('habitrpg')
|
||||
})
|
||||
.then(function (response) {
|
||||
var tasks = response.data.data;
|
||||
user.habits = [];
|
||||
user.todos = [];
|
||||
user.dailys = [];
|
||||
user.rewards = [];
|
||||
tasks.forEach(function (element, index, array) {
|
||||
user[element.type + 's'].push(element)
|
||||
})
|
||||
|
||||
syncUserTasks(tasks);
|
||||
save();
|
||||
$rootScope.$emit('userSynced');
|
||||
});
|
||||
@@ -479,6 +482,8 @@ angular.module('habitrpg')
|
||||
return sync();
|
||||
},
|
||||
|
||||
syncUserTasks: syncUserTasks,
|
||||
|
||||
save: save,
|
||||
|
||||
settings: settings
|
||||
|
||||
Reference in New Issue
Block a user