Move remaining actions over to use redux and v4 endpoints (#6720)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fe7e9d95b3
Коммит
23ccfc845c
@@ -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;
|
||||
|
||||
@@ -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.map = new EmojiMap(this.customEmojis);
|
||||
this.entities = {};
|
||||
|
||||
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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user