Files
mostlymatter/webapp/stores/integration_store.jsx
94117nl ea095d6206 GH-6452 Migrate installed_command.jsx to be pure and use Redux (#6903)
* Migrate installed_command.jsx to be pure and use Redux

* Add test for InstalledCommand component

* Fix failing test and typo

* Whoops. Revert back deleted filter

* Add filter test

* Remove commands related code from /stores/integration_store.jsx
2017-08-03 09:25:07 -04:00

104 строки
2.5 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import EventEmitter from 'events';
const CHANGE_EVENT = 'changed';
import store from 'stores/redux_store.jsx';
class IntegrationStore extends EventEmitter {
constructor() {
super();
this.entities = {};
store.subscribe(() => {
const newEntities = store.getState().entities.integrations;
if (newEntities !== this.entities) {
this.emitChange();
}
this.entities = newEntities;
});
}
addChangeListener(callback) {
this.on(CHANGE_EVENT, callback);
}
removeChangeListener(callback) {
this.removeListener(CHANGE_EVENT, callback);
}
emitChange() {
this.emit(CHANGE_EVENT);
}
hasReceivedIncomingWebhooks(teamId) {
const hooks = store.getState().entities.integrations.incomingHooks || {};
let hasTeam = false;
Object.values(hooks).forEach((hook) => {
if (hook.team_id === teamId) {
hasTeam = true;
}
});
return hasTeam;
}
getIncomingWebhooks(teamId) {
const hooks = store.getState().entities.integrations.incomingHooks;
const teamHooks = [];
Object.values(hooks).forEach((hook) => {
if (hook.team_id === teamId) {
teamHooks.push(hook);
}
});
return teamHooks;
}
hasReceivedOutgoingWebhooks(teamId) {
const hooks = store.getState().entities.integrations.outgoingHooks;
let hasTeam = false;
Object.values(hooks).forEach((hook) => {
if (hook.team_id === teamId) {
hasTeam = true;
}
});
return hasTeam;
}
getOutgoingWebhooks(teamId) {
const hooks = store.getState().entities.integrations.outgoingHooks;
const teamHooks = [];
Object.values(hooks).forEach((hook) => {
if (hook.team_id === teamId) {
teamHooks.push(hook);
}
});
return teamHooks;
}
getOutgoingWebhook(teamId, id) {
return store.getState().entities.integrations.outgoingHooks[id];
}
hasReceivedOAuthApps() {
return Object.keys(store.getState().entities.integrations.oauthApps).length > 0;
}
getOAuthApps() {
return Object.values(store.getState().entities.integrations.oauthApps);
}
}
export default new IntegrationStore();