summaryrefslogtreecommitdiffstats
path: root/web/react/stores
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/stores')
-rw-r--r--web/react/stores/post_store.jsx357
-rw-r--r--web/react/stores/user_store.jsx447
2 files changed, 404 insertions, 400 deletions
diff --git a/web/react/stores/post_store.jsx b/web/react/stores/post_store.jsx
index ecf54ede6..9ebdf734c 100644
--- a/web/react/stores/post_store.jsx
+++ b/web/react/stores/post_store.jsx
@@ -6,7 +6,6 @@ var EventEmitter = require('events').EventEmitter;
var assign = require('object-assign');
var ChannelStore = require('../stores/channel_store.jsx');
-var UserStore = require('../stores/user_store.jsx');
var BrowserStore = require('../stores/browser_store.jsx');
var Constants = require('../utils/constants.jsx');
@@ -21,185 +20,187 @@ var ADD_MENTION_EVENT = 'add_mention';
var PostStore = assign({}, EventEmitter.prototype, {
- emitChange: function() {
- this.emit(CHANGE_EVENT);
- },
-
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
-
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
-
- emitSearchChange: function() {
- this.emit(SEARCH_CHANGE_EVENT);
- },
-
- addSearchChangeListener: function(callback) {
- this.on(SEARCH_CHANGE_EVENT, callback);
- },
-
- removeSearchChangeListener: function(callback) {
- this.removeListener(SEARCH_CHANGE_EVENT, callback);
- },
-
- emitSearchTermChange: function(doSearch, isMentionSearch) {
- this.emit(SEARCH_TERM_CHANGE_EVENT, doSearch, isMentionSearch);
- },
-
- addSearchTermChangeListener: function(callback) {
- this.on(SEARCH_TERM_CHANGE_EVENT, callback);
- },
-
- removeSearchTermChangeListener: function(callback) {
- this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback);
- },
-
- emitSelectedPostChange: function(from_search) {
- this.emit(SELECTED_POST_CHANGE_EVENT, from_search);
- },
-
- addSelectedPostChangeListener: function(callback) {
- this.on(SELECTED_POST_CHANGE_EVENT, callback);
- },
-
- removeSelectedPostChangeListener: function(callback) {
- this.removeListener(SELECTED_POST_CHANGE_EVENT, callback);
- },
-
- emitMentionDataChange: function(id, mentionText, excludeList) {
- this.emit(MENTION_DATA_CHANGE_EVENT, id, mentionText, excludeList);
- },
-
- addMentionDataChangeListener: function(callback) {
- this.on(MENTION_DATA_CHANGE_EVENT, callback);
- },
-
- removeMentionDataChangeListener: function(callback) {
- this.removeListener(MENTION_DATA_CHANGE_EVENT, callback);
- },
-
- emitAddMention: function(id, username) {
- this.emit(ADD_MENTION_EVENT, id, username);
- },
-
- addAddMentionListener: function(callback) {
- this.on(ADD_MENTION_EVENT, callback);
- },
-
- removeAddMentionListener: function(callback) {
- this.removeListener(ADD_MENTION_EVENT, callback);
- },
-
- getCurrentPosts: function() {
- var currentId = ChannelStore.getCurrentId();
-
- if (currentId != null)
- return this.getPosts(currentId);
- else
- return null;
- },
- storePosts: function(channelId, posts) {
- this._storePosts(channelId, posts);
- this.emitChange();
- },
- _storePosts: function(channelId, posts) {
- BrowserStore.setItem("posts_" + channelId, posts);
- },
- getPosts: function(channelId) {
- return BrowserStore.getItem("posts_" + channelId);
- },
- storeSearchResults: function(results, is_mention_search) {
- BrowserStore.setItem("search_results", results);
- is_mention_search = is_mention_search ? true : false; // force to bool
- BrowserStore.setItem("is_mention_search", is_mention_search);
- },
- getSearchResults: function() {
- return BrowserStore.getItem("search_results");
- },
- getIsMentionSearch: function() {
- return BrowserStore.getItem("is_mention_search");
- },
- storeSelectedPost: function(post_list) {
- BrowserStore.setItem("select_post", post_list);
- },
- getSelectedPost: function() {
- return BrowserStore.getItem("select_post");
- },
- storeSearchTerm: function(term) {
- BrowserStore.setItem("search_term", term);
- },
- getSearchTerm: function() {
- return BrowserStore.getItem("search_term");
- },
- storeCurrentDraft: function(draft) {
- var channel_id = ChannelStore.getCurrentId();
- BrowserStore.setItem("draft_" + channel_id, draft);
- },
- getCurrentDraft: function() {
- var channel_id = ChannelStore.getCurrentId();
- return BrowserStore.getItem("draft_" + channel_id);
- },
- storeDraft: function(channel_id, draft) {
- BrowserStore.setItem("draft_" + channel_id, draft);
- },
- getDraft: function(channel_id) {
- return BrowserStore.getItem("draft_" + channel_id);
- },
- storeCommentDraft: function(parent_post_id, draft) {
- BrowserStore.setItem("comment_draft_" + parent_post_id, draft);
- },
- getCommentDraft: function(parent_post_id) {
- return BrowserStore.getItem("comment_draft_" + parent_post_id);
- },
- clearDraftUploads: function() {
- BrowserStore.actionOnItemsWithPrefix("draft_", function (key, value) {
- if (value) {
- value.uploadsInProgress = 0;
- BrowserStore.setItem(key, value);
- }
- });
- },
- clearCommentDraftUploads: function() {
- BrowserStore.actionOnItemsWithPrefix("comment_draft_", function (key, value) {
- if (value) {
- value.uploadsInProgress = 0;
- BrowserStore.setItem(key, value);
- }
- });
- }
+ emitChange: function emitChange() {
+ this.emit(CHANGE_EVENT);
+ },
+
+ addChangeListener: function addChangeListener(callback) {
+ this.on(CHANGE_EVENT, callback);
+ },
+
+ removeChangeListener: function removeChangeListener(callback) {
+ this.removeListener(CHANGE_EVENT, callback);
+ },
+
+ emitSearchChange: function emitSearchChange() {
+ this.emit(SEARCH_CHANGE_EVENT);
+ },
+
+ addSearchChangeListener: function addSearchChangeListener(callback) {
+ this.on(SEARCH_CHANGE_EVENT, callback);
+ },
+
+ removeSearchChangeListener: function removeSearchChangeListener(callback) {
+ this.removeListener(SEARCH_CHANGE_EVENT, callback);
+ },
+
+ emitSearchTermChange: function emitSearchTermChange(doSearch, isMentionSearch) {
+ this.emit(SEARCH_TERM_CHANGE_EVENT, doSearch, isMentionSearch);
+ },
+
+ addSearchTermChangeListener: function addSearchTermChangeListener(callback) {
+ this.on(SEARCH_TERM_CHANGE_EVENT, callback);
+ },
+
+ removeSearchTermChangeListener: function removeSearchTermChangeListener(callback) {
+ this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback);
+ },
+
+ emitSelectedPostChange: function emitSelectedPostChange(fromSearch) {
+ this.emit(SELECTED_POST_CHANGE_EVENT, fromSearch);
+ },
+
+ addSelectedPostChangeListener: function addSelectedPostChangeListener(callback) {
+ this.on(SELECTED_POST_CHANGE_EVENT, callback);
+ },
+
+ removeSelectedPostChangeListener: function removeSelectedPostChangeListener(callback) {
+ this.removeListener(SELECTED_POST_CHANGE_EVENT, callback);
+ },
+
+ emitMentionDataChange: function emitMentionDataChange(id, mentionText) {
+ this.emit(MENTION_DATA_CHANGE_EVENT, id, mentionText);
+ },
+
+ addMentionDataChangeListener: function addMentionDataChangeListener(callback) {
+ this.on(MENTION_DATA_CHANGE_EVENT, callback);
+ },
+
+ removeMentionDataChangeListener: function removeMentionDataChangeListener(callback) {
+ this.removeListener(MENTION_DATA_CHANGE_EVENT, callback);
+ },
+
+ emitAddMention: function emitAddMention(id, username) {
+ this.emit(ADD_MENTION_EVENT, id, username);
+ },
+
+ addAddMentionListener: function addAddMentionListener(callback) {
+ this.on(ADD_MENTION_EVENT, callback);
+ },
+
+ removeAddMentionListener: function removeAddMentionListener(callback) {
+ this.removeListener(ADD_MENTION_EVENT, callback);
+ },
+
+ getCurrentPosts: function getCurrentPosts() {
+ var currentId = ChannelStore.getCurrentId();
+
+ if (currentId != null) {
+ return this.getPosts(currentId);
+ }
+ return null;
+ },
+ storePosts: function storePosts(channelId, posts) {
+ this.pStorePosts(channelId, posts);
+ this.emitChange();
+ },
+ pStorePosts: function pStorePosts(channelId, posts) {
+ BrowserStore.setItem('posts_' + channelId, posts);
+ },
+ getPosts: function getPosts(channelId) {
+ return BrowserStore.getItem('posts_' + channelId);
+ },
+ storeSearchResults: function storeSearchResults(results, isMentionSearch) {
+ BrowserStore.setItem('search_results', results);
+ BrowserStore.setItem('is_mention_search', Boolean(isMentionSearch));
+ },
+ getSearchResults: function getSearchResults() {
+ return BrowserStore.getItem('search_results');
+ },
+ getIsMentionSearch: function getIsMentionSearch() {
+ return BrowserStore.getItem('is_mention_search');
+ },
+ storeSelectedPost: function storeSelectedPost(postList) {
+ BrowserStore.setItem('select_post', postList);
+ },
+ getSelectedPost: function getSelectedPost() {
+ return BrowserStore.getItem('select_post');
+ },
+ storeSearchTerm: function storeSearchTerm(term) {
+ BrowserStore.setItem('search_term', term);
+ },
+ getSearchTerm: function getSearchTerm() {
+ return BrowserStore.getItem('search_term');
+ },
+ getEmptyDraft: function getEmptyDraft(draft) {
+ return {message: '', uploadsInProgress: [], previews: []};
+ },
+ storeCurrentDraft: function storeCurrentDraft(draft) {
+ var channelId = ChannelStore.getCurrentId();
+ BrowserStore.setItem('draft_' + channelId, draft);
+ },
+ getCurrentDraft: function getCurrentDraft() {
+ var channelId = ChannelStore.getCurrentId();
+ return PostStore.getDraft(channelId);
+ },
+ storeDraft: function storeDraft(channelId, draft) {
+ BrowserStore.setItem('draft_' + channelId, draft);
+ },
+ getDraft: function getDraft(channelId) {
+ return BrowserStore.getItem('draft_' + channelId, PostStore.getEmptyDraft());
+ },
+ storeCommentDraft: function storeCommentDraft(parentPostId, draft) {
+ BrowserStore.setItem('comment_draft_' + parentPostId, draft);
+ },
+ getCommentDraft: function getCommentDraft(parentPostId) {
+ return BrowserStore.getItem('comment_draft_' + parentPostId, PostStore.getEmptyDraft());
+ },
+ clearDraftUploads: function clearDraftUploads() {
+ BrowserStore.actionOnItemsWithPrefix('draft_', function clearUploads(key, value) {
+ if (value) {
+ value.uploadsInProgress = [];
+ BrowserStore.setItem(key, value);
+ }
+ });
+ },
+ clearCommentDraftUploads: function clearCommentDraftUploads() {
+ BrowserStore.actionOnItemsWithPrefix('comment_draft_', function clearUploads(key, value) {
+ if (value) {
+ value.uploadsInProgress = [];
+ BrowserStore.setItem(key, value);
+ }
+ });
+ }
});
-PostStore.dispatchToken = AppDispatcher.register(function(payload) {
- var action = payload.action;
-
- switch(action.type) {
- case ActionTypes.RECIEVED_POSTS:
- PostStore._storePosts(action.id, action.post_list);
- PostStore.emitChange();
- break;
- case ActionTypes.RECIEVED_SEARCH:
- PostStore.storeSearchResults(action.results, action.is_mention_search);
- PostStore.emitSearchChange();
- break;
- case ActionTypes.RECIEVED_SEARCH_TERM:
- PostStore.storeSearchTerm(action.term);
- PostStore.emitSearchTermChange(action.do_search, action.is_mention_search);
- break;
- case ActionTypes.RECIEVED_POST_SELECTED:
- PostStore.storeSelectedPost(action.post_list);
- PostStore.emitSelectedPostChange(action.from_search);
- break;
- case ActionTypes.RECIEVED_MENTION_DATA:
- PostStore.emitMentionDataChange(action.id, action.mention_text, action.exclude_list);
- break;
- case ActionTypes.RECIEVED_ADD_MENTION:
- PostStore.emitAddMention(action.id, action.username);
- break;
- default:
- }
+PostStore.dispatchToken = AppDispatcher.register(function registry(payload) {
+ var action = payload.action;
+
+ switch (action.type) {
+ case ActionTypes.RECIEVED_POSTS:
+ PostStore.pStorePosts(action.id, action.post_list);
+ PostStore.emitChange();
+ break;
+ case ActionTypes.RECIEVED_SEARCH:
+ PostStore.storeSearchResults(action.results, action.is_mention_search);
+ PostStore.emitSearchChange();
+ break;
+ case ActionTypes.RECIEVED_SEARCH_TERM:
+ PostStore.storeSearchTerm(action.term);
+ PostStore.emitSearchTermChange(action.do_search, action.is_mention_search);
+ break;
+ case ActionTypes.RECIEVED_POST_SELECTED:
+ PostStore.storeSelectedPost(action.post_list);
+ PostStore.emitSelectedPostChange(action.from_search);
+ break;
+ case ActionTypes.RECIEVED_MENTION_DATA:
+ PostStore.emitMentionDataChange(action.id, action.mention_text);
+ break;
+ case ActionTypes.RECIEVED_ADD_MENTION:
+ PostStore.emitAddMention(action.id, action.username);
+ break;
+ default:
+ }
});
module.exports = PostStore;
diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index aff5a0bed..f8616c6ab 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -4,7 +4,6 @@
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var EventEmitter = require('events').EventEmitter;
var assign = require('object-assign');
-var client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
@@ -18,244 +17,248 @@ var CHANGE_EVENT_STATUSES = 'change_statuses';
var UserStore = assign({}, EventEmitter.prototype, {
- _current_id: null,
+ gCurrentId: null,
- emitChange: function(userId) {
- this.emit(CHANGE_EVENT, userId);
- },
- addChangeListener: function(callback) {
- this.on(CHANGE_EVENT, callback);
- },
- removeChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT, callback);
- },
- emitSessionsChange: function() {
- this.emit(CHANGE_EVENT_SESSIONS);
- },
- addSessionsChangeListener: function(callback) {
- this.on(CHANGE_EVENT_SESSIONS, callback);
- },
- removeSessionsChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT_SESSIONS, callback);
- },
- emitAuditsChange: function() {
- this.emit(CHANGE_EVENT_AUDITS);
- },
- addAuditsChangeListener: function(callback) {
- this.on(CHANGE_EVENT_AUDITS, callback);
- },
- removeAuditsChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT_AUDITS, callback);
- },
- emitTeamsChange: function() {
- this.emit(CHANGE_EVENT_TEAMS);
- },
- addTeamsChangeListener: function(callback) {
- this.on(CHANGE_EVENT_TEAMS, callback);
- },
- removeTeamsChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT_TEAMS, callback);
- },
- emitStatusesChange: function() {
- this.emit(CHANGE_EVENT_STATUSES);
- },
- addStatusesChangeListener: function(callback) {
- this.on(CHANGE_EVENT_STATUSES, callback);
- },
- removeStatusesChangeListener: function(callback) {
- this.removeListener(CHANGE_EVENT_STATUSES, callback);
- },
- setCurrentId: function(id) {
- this._current_id = id;
- if (id == null) {
- BrowserStore.removeGlobalItem("current_user_id");
- } else {
- BrowserStore.setGlobalItem("current_user_id", id);
- }
- },
- getCurrentId: function(skipFetch) {
- var current_id = this._current_id;
+ emitChange: function(userId) {
+ this.emit(CHANGE_EVENT, userId);
+ },
+ addChangeListener: function(callback) {
+ this.on(CHANGE_EVENT, callback);
+ },
+ removeChangeListener: function(callback) {
+ this.removeListener(CHANGE_EVENT, callback);
+ },
+ emitSessionsChange: function() {
+ this.emit(CHANGE_EVENT_SESSIONS);
+ },
+ addSessionsChangeListener: function(callback) {
+ this.on(CHANGE_EVENT_SESSIONS, callback);
+ },
+ removeSessionsChangeListener: function(callback) {
+ this.removeListener(CHANGE_EVENT_SESSIONS, callback);
+ },
+ emitAuditsChange: function() {
+ this.emit(CHANGE_EVENT_AUDITS);
+ },
+ addAuditsChangeListener: function(callback) {
+ this.on(CHANGE_EVENT_AUDITS, callback);
+ },
+ removeAuditsChangeListener: function(callback) {
+ this.removeListener(CHANGE_EVENT_AUDITS, callback);
+ },
+ emitTeamsChange: function() {
+ this.emit(CHANGE_EVENT_TEAMS);
+ },
+ addTeamsChangeListener: function(callback) {
+ this.on(CHANGE_EVENT_TEAMS, callback);
+ },
+ removeTeamsChangeListener: function(callback) {
+ this.removeListener(CHANGE_EVENT_TEAMS, callback);
+ },
+ emitStatusesChange: function() {
+ this.emit(CHANGE_EVENT_STATUSES);
+ },
+ addStatusesChangeListener: function(callback) {
+ this.on(CHANGE_EVENT_STATUSES, callback);
+ },
+ removeStatusesChangeListener: function(callback) {
+ this.removeListener(CHANGE_EVENT_STATUSES, callback);
+ },
+ setCurrentId: function(id) {
+ this.gCurrentId = id;
+ if (id == null) {
+ BrowserStore.removeGlobalItem('current_user_id');
+ } else {
+ BrowserStore.setGlobalItem('current_user_id', id);
+ }
+ },
+ getCurrentId: function() {
+ var currentId = this.gCurrentId;
- if (current_id == null) {
- current_id = BrowserStore.getGlobalItem("current_user_id");
- }
+ if (currentId == null) {
+ currentId = BrowserStore.getGlobalItem('current_user_id');
+ this.gCurrentId = currentId;
+ }
- // this is a speical case to force fetch the
- // current user if it's missing
- // it's synchronous to block rendering
- if (current_id == null && !skipFetch) {
- var me = client.getMeSynchronous();
- if (me != null) {
- this.setCurrentUser(me);
- current_id = me.id;
- }
- }
+ return currentId;
+ },
+ getCurrentUser: function() {
+ if (this.getCurrentId() == null) {
+ return null;
+ }
- return current_id;
- },
- getCurrentUser: function(skipFetch) {
- if (this.getCurrentId(skipFetch) == null) {
- return null;
- }
+ return this._getProfiles()[this.getCurrentId()];
+ },
+ setCurrentUser: function(user) {
+ this.setCurrentId(user.id);
+ this.saveProfile(user);
+ },
+ getLastEmail: function() {
+ return BrowserStore.getItem('last_email', '');
+ },
+ setLastEmail: function(email) {
+ BrowserStore.setItem('last_email', email);
+ },
+ removeCurrentUser: function() {
+ this.setCurrentId(null);
+ },
+ hasProfile: function(userId) {
+ return this._getProfiles()[userId] != null;
+ },
+ getProfile: function(userId) {
+ return this._getProfiles()[userId];
+ },
+ getProfileByUsername: function(username) {
+ return this._getProfilesUsernameMap()[username];
+ },
+ getProfilesUsernameMap: function() {
+ return this._getProfilesUsernameMap();
+ },
+ getProfiles: function() {
- return this._getProfiles()[this.getCurrentId()];
- },
- setCurrentUser: function(user) {
- this.setCurrentId(user.id);
- this.saveProfile(user);
- },
- getLastEmail: function() {
- return BrowserStore.getItem("last_email", '');
- },
- setLastEmail: function(email) {
- BrowserStore.setItem("last_email", email);
- },
- removeCurrentUser: function() {
- this.setCurrentId(null);
- },
- hasProfile: function(userId) {
- return this._getProfiles()[userId] != null;
- },
- getProfile: function(userId) {
- return this._getProfiles()[userId];
- },
- getProfileByUsername: function(username) {
- return this._getProfilesUsernameMap()[username];
- },
- getProfilesUsernameMap: function() {
- return this._getProfilesUsernameMap();
- },
- getProfiles: function() {
+ return this._getProfiles();
+ },
+ getActiveOnlyProfiles: function() {
+ var active = {};
+ var current = this._getProfiles();
- return this._getProfiles();
- },
- getActiveOnlyProfiles: function() {
- active = {};
- current = this._getProfiles();
+ for (var key in current) {
+ if (current[key].delete_at === 0) {
+ active[key] = current[key];
+ }
+ }
- for (var key in current) {
- if (current[key].delete_at == 0) {
- active[key] = current[key];
- }
- }
+ return active;
+ },
+ saveProfile: function(profile) {
+ var ps = this._getProfiles();
+ ps[profile.id] = profile;
+ this._storeProfiles(ps);
+ },
+ _storeProfiles: function(profiles) {
+ BrowserStore.setItem('profiles', profiles);
+ var profileUsernameMap = {};
+ for (var id in profiles) {
+ profileUsernameMap[profiles[id].username] = profiles[id];
+ }
+ BrowserStore.setItem('profileUsernameMap', profileUsernameMap);
+ },
+ _getProfiles: function() {
+ return BrowserStore.getItem('profiles', {});
+ },
+ _getProfilesUsernameMap: function() {
+ return BrowserStore.getItem('profileUsernameMap', {});
+ },
+ setSessions: function(sessions) {
+ BrowserStore.setItem('sessions', sessions);
+ },
+ getSessions: function() {
+ return BrowserStore.getItem('sessions', {loading: true});
+ },
+ setAudits: function(audits) {
+ BrowserStore.setItem('audits', audits);
+ },
+ getAudits: function() {
+ return BrowserStore.getItem('audits', {loading: true});
+ },
+ setTeams: function(teams) {
+ BrowserStore.setItem('teams', teams);
+ },
+ getTeams: function() {
+ return BrowserStore.getItem('teams', []);
+ },
+ getCurrentMentionKeys: function() {
+ var user = this.getCurrentUser();
- return active;
- },
- saveProfile: function(profile) {
- var ps = this._getProfiles();
- ps[profile.id] = profile;
- this._storeProfiles(ps);
- },
- _storeProfiles: function(profiles) {
- BrowserStore.setItem("profiles", profiles);
- var profileUsernameMap = {};
- for (var id in profiles) {
- profileUsernameMap[profiles[id].username] = profiles[id];
- }
- BrowserStore.setItem("profileUsernameMap", profileUsernameMap);
- },
- _getProfiles: function() {
- return BrowserStore.getItem("profiles", {});
- },
- _getProfilesUsernameMap: function() {
- return BrowserStore.getItem("profileUsernameMap", {});
- },
- setSessions: function(sessions) {
- BrowserStore.setItem("sessions", sessions);
- },
- getSessions: function() {
- return BrowserStore.getItem("sessions", {loading: true});
- },
- setAudits: function(audits) {
- BrowserStore.setItem("audits", audits);
- },
- getAudits: function() {
- return BrowserStore.getItem("audits", {loading: true});
- },
- setTeams: function(teams) {
- BrowserStore.setItem("teams", teams);
- },
- getTeams: function() {
- return BrowserStore.getItem("teams", []);
- },
- getCurrentMentionKeys: function() {
- var user = this.getCurrentUser();
+ var keys = [];
- var keys = [];
+ if (!user || !user.notify_props) {
+ return keys;
+ }
- if (!user)
- return keys;
+ if (user.notify_props.mention_keys) {
+ keys = keys.concat(user.notify_props.mention_keys.split(','));
+ }
- 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.notify_props.first_name === 'true' && user.first_name) {
+ keys.push(user.first_name);
+ }
- return keys;
- },
- getLastVersion: function() {
- return BrowserStore.getItem("last_version", '');
- },
- setLastVersion: function(version) {
- BrowserStore.setItem("last_version", version);
- },
- setStatuses: function(statuses) {
- this._setStatuses(statuses);
- this.emitStatusesChange();
- },
- _setStatuses: function(statuses) {
- BrowserStore.setItem("statuses", statuses);
- },
- setStatus: function(user_id, status) {
- var statuses = this.getStatuses();
- statuses[user_id] = status;
- this._setStatuses(statuses);
- this.emitStatusesChange();
- },
- getStatuses: function() {
- return BrowserStore.getItem("statuses", {});
- },
- getStatus: function(id) {
- return this.getStatuses()[id];
- }
+ if (user.notify_props.all === 'true') {
+ keys.push('@all');
+ }
+
+ if (user.notify_props.channel === 'true') {
+ keys.push('@channel');
+ }
+
+ return keys;
+ },
+ getLastVersion: function() {
+ return BrowserStore.getItem('last_version', '');
+ },
+ setLastVersion: function(version) {
+ BrowserStore.setItem('last_version', version);
+ },
+ setStatuses: function(statuses) {
+ this._setStatuses(statuses);
+ this.emitStatusesChange();
+ },
+ _setStatuses: function(statuses) {
+ BrowserStore.setItem('statuses', statuses);
+ },
+ setStatus: function(userId, status) {
+ var statuses = this.getStatuses();
+ statuses[userId] = status;
+ this._setStatuses(statuses);
+ this.emitStatusesChange();
+ },
+ getStatuses: function() {
+ return BrowserStore.getItem('statuses', {});
+ },
+ getStatus: function(id) {
+ return this.getStatuses()[id];
+ }
});
UserStore.dispatchToken = AppDispatcher.register(function(payload) {
- var action = payload.action;
+ var action = payload.action;
- switch(action.type) {
- case ActionTypes.RECIEVED_PROFILES:
- for(var id in action.profiles) {
- // profiles can have incomplete data, so don't overwrite current user
- if (id === UserStore.getCurrentId()) continue;
- var profile = action.profiles[id];
- UserStore.saveProfile(profile);
- UserStore.emitChange(profile.id);
- }
- break;
- case ActionTypes.RECIEVED_ME:
- UserStore.setCurrentUser(action.me);
- UserStore.emitChange(action.me.id);
- break;
- case ActionTypes.RECIEVED_SESSIONS:
- UserStore.setSessions(action.sessions);
- UserStore.emitSessionsChange();
- break;
- case ActionTypes.RECIEVED_AUDITS:
- UserStore.setAudits(action.audits);
- UserStore.emitAuditsChange();
- break;
- case ActionTypes.RECIEVED_TEAMS:
- UserStore.setTeams(action.teams);
- UserStore.emitTeamsChange();
- break;
- case ActionTypes.RECIEVED_STATUSES:
- UserStore._setStatuses(action.statuses);
- UserStore.emitStatusesChange();
- break;
+ switch (action.type) {
+ case ActionTypes.RECIEVED_PROFILES:
+ for (var id in action.profiles) {
+ // profiles can have incomplete data, so don't overwrite current user
+ if (id === UserStore.getCurrentId()) {
+ continue;
+ }
+ var profile = action.profiles[id];
+ UserStore.saveProfile(profile);
+ UserStore.emitChange(profile.id);
+ }
+ break;
+ case ActionTypes.RECIEVED_ME:
+ UserStore.setCurrentUser(action.me);
+ UserStore.emitChange(action.me.id);
+ break;
+ case ActionTypes.RECIEVED_SESSIONS:
+ UserStore.setSessions(action.sessions);
+ UserStore.emitSessionsChange();
+ break;
+ case ActionTypes.RECIEVED_AUDITS:
+ UserStore.setAudits(action.audits);
+ UserStore.emitAuditsChange();
+ break;
+ case ActionTypes.RECIEVED_TEAMS:
+ UserStore.setTeams(action.teams);
+ UserStore.emitTeamsChange();
+ break;
+ case ActionTypes.RECIEVED_STATUSES:
+ UserStore._setStatuses(action.statuses);
+ UserStore.emitStatusesChange();
+ break;
- default:
- }
+ default:
+ }
});
UserStore.setMaxListeners(0);