fixed the spacing on UserStore

Этот коммит содержится в:
nickago
2015-08-06 11:10:07 -07:00
родитель 3815ab8065
Коммит 24b6c6587c

Просмотреть файл

@@ -19,231 +19,231 @@ var UserStore = assign({}, EventEmitter.prototype, {
_current_id: null, _current_id: null,
emitChange: function(userId) { emitChange: function(userId) {
this.emit(CHANGE_EVENT, userId); this.emit(CHANGE_EVENT, userId);
}, },
addChangeListener: function(callback) { addChangeListener: function(callback) {
this.on(CHANGE_EVENT, callback); this.on(CHANGE_EVENT, callback);
}, },
removeChangeListener: function(callback) { removeChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT, callback); this.removeListener(CHANGE_EVENT, callback);
}, },
emitSessionsChange: function() { emitSessionsChange: function() {
this.emit(CHANGE_EVENT_SESSIONS); this.emit(CHANGE_EVENT_SESSIONS);
}, },
addSessionsChangeListener: function(callback) { addSessionsChangeListener: function(callback) {
this.on(CHANGE_EVENT_SESSIONS, callback); this.on(CHANGE_EVENT_SESSIONS, callback);
}, },
removeSessionsChangeListener: function(callback) { removeSessionsChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT_SESSIONS, callback); this.removeListener(CHANGE_EVENT_SESSIONS, callback);
}, },
emitAuditsChange: function() { emitAuditsChange: function() {
this.emit(CHANGE_EVENT_AUDITS); this.emit(CHANGE_EVENT_AUDITS);
}, },
addAuditsChangeListener: function(callback) { addAuditsChangeListener: function(callback) {
this.on(CHANGE_EVENT_AUDITS, callback); this.on(CHANGE_EVENT_AUDITS, callback);
}, },
removeAuditsChangeListener: function(callback) { removeAuditsChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT_AUDITS, callback); this.removeListener(CHANGE_EVENT_AUDITS, callback);
}, },
emitTeamsChange: function() { emitTeamsChange: function() {
this.emit(CHANGE_EVENT_TEAMS); this.emit(CHANGE_EVENT_TEAMS);
}, },
addTeamsChangeListener: function(callback) { addTeamsChangeListener: function(callback) {
this.on(CHANGE_EVENT_TEAMS, callback); this.on(CHANGE_EVENT_TEAMS, callback);
}, },
removeTeamsChangeListener: function(callback) { removeTeamsChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT_TEAMS, callback); this.removeListener(CHANGE_EVENT_TEAMS, callback);
}, },
emitStatusesChange: function() { emitStatusesChange: function() {
this.emit(CHANGE_EVENT_STATUSES); this.emit(CHANGE_EVENT_STATUSES);
}, },
addStatusesChangeListener: function(callback) { addStatusesChangeListener: function(callback) {
this.on(CHANGE_EVENT_STATUSES, callback); this.on(CHANGE_EVENT_STATUSES, callback);
}, },
removeStatusesChangeListener: function(callback) { removeStatusesChangeListener: function(callback) {
this.removeListener(CHANGE_EVENT_STATUSES, callback); this.removeListener(CHANGE_EVENT_STATUSES, callback);
}, },
setCurrentId: function(id) { setCurrentId: function(id) {
this._current_id = id; this._current_id = id;
if (id == null) { if (id == null) {
BrowserStore.removeGlobalItem("current_user_id"); BrowserStore.removeGlobalItem("current_user_id");
} else { } else {
BrowserStore.setGlobalItem("current_user_id", id); BrowserStore.setGlobalItem("current_user_id", id);
} }
}, },
getCurrentId: function() { getCurrentId: function() {
var current_id = this._current_id; var current_id = this._current_id;
if (current_id == null) { if (current_id == null) {
current_id = BrowserStore.getGlobalItem("current_user_id"); current_id = BrowserStore.getGlobalItem("current_user_id");
} }
return current_id; return current_id;
}, },
getCurrentUser: function(skipFetch) { getCurrentUser: function(skipFetch) {
if (this.getCurrentId(skipFetch) == null) { if (this.getCurrentId(skipFetch) == null) {
return null; return null;
} }
return this._getProfiles()[this.getCurrentId()]; return this._getProfiles()[this.getCurrentId()];
}, },
setCurrentUser: function(user) { setCurrentUser: function(user) {
this.setCurrentId(user.id); this.setCurrentId(user.id);
this.saveProfile(user); this.saveProfile(user);
}, },
getLastEmail: function() { getLastEmail: function() {
return BrowserStore.getItem("last_email", ''); return BrowserStore.getItem("last_email", '');
}, },
setLastEmail: function(email) { setLastEmail: function(email) {
BrowserStore.setItem("last_email", email); BrowserStore.setItem("last_email", email);
}, },
removeCurrentUser: function() { removeCurrentUser: function() {
this.setCurrentId(null); this.setCurrentId(null);
}, },
hasProfile: function(userId) { hasProfile: function(userId) {
return this._getProfiles()[userId] != null; return this._getProfiles()[userId] != null;
}, },
getProfile: function(userId) { getProfile: function(userId) {
return this._getProfiles()[userId]; return this._getProfiles()[userId];
}, },
getProfileByUsername: function(username) { getProfileByUsername: function(username) {
return this._getProfilesUsernameMap()[username]; return this._getProfilesUsernameMap()[username];
}, },
getProfilesUsernameMap: function() { getProfilesUsernameMap: function() {
return this._getProfilesUsernameMap(); return this._getProfilesUsernameMap();
}, },
getProfiles: function() { getProfiles: function() {
return this._getProfiles(); return this._getProfiles();
}, },
getActiveOnlyProfiles: function() { getActiveOnlyProfiles: function() {
active = {}; active = {};
current = this._getProfiles(); current = this._getProfiles();
for (var key in current) { for (var key in current) {
if (current[key].delete_at == 0) { if (current[key].delete_at == 0) {
active[key] = current[key]; active[key] = current[key];
} }
} }
return active; return active;
}, },
saveProfile: function(profile) { saveProfile: function(profile) {
var ps = this._getProfiles(); var ps = this._getProfiles();
ps[profile.id] = profile; ps[profile.id] = profile;
this._storeProfiles(ps); this._storeProfiles(ps);
}, },
_storeProfiles: function(profiles) { _storeProfiles: function(profiles) {
BrowserStore.setItem("profiles", profiles); BrowserStore.setItem("profiles", profiles);
var profileUsernameMap = {}; var profileUsernameMap = {};
for (var id in profiles) { for (var id in profiles) {
profileUsernameMap[profiles[id].username] = profiles[id]; profileUsernameMap[profiles[id].username] = profiles[id];
} }
BrowserStore.setItem("profileUsernameMap", profileUsernameMap); BrowserStore.setItem("profileUsernameMap", profileUsernameMap);
}, },
_getProfiles: function() { _getProfiles: function() {
return BrowserStore.getItem("profiles", {}); return BrowserStore.getItem("profiles", {});
}, },
_getProfilesUsernameMap: function() { _getProfilesUsernameMap: function() {
return BrowserStore.getItem("profileUsernameMap", {}); return BrowserStore.getItem("profileUsernameMap", {});
}, },
setSessions: function(sessions) { setSessions: function(sessions) {
BrowserStore.setItem("sessions", sessions); BrowserStore.setItem("sessions", sessions);
}, },
getSessions: function() { getSessions: function() {
return BrowserStore.getItem("sessions", {loading: true}); return BrowserStore.getItem("sessions", {loading: true});
}, },
setAudits: function(audits) { setAudits: function(audits) {
BrowserStore.setItem("audits", audits); BrowserStore.setItem("audits", audits);
}, },
getAudits: function() { getAudits: function() {
return BrowserStore.getItem("audits", {loading: true}); return BrowserStore.getItem("audits", {loading: true});
}, },
setTeams: function(teams) { setTeams: function(teams) {
BrowserStore.setItem("teams", teams); BrowserStore.setItem("teams", teams);
}, },
getTeams: function() { getTeams: function() {
return BrowserStore.getItem("teams", []); return BrowserStore.getItem("teams", []);
}, },
getCurrentMentionKeys: function() { getCurrentMentionKeys: function() {
var user = this.getCurrentUser(); var user = this.getCurrentUser();
var keys = []; var keys = [];
if (!user)
return keys;
if (user.notify_props && user.notify_props.mention_keys) keys = keys.concat(user.notify_props.mention_keys.split(','));
if (user.first_name && user.notify_props.first_name === "true") keys.push(user.first_name);
if (user.notify_props.all === "true") keys.push('@all');
if (user.notify_props.channel === "true") keys.push('@channel');
if (!user)
return keys; return keys;
},
if (user.notify_props && user.notify_props.mention_keys) keys = keys.concat(user.notify_props.mention_keys.split(',')); getLastVersion: function() {
if (user.first_name && user.notify_props.first_name === "true") keys.push(user.first_name); return BrowserStore.getItem("last_version", '');
if (user.notify_props.all === "true") keys.push('@all'); },
if (user.notify_props.channel === "true") keys.push('@channel'); setLastVersion: function(version) {
BrowserStore.setItem("last_version", version);
return keys; },
}, setStatuses: function(statuses) {
getLastVersion: function() { this._setStatuses(statuses);
return BrowserStore.getItem("last_version", ''); this.emitStatusesChange();
}, },
setLastVersion: function(version) { _setStatuses: function(statuses) {
BrowserStore.setItem("last_version", version); BrowserStore.setItem("statuses", statuses);
}, },
setStatuses: function(statuses) { setStatus: function(user_id, status) {
this._setStatuses(statuses); var statuses = this.getStatuses();
this.emitStatusesChange(); statuses[user_id] = status;
}, this._setStatuses(statuses);
_setStatuses: function(statuses) { this.emitStatusesChange();
BrowserStore.setItem("statuses", statuses); },
}, getStatuses: function() {
setStatus: function(user_id, status) { return BrowserStore.getItem("statuses", {});
var statuses = this.getStatuses(); },
statuses[user_id] = status; getStatus: function(id) {
this._setStatuses(statuses); return this.getStatuses()[id];
this.emitStatusesChange(); }
},
getStatuses: function() {
return BrowserStore.getItem("statuses", {});
},
getStatus: function(id) {
return this.getStatuses()[id];
}
}); });
UserStore.dispatchToken = AppDispatcher.register(function(payload) { UserStore.dispatchToken = AppDispatcher.register(function(payload) {
var action = payload.action; var action = payload.action;
switch(action.type) { switch(action.type) {
case ActionTypes.RECIEVED_PROFILES: case ActionTypes.RECIEVED_PROFILES:
for(var id in action.profiles) { for(var id in action.profiles) {
// profiles can have incomplete data, so don't overwrite current user // profiles can have incomplete data, so don't overwrite current user
if (id === UserStore.getCurrentId()) continue; if (id === UserStore.getCurrentId()) continue;
var profile = action.profiles[id]; var profile = action.profiles[id];
UserStore.saveProfile(profile); UserStore.saveProfile(profile);
UserStore.emitChange(profile.id); UserStore.emitChange(profile.id);
} }
break; break;
case ActionTypes.RECIEVED_ME: case ActionTypes.RECIEVED_ME:
UserStore.setCurrentUser(action.me); UserStore.setCurrentUser(action.me);
UserStore.emitChange(action.me.id); UserStore.emitChange(action.me.id);
break; break;
case ActionTypes.RECIEVED_SESSIONS: case ActionTypes.RECIEVED_SESSIONS:
UserStore.setSessions(action.sessions); UserStore.setSessions(action.sessions);
UserStore.emitSessionsChange(); UserStore.emitSessionsChange();
break; break;
case ActionTypes.RECIEVED_AUDITS: case ActionTypes.RECIEVED_AUDITS:
UserStore.setAudits(action.audits); UserStore.setAudits(action.audits);
UserStore.emitAuditsChange(); UserStore.emitAuditsChange();
break; break;
case ActionTypes.RECIEVED_TEAMS: case ActionTypes.RECIEVED_TEAMS:
UserStore.setTeams(action.teams); UserStore.setTeams(action.teams);
UserStore.emitTeamsChange(); UserStore.emitTeamsChange();
break; break;
case ActionTypes.RECIEVED_STATUSES: case ActionTypes.RECIEVED_STATUSES:
UserStore._setStatuses(action.statuses); UserStore._setStatuses(action.statuses);
UserStore.emitStatusesChange(); UserStore.emitStatusesChange();
break; break;
default: default:
} }
}); });
UserStore.setMaxListeners(0); UserStore.setMaxListeners(0);