PLT-6214 Move channel store and actions over to redux (#6235)

* Move channel store and actions over to redux

* Fix style errors

* Fix unit test

* Various fixes

* More fixes

* Revert config changes
Этот коммит содержится в:
Joram Wilander
2017-04-28 13:16:03 -04:00
коммит произвёл Christopher Speller
родитель 302ec17bee
Коммит 96906482ce
30 изменённых файлов: 499 добавлений и 691 удалений

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

@@ -2,10 +2,8 @@
// See License.txt for license information.
import BrowserStore from 'stores/browser_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import ErrorStore from 'stores/error_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
@@ -62,233 +60,6 @@ export function checkVersion() {
}
}
export function getChannels() {
return new Promise((resolve, reject) => {
if (isCallInProgress('getChannels')) {
resolve();
return;
}
callTracker.getChannels = utils.getTimestamp();
Client.getChannels(
(data) => {
callTracker.getChannels = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNELS,
channels: data
});
resolve();
},
(err) => {
callTracker.getChannels = 0;
dispatchError(err, 'getChannels');
reject(new Error('Unable to getChannels'));
}
);
});
}
export function getChannel(id) {
if (isCallInProgress('getChannel' + id)) {
return;
}
callTracker['getChannel' + id] = utils.getTimestamp();
Client.getChannel(id,
(data) => {
callTracker['getChannel' + id] = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data.channel,
member: data.member
});
},
(err) => {
callTracker['getChannel' + id] = 0;
dispatchError(err, 'getChannel');
}
);
}
export function getMyChannelMembers() {
return new Promise((resolve, reject) => {
if (isCallInProgress('getMyChannelMembers')) {
resolve();
return;
}
callTracker.getMyChannelMembers = utils.getTimestamp();
Client.getMyChannelMembers(
(data) => {
callTracker.getMyChannelMembers = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
members: data
});
resolve();
},
(err) => {
callTracker.getMyChannelMembers = 0;
dispatchError(err, 'getMyChannelMembers');
reject(new Error('Unable to getMyChannelMembers'));
}
);
});
}
export function getMyChannelMembersForTeam(teamId) {
return new Promise((resolve, reject) => {
if (isCallInProgress(`getMyChannelMembers${teamId}`)) {
resolve();
return;
}
callTracker[`getMyChannelMembers${teamId}`] = utils.getTimestamp();
Client.getMyChannelMembersForTeam(
teamId,
(data) => {
callTracker[`getMyChannelMembers${teamId}`] = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
members: data
});
resolve();
},
(err) => {
callTracker[`getMyChannelMembers${teamId}`] = 0;
dispatchError(err, 'getMyChannelMembersForTeam');
reject(new Error('Unable to getMyChannelMembersForTeam'));
}
);
});
}
export function viewChannel(channelId = ChannelStore.getCurrentId(), prevChannelId = '', time = 0) {
if (channelId == null || !Client.teamId) {
return;
}
if (isCallInProgress(`viewChannel${channelId}`)) {
return;
}
callTracker[`viewChannel${channelId}`] = utils.getTimestamp();
Client.viewChannel(
channelId,
prevChannelId,
time,
() => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_PREFERENCE,
preference: {
category: 'last',
name: TeamStore.getCurrentId(),
value: channelId
}
});
callTracker[`viewChannel${channelId}`] = 0;
ErrorStore.clearLastError();
},
(err) => {
callTracker[`viewChannel${channelId}`] = 0;
const count = ErrorStore.getConnectionErrorCount();
ErrorStore.setConnectionErrorCount(count + 1);
dispatchError(err, 'viewChannel');
}
);
}
export function getMoreChannelsPage(offset, limit) {
if (isCallInProgress('getMoreChannelsPage')) {
return;
}
callTracker.getMoreChannelsPage = utils.getTimestamp();
Client.getMoreChannelsPage(
offset,
limit,
(data) => {
callTracker.getMoreChannelsPage = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_MORE_CHANNELS,
channels: data
});
},
(err) => {
callTracker.getMoreChannelsPage = 0;
dispatchError(err, 'getMoreChannelsPage');
}
);
}
export function getChannelStats(channelId = ChannelStore.getCurrentId(), doVersionCheck = false) {
if (isCallInProgress('getChannelStats' + channelId) || channelId == null) {
return;
}
callTracker['getChannelStats' + channelId] = utils.getTimestamp();
Client.getChannelStats(
channelId,
(data) => {
callTracker['getChannelStats' + channelId] = 0;
if (doVersionCheck) {
checkVersion();
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL_STATS,
stats: data
});
},
(err) => {
callTracker['getChannelStats' + channelId] = 0;
dispatchError(err, 'getChannelStats');
}
);
}
export function getChannelMember(channelId, userId) {
return new Promise((resolve, reject) => {
if (isCallInProgress(`getChannelMember${channelId}${userId}`)) {
resolve();
return;
}
callTracker[`getChannelMember${channelId}${userId}`] = utils.getTimestamp();
Client.getChannelMember(
channelId,
userId,
(data) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL_MEMBER,
member: data
});
resolve();
},
(err) => {
callTracker[`getChannelMember${channelId}${userId}`] = 0;
dispatchError(err, 'getChannelMember');
reject(new Error('Unable to getChannelMeber'));
}
);
});
}
export function getUser(userId, success, error) {
const callName = `getUser${userId}`;