2017-11-26 20:58:24 +00:00
|
|
|
import googleHelper from './providers/helpers/googleHelper';
|
2017-11-15 08:12:56 +00:00
|
|
|
import store from '../store';
|
|
|
|
|
|
|
|
const promised = {};
|
|
|
|
|
|
|
|
export default {
|
2018-04-27 14:37:05 +00:00
|
|
|
addInfo({ id, name, imageUrl }) {
|
|
|
|
promised[id] = true;
|
|
|
|
store.commit('userInfo/addItem', { id, name, imageUrl });
|
|
|
|
},
|
2017-11-15 08:12:56 +00:00
|
|
|
getInfo(userId) {
|
|
|
|
if (!promised[userId]) {
|
|
|
|
// Try to find a token with this sub
|
|
|
|
const token = store.getters['data/googleTokens'][userId];
|
|
|
|
if (token) {
|
|
|
|
store.commit('userInfo/addItem', {
|
|
|
|
id: userId,
|
|
|
|
name: token.name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get user info from Google
|
|
|
|
if (!store.state.offline) {
|
|
|
|
promised[userId] = true;
|
|
|
|
googleHelper.getUser(userId)
|
2017-11-26 20:58:24 +00:00
|
|
|
.catch((err) => {
|
|
|
|
if (err.status !== 404) {
|
|
|
|
promised[userId] = false;
|
|
|
|
}
|
2017-11-15 08:12:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|