summaryrefslogtreecommitdiffstats
path: root/webapp/stores
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-06-26 08:16:57 -0400
committerGitHub <noreply@github.com>2017-06-26 08:16:57 -0400
commit23ccfc845ca2350075f6027e16c6206fc7b71716 (patch)
tree3fd1f896a5a24b43913be03b21c85638dd7c356e /webapp/stores
parentfe7e9d95b30ae2195fcba68db960866db91ce045 (diff)
downloadchat-23ccfc845ca2350075f6027e16c6206fc7b71716.tar.gz
chat-23ccfc845ca2350075f6027e16c6206fc7b71716.tar.bz2
chat-23ccfc845ca2350075f6027e16c6206fc7b71716.zip
Move remaining actions over to use redux and v4 endpoints (#6720)
Diffstat (limited to 'webapp/stores')
-rw-r--r--webapp/stores/analytics_store.jsx71
-rw-r--r--webapp/stores/emoji_store.jsx70
-rw-r--r--webapp/stores/user_store.jsx6
3 files changed, 45 insertions, 102 deletions
diff --git a/webapp/stores/analytics_store.jsx b/webapp/stores/analytics_store.jsx
index 01c60b2f9..63c8a5bee 100644
--- a/webapp/stores/analytics_store.jsx
+++ b/webapp/stores/analytics_store.jsx
@@ -1,19 +1,31 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import EventEmitter from 'events';
-import Constants from 'utils/constants.jsx';
-const ActionTypes = Constants.ActionTypes;
-
const CHANGE_EVENT = 'change';
+import store from 'stores/redux_store.jsx';
+
class AnalyticsStoreClass extends EventEmitter {
constructor() {
super();
- this.systemStats = {};
- this.teamStats = {};
+
+ this.entities = {};
+
+ store.subscribe(() => {
+ const newEntities = store.getState().entities.admin;
+
+ if (newEntities.analytics !== this.entities.analytics) {
+ this.emitChange();
+ }
+
+ if (newEntities.teamAnalytics !== this.entities.teamAnalytics) {
+ this.emitChange();
+ }
+
+ this.entities = newEntities;
+ });
}
emitChange() {
@@ -29,57 +41,18 @@ class AnalyticsStoreClass extends EventEmitter {
}
getAllSystem() {
- return JSON.parse(JSON.stringify(this.systemStats));
+ return JSON.parse(JSON.stringify(store.getState().entities.admin.analytics));
}
getAllTeam(id) {
- if (id in this.teamStats) {
- return JSON.parse(JSON.stringify(this.teamStats[id]));
+ const teamStats = store.getState().entities.admin.teamAnalytics[id];
+ if (teamStats) {
+ return JSON.parse(JSON.stringify(teamStats));
}
return {};
}
-
- storeSystemStats(newStats) {
- for (const stat in newStats) {
- if (!newStats.hasOwnProperty(stat)) {
- continue;
- }
- this.systemStats[stat] = newStats[stat];
- }
- }
-
- storeTeamStats(id, newStats) {
- if (!(id in this.teamStats)) {
- this.teamStats[id] = {};
- }
-
- for (const stat in newStats) {
- if (!newStats.hasOwnProperty(stat)) {
- continue;
- }
- this.teamStats[id][stat] = newStats[stat];
- }
- }
-
}
var AnalyticsStore = new AnalyticsStoreClass();
-
-AnalyticsStore.dispatchToken = AppDispatcher.register((payload) => {
- var action = payload.action;
-
- switch (action.type) {
- case ActionTypes.RECEIVED_ANALYTICS:
- if (action.teamId == null) {
- AnalyticsStore.storeSystemStats(action.stats);
- } else {
- AnalyticsStore.storeTeamStats(action.teamId, action.stats);
- }
- AnalyticsStore.emitChange();
- break;
- default:
- }
-});
-
export default AnalyticsStore;
diff --git a/webapp/stores/emoji_store.jsx b/webapp/stores/emoji_store.jsx
index 812688995..d8af75dbc 100644
--- a/webapp/stores/emoji_store.jsx
+++ b/webapp/stores/emoji_store.jsx
@@ -1,12 +1,15 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import Client from '../client/web_client.jsx';
-import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
+import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx';
import EventEmitter from 'events';
import * as Emoji from 'utils/emoji.jsx';
+import store from 'stores/redux_store.jsx';
+import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
+import {Client4} from 'mattermost-redux/client';
+
const ActionTypes = Constants.ActionTypes;
const CHANGE_EVENT = 'changed';
@@ -72,10 +75,20 @@ class EmojiStore extends EventEmitter {
this.setMaxListeners(600);
- this.receivedCustomEmojis = false;
- this.customEmojis = new Map();
+ this.map = new EmojiMap(getCustomEmojisByName(store.getState()));
+
+ this.entities = {};
- this.map = new EmojiMap(this.customEmojis);
+ store.subscribe(() => {
+ const newEntities = store.getState().entities.emojis.customEmoji;
+
+ if (newEntities !== this.entities) {
+ this.map = new EmojiMap(getCustomEmojisByName(store.getState()));
+ this.emitChange();
+ }
+
+ this.entities = newEntities;
+ });
}
addChangeListener(callback) {
@@ -90,41 +103,12 @@ class EmojiStore extends EventEmitter {
this.emit(CHANGE_EVENT);
}
- hasReceivedCustomEmojis() {
- return this.receivedCustomEmojis;
- }
-
- setCustomEmojis(customEmojis) {
- customEmojis.sort((a, b) => a.name.localeCompare(b.name));
-
- this.customEmojis = new Map();
-
- for (const emoji of customEmojis) {
- this.addCustomEmoji(emoji);
- }
-
- this.map = new EmojiMap(this.customEmojis);
- }
-
- addCustomEmoji(emoji) {
- this.customEmojis.set(emoji.name, emoji);
- }
-
- removeCustomEmoji(id) {
- for (const [name, emoji] of this.customEmojis) {
- if (emoji.id === id) {
- this.customEmojis.delete(name);
- break;
- }
- }
- }
-
hasSystemEmoji(name) {
return Emoji.EmojiIndicesByAlias.has(name);
}
getCustomEmojiMap() {
- return this.customEmojis;
+ return getCustomEmojisByName(store.getState());
}
getEmojis() {
@@ -202,7 +186,7 @@ class EmojiStore extends EventEmitter {
getEmojiImageUrl(emoji) {
if (emoji.id) {
- return Client.getCustomEmojiImageUrl(emoji.id);
+ return Client4.getUrlVersion() + '/emoji/' + emoji.id + '/image';
}
const filename = emoji.filename || emoji.aliases[0];
@@ -214,20 +198,6 @@ class EmojiStore extends EventEmitter {
const action = payload.action;
switch (action.type) {
- case ActionTypes.RECEIVED_CUSTOM_EMOJIS:
- this.setCustomEmojis(action.emojis);
- this.receivedCustomEmojis = true;
- this.emitChange();
- break;
- case ActionTypes.RECEIVED_CUSTOM_EMOJI:
- this.addCustomEmoji(action.emoji);
- this.emitChange();
- break;
- case ActionTypes.REMOVED_CUSTOM_EMOJI:
- this.removeCustomEmoji(action.id);
- this.removeRecentEmoji(action.id);
- this.emitChange();
- break;
case ActionTypes.EMOJI_POSTED:
this.addRecentEmoji(action.alias);
this.emitChange();
diff --git a/webapp/stores/user_store.jsx b/webapp/stores/user_store.jsx
index 79052d77e..c2ea619e8 100644
--- a/webapp/stores/user_store.jsx
+++ b/webapp/stores/user_store.jsx
@@ -3,9 +3,6 @@
import EventEmitter from 'events';
-import ChannelStore from 'stores/channel_store.jsx';
-import TeamStore from 'stores/team_store.jsx';
-
import Constants from 'utils/constants.jsx';
const UserStatuses = Constants.UserStatuses;
@@ -23,6 +20,9 @@ import store from 'stores/redux_store.jsx';
import * as Selectors from 'mattermost-redux/selectors/entities/users';
import {UserTypes} from 'mattermost-redux/action_types';
+import ChannelStore from 'stores/channel_store.jsx';
+import TeamStore from 'stores/team_store.jsx';
+
var Utils;
class UserStoreClass extends EventEmitter {