Move instances of Client.leaveChannel() in components to an action (#5131)

* Move instances of Client.leaveChannel() in components to an action

* create isFavoriteChannelId
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-01-20 15:45:22 +01:00
коммит произвёл Christopher Speller
родитель e8d7701b60
Коммит 6097f93704
4 изменённых файлов: 34 добавлений и 38 удалений

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

@@ -6,6 +6,7 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import * as ChannelUtils from 'utils/channel_utils.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
@@ -434,3 +435,29 @@ export function getChannelMembersForUserIds(channelId, userIds, success, error)
}
);
}
export function leaveChannel(channelId, success, error) {
Client.leaveChannel(channelId,
() => {
loadChannelsForCurrentUser();
if (ChannelUtils.isFavoriteChannelId(channelId)) {
unmarkFavorite(channelId);
}
const townsquare = ChannelStore.getByName('town-square');
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
if (success) {
success();
}
},
(err) => {
AsyncClient.dispatchError(err, 'handleLeave');
if (error) {
error(err);
}
}
);
}