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.jsx120
1 files changed, 20 insertions, 100 deletions
diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index e832b34c7..93ddfec70 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -8,7 +8,7 @@ var client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
-var BrowserStore = require('../stores/browser_store.jsx');
+var BrowserStore = require('./browser_store.jsx');
var CHANGE_EVENT = 'change';
var CHANGE_EVENT_SESSIONS = 'change_sessions';
@@ -18,6 +18,8 @@ var CHANGE_EVENT_STATUSES = 'change_statuses';
var UserStore = assign({}, EventEmitter.prototype, {
+ _current_id: null,
+
emitChange: function(userId) {
this.emit(CHANGE_EVENT, userId);
},
@@ -64,13 +66,10 @@ var UserStore = assign({}, EventEmitter.prototype, {
this.removeListener(CHANGE_EVENT_STATUSES, callback);
},
setCurrentId: function(id) {
- if (id == null)
- BrowserStore.removeGlobalItem("current_user_id");
- else
- BrowserStore.setGlobalItem("current_user_id", id);
+ this._current_id = id;
},
getCurrentId: function(skipFetch) {
- var current_id = BrowserStore.getGlobalItem("current_user_id");
+ var current_id = this._current_id;
// this is a speical case to force fetch the
// current user if it's missing
@@ -97,21 +96,13 @@ var UserStore = assign({}, EventEmitter.prototype, {
this.setCurrentId(user.id);
},
getLastDomain: function() {
- var last_domain = BrowserStore.getItem("last_domain");
- if (last_domain == null) {
- last_domain = "";
- }
- return last_domain;
+ return BrowserStore.getItem("last_domain", '');
},
setLastDomain: function(domain) {
BrowserStore.setItem("last_domain", domain);
},
getLastEmail: function() {
- var last_email = BrowserStore.getItem("last_email");
- if (last_email == null) {
- last_email = "";
- }
- return last_email;
+ return BrowserStore.getItem("last_email", '');
},
setLastEmail: function(email) {
BrowserStore.setItem("last_email", email);
@@ -153,91 +144,36 @@ var UserStore = assign({}, EventEmitter.prototype, {
this._storeProfiles(ps);
},
_storeProfiles: function(profiles) {
- BrowserStore.setGlobalItem("profiles", JSON.stringify(profiles));
+ BrowserStore.setGlobalItem("profiles", profiles);
var profileUsernameMap = {};
for (var id in profiles) {
profileUsernameMap[profiles[id].username] = profiles[id];
}
- BrowserStore.setGlobalItem("profileUsernameMap", JSON.stringify(profileUsernameMap));
+ BrowserStore.setGlobalItem("profileUsernameMap", profileUsernameMap);
},
_getProfiles: function() {
- var profiles = {};
- try {
- profiles = JSON.parse(BrowserStore.getGlobalItem("profiles"));
- }
- catch (err) {
- }
-
- if (profiles == null) {
- profiles = {};
- }
-
- return profiles;
+ return BrowserStore.getGlobalItem("profiles", {});
},
_getProfilesUsernameMap: function() {
- var profileUsernameMap = {};
- try {
- profileUsernameMap = JSON.parse(BrowserStore.getGlobalItem("profileUsernameMap"));
- }
- catch (err) {
- }
-
- if (profileUsernameMap == null) {
- profileUsernameMap = {};
- }
-
- return profileUsernameMap;
+ return BrowserStore.getGlobalItem("profileUsernameMap", {});
},
setSessions: function(sessions) {
- BrowserStore.setItem("sessions", JSON.stringify(sessions));
+ BrowserStore.setItem("sessions", sessions);
},
getSessions: function() {
- var sessions = [];
- try {
- sessions = JSON.parse(BrowserStore.getItem("sessions"));
- }
- catch (err) {
- }
- if (sessions == null) {
- sessions = [];
- }
-
- return sessions;
+ return BrowserStore.getItem("sessions", []);
},
setAudits: function(audits) {
- BrowserStore.setItem("audits", JSON.stringify(audits));
+ BrowserStore.setItem("audits", audits);
},
getAudits: function() {
- var audits = [];
- try {
- audits = JSON.parse(BrowserStore.getItem("audits"));
- }
- catch (err) {
- }
-
- if (audits == null) {
- audits = [];
- }
-
- return audits;
+ return BrowserStore.getItem("audits", []);
},
setTeams: function(teams) {
- BrowserStore.setItem("teams", JSON.stringify(teams));
+ BrowserStore.setItem("teams", teams);
},
getTeams: function() {
- var teams = [];
- try {
- teams = JSON.parse(BrowserStore.getItem("teams"));
-
- }
- catch (err) {
- }
-
- if (teams == null) {
- teams = [];
- }
-
- return teams;
+ return BrowserStore.getItem("teams", []);
},
getCurrentMentionKeys: function() {
var user = this.getCurrentUser();
@@ -258,11 +194,7 @@ var UserStore = assign({}, EventEmitter.prototype, {
}
},
getLastVersion: function() {
- var last_version = BrowserStore.getItem("last_version");
- if (last_version == null) {
- last_version = "";
- }
- return last_version;
+ return BrowserStore.getItem("last_version", '');
},
setLastVersion: function(version) {
BrowserStore.setItem("last_version", version);
@@ -272,7 +204,7 @@ var UserStore = assign({}, EventEmitter.prototype, {
this.emitStatusesChange();
},
_setStatuses: function(statuses) {
- BrowserStore.setItem("statuses", JSON.stringify(statuses));
+ BrowserStore.setItem("statuses", statuses);
},
setStatus: function(user_id, status) {
var statuses = this.getStatuses();
@@ -281,18 +213,7 @@ var UserStore = assign({}, EventEmitter.prototype, {
this.emitStatusesChange();
},
getStatuses: function() {
- var statuses = {};
- try {
- statuses = JSON.parse(BrowserStore.getItem("statuses"));
- }
- catch (err) {
- }
-
- if (statuses == null) {
- statuses = {};
- }
-
- return statuses;
+ return BrowserStore.getItem("statuses", {});
},
getStatus: function(id) {
return this.getStatuses()[id];
@@ -341,4 +262,3 @@ UserStore.setMaxListeners(0);
global.window.UserStore = UserStore;
module.exports = UserStore;
-