mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
More Client Fixes (#9036)
* add automatic user syncing when user._v does not match with server * fix google signup * fixes to user sync * check for next cron on activity * add comment
This commit is contained in:
@@ -130,6 +130,7 @@ export default {
|
||||
this.selectedItemToBuy = item;
|
||||
});
|
||||
|
||||
// @TODO split up this file, it's too big
|
||||
// Set up Error interceptors
|
||||
axios.interceptors.response.use((response) => {
|
||||
if (this.user) {
|
||||
@@ -149,6 +150,39 @@ export default {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
axios.interceptors.response.use((response) => {
|
||||
// Verify that the user was not updated from another browser/app/client
|
||||
// If it was, sync
|
||||
const url = response.config.url;
|
||||
const method = response.config.method;
|
||||
|
||||
const isApiCall = url.indexOf('api/v3') !== -1;
|
||||
const userV = response.data && response.data.userV;
|
||||
|
||||
if (this.isUserLoaded && isApiCall && userV) {
|
||||
const oldUserV = this.user._v;
|
||||
this.user._v = userV;
|
||||
|
||||
// Do not sync again if already syncing
|
||||
const isUserSync = url.indexOf('/api/v3/user') === 0 && method === 'get';
|
||||
const isTasksSync = url.indexOf('/api/v3/tasks/user') === 0 && method === 'get';
|
||||
// exclude chat seen requests because with real time chat they would be too many
|
||||
const isChatSeen = url.indexOf('/chat/seen') !== -1 && method === 'post';
|
||||
// exclude POST /api/v3/cron because the user is synced automatically after cron runs
|
||||
const isCron = url.indexOf('/api/v3/cron') === 0 && method === 'post';
|
||||
|
||||
// Something has changed on the user object that was not tracked here, sync the user
|
||||
if (userV - oldUserV > 1 && !isCron && !isChatSeen && !isUserSync && !isTasksSync) {
|
||||
Promise.all([
|
||||
this.$store.dispatch('user:fetch', {forceLoad: true}),
|
||||
this.$store.dispatch('tasks:fetchUserTasks', {forceLoad: true}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
});
|
||||
|
||||
// Setup listener for title
|
||||
this.$store.watch(state => state.title, (title) => {
|
||||
document.title = title;
|
||||
|
||||
Reference in New Issue
Block a user