summaryrefslogtreecommitdiffstats
path: root/web/react/stores/user_store.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/stores/user_store.jsx')
-rw-r--r--web/react/stores/user_store.jsx66
1 files changed, 20 insertions, 46 deletions
diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index 9fcd2440e..c1e5c75dc 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -11,13 +11,13 @@ import BrowserStore from './browser_store.jsx';
const CHANGE_EVENT = 'change';
const CHANGE_EVENT_SESSIONS = 'change_sessions';
const CHANGE_EVENT_AUDITS = 'change_audits';
-const CHANGE_EVENT_TEAMS = 'change_teams';
const CHANGE_EVENT_STATUSES = 'change_statuses';
class UserStoreClass extends EventEmitter {
constructor() {
super();
this.profileCache = null;
+ this.currentUserId = '';
}
emitChange(userId) {
@@ -56,18 +56,6 @@ class UserStoreClass extends EventEmitter {
this.removeListener(CHANGE_EVENT_AUDITS, callback);
}
- emitTeamsChange() {
- this.emit(CHANGE_EVENT_TEAMS);
- }
-
- addTeamsChangeListener(callback) {
- this.on(CHANGE_EVENT_TEAMS, callback);
- }
-
- removeTeamsChangeListener(callback) {
- this.removeListener(CHANGE_EVENT_TEAMS, callback);
- }
-
emitStatusesChange() {
this.emit(CHANGE_EVENT_STATUSES);
}
@@ -81,26 +69,17 @@ class UserStoreClass extends EventEmitter {
}
getCurrentUser() {
- if (this.getProfiles()[global.window.mm_user.id] == null) {
- this.saveProfile(global.window.mm_user);
- }
-
- return global.window.mm_user;
+ return this.getProfiles()[this.currentUserId];
}
setCurrentUser(user) {
- var oldUser = global.window.mm_user;
-
- if (oldUser.id === user.id) {
- global.window.mm_user = user;
- this.saveProfile(user);
- } else {
- throw new Error('Problem with setCurrentUser old_user_id=' + oldUser.id + ' new_user_id=' + user.id);
- }
+ this.saveProfile(user);
+ this.currentUserId = user.id;
+ global.window.mm_current_user_id = this.currentUserId;
}
getCurrentId() {
- var user = global.window.mm_user;
+ var user = this.getCurrentUser();
if (user) {
return user.id;
@@ -200,11 +179,22 @@ class UserStoreClass extends EventEmitter {
saveProfiles(profiles) {
const currentId = this.getCurrentId();
- if (currentId in profiles) {
- delete profiles[currentId];
+ if (this.profileCache) {
+ const currentUser = this.profileCache[currentId];
+ if (currentUser) {
+ if (currentId in profiles) {
+ delete profiles[currentId];
+ }
+
+ this.profileCache = profiles;
+ this.profileCache[currentId] = currentUser;
+ } else {
+ this.profileCache = profiles;
+ }
+ } else {
+ this.profileCache = profiles;
}
- this.profileCache = profiles;
BrowserStore.setItem('profiles', profiles);
}
@@ -224,14 +214,6 @@ class UserStoreClass extends EventEmitter {
return BrowserStore.getItem('audits', {loading: true});
}
- setTeams(teams) {
- BrowserStore.setItem('teams', teams);
- }
-
- getTeams() {
- return BrowserStore.getItem('teams', []);
- }
-
getCurrentMentionKeys() {
return this.getMentionKeys(this.getCurrentId());
}
@@ -312,10 +294,6 @@ UserStore.dispatchToken = AppDispatcher.register((payload) => {
UserStore.setAudits(action.audits);
UserStore.emitAuditsChange();
break;
- case ActionTypes.RECEIVED_TEAMS:
- UserStore.setTeams(action.teams);
- UserStore.emitTeamsChange();
- break;
case ActionTypes.RECEIVED_STATUSES:
UserStore.pSetStatuses(action.statuses);
UserStore.emitStatusesChange();
@@ -325,7 +303,3 @@ UserStore.dispatchToken = AppDispatcher.register((payload) => {
});
export {UserStore as default};
-
-if (window.mm_config.EnableDeveloper === 'true') {
- window.UserStore = UserStore;
-}