* Further cleanup and fixes Tests clean-up Tests fixed? Plays nicely with threads Tests fixed Fixes ESR and show experimental flags Failing test fixed DM Fix WIP: Bottom bar UX Fixes for unreads Failing test Always show current channel Create a channel in a category! * Unreads on top * Various fixes * Improves category collapsing * Passes correct ID through * Tests cleanup * Redo unreads and unread-button * Reverts to just using ids * More unreads back to using ids * Uses appropriate selectors for pref updates * Unreads sorted by recency * Fixes test for recency * Fixes re-rendering bug * Code review updates, websocket event debounced
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {addChannelToCategory} from '@mm-redux/actions/channel_categories';
|
|
import {createChannel} from '@mm-redux/actions/channels';
|
|
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
|
|
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
|
|
import {cleanUpUrlable} from '@mm-redux/utils/channel_utils';
|
|
import {generateId} from '@mm-redux/utils/helpers';
|
|
|
|
import {handleSelectChannel, setChannelDisplayName} from './channel';
|
|
|
|
export function generateChannelNameFromDisplayName(displayName) {
|
|
let name = cleanUpUrlable(displayName);
|
|
|
|
if (name === '') {
|
|
name = generateId();
|
|
}
|
|
|
|
return name;
|
|
}
|
|
|
|
export function handleCreateChannel(displayName, purpose, header, type, categoryId) {
|
|
return async (dispatch, getState) => {
|
|
const state = getState();
|
|
const currentUserId = getCurrentUserId(state);
|
|
const teamId = getCurrentTeamId(state);
|
|
const channel = {
|
|
team_id: teamId,
|
|
name: generateChannelNameFromDisplayName(displayName),
|
|
display_name: displayName,
|
|
purpose,
|
|
header,
|
|
type,
|
|
};
|
|
|
|
const {data} = await dispatch(createChannel(channel, currentUserId));
|
|
if (data && data.id) {
|
|
dispatch(setChannelDisplayName(displayName));
|
|
dispatch(handleSelectChannel(data.id));
|
|
|
|
if (categoryId) {
|
|
dispatch(addChannelToCategory(categoryId, data.id));
|
|
}
|
|
}
|
|
};
|
|
}
|