Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buildContent = () => {
const {currentChannel} = this.props;
switch (currentChannel.type) {
default:
case General.DM_CHANNEL:
return this.buildDMContent();
case General.GM_CHANNEL:
return this.buildGMContent();
case General.OPEN_CHANNEL: {
if (currentChannel.name === General.DEFAULT_CHANNEL) {
return this.buildTownSquareContent();
}
return this.buildOpenChannelContent();
}
case General.PRIVATE_CHANNEL:
return this.buildPrivateChannelContent();
}
return (dispatch, getState) => {
const state = getState();
const {channels, myMembers} = state.entities.channels;
const {currentUserId} = state.entities.users;
const {myPreferences} = state.entities.preferences;
const lastChannelForTeam = state.views.team.lastChannelForTeam[teamId];
const lastChannelId = lastChannelForTeam && lastChannelForTeam.length ? lastChannelForTeam[0] : '';
const lastChannel = channels[lastChannelId];
const isDMVisible = lastChannel && lastChannel.type === General.DM_CHANNEL &&
isDirectChannelVisible(currentUserId, myPreferences, lastChannel);
const isGMVisible = lastChannel && lastChannel.type === General.GM_CHANNEL &&
isGroupChannelVisible(myPreferences, lastChannel);
if (
myMembers[lastChannelId] &&
lastChannel &&
(lastChannel.team_id === teamId || isDMVisible || isGMVisible)
) {
dispatch(handleSelectChannel(lastChannelId));
return;
}
dispatch(selectDefaultChannel(teamId));
};
channels = myChannels.filter((c) => {
if (c.type === General.DM_CHANNEL && (originalChannels[c.id].display_name.toLowerCase().startsWith(matchTerm))) {
return true;
}
if (c.type === General.GM_CHANNEL && (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().replace(/ /g, '').startsWith(matchTerm))) {
return true;
}
return false;
});
} else {
icon = (
);
} else if (type === General.GM_CHANNEL) {
icon = (
);
} else if (type === General.DM_CHANNEL) {
switch (status) {
case General.AWAY:
icon = (
);
break;
case General.DND:
icon = (
setTimeout(async () => {
const displayValue = {displayName: channel.display_name};
const utils = require('app/utils/general');
let result;
if (channel.type === General.DM_CHANNEL) {
result = await makeDirectChannel(channel.id, false);
if (result.error) {
const dmFailedMessage = {
id: t('mobile.open_dm.error'),
defaultMessage: "We couldn't open a direct message with {displayName}. Please check your connection and try again.",
};
utils.alertErrorWithFallback(intl, result.error, dmFailedMessage, displayValue);
}
} else {
result = await joinChannel(currentUserId, currentTeamId, channel.id);
if (result.error || !result.data || !result.data.channel) {
const joinFailedMessage = {
id: t('mobile.join_channel.error'),
defaultMessage: "We couldn't join the channel {displayName}. Please check your connection and try again.",
const directAndGroupChannelMembers = [...channels.directAndGroupChannels, ...favoriteAndUnreadDms].filter((c) => c.type === General.DM_CHANNEL).map((c) => c.teammate_id);
onUpdateChannel = async () => {
Keyboard.dismiss();
const {displayName, channelURL, purpose, header} = this.state;
const {channel: {id, type}} = this.props;
const isDirect = type === General.DM_CHANNEL || type === General.GM_CHANNEL;
const channel = {
display_name: isDirect ? '' : displayName,
name: channelURL,
purpose,
header,
};
if (!isDirect) {
let result = this.validateDisplayName(displayName.trim());
if (result.error) {
this.setState({error: result.error});
return;
}
result = this.validateChannelURL(channelURL.trim());
if (result.error) {
completeMention = () => {
const {onPress, displayName, name, type} = this.props;
if (type === General.DM_CHANNEL || type === General.GM_CHANNEL) {
onPress('@' + displayName.replace(/ /g, ''));
} else {
onPress(name);
}
};
function mapStateToProps(state) {
const currentChannel = getCurrentChannel(state);
const currentUserId = getCurrentUserId(state);
const myChannelMember = getMyCurrentChannelMembership(state);
const stats = getCurrentChannelStats(state) || {member_count: 0, guest_count: 0};
let isTeammateGuest = false;
let isSelfDMChannel = false;
if (currentChannel && currentChannel.type === General.DM_CHANNEL) {
const teammateId = getUserIdFromChannelName(currentUserId, currentChannel.name);
const teammate = getUser(state, teammateId);
isTeammateGuest = isGuest(teammate);
isSelfDMChannel = currentUserId === currentChannel.teammate_id;
}
return {
isSelfDMChannel,
currentChannelName: currentChannel ? currentChannel.display_name : '',
isArchived: currentChannel ? currentChannel.delete_at !== 0 : false,
displayName: state.views.channel.displayName,
channelType: currentChannel?.type,
isChannelMuted: isChannelMuted(myChannelMember),
theme: getTheme(state),
isGuest: isTeammateGuest,
hasGuests: stats.guest_count > 0,
render() {
const {
theme,
channelType,
deviceWidth,
deviceHeight,
displayName,
header,
purpose,
isLandscape,
} = this.props;
const {error, saving} = this.props;
const style = getStyleSheet(theme);
const displayHeaderOnly = channelType === General.DM_CHANNEL ||
channelType === General.GM_CHANNEL;
if (saving) {
return (
);
}
let displayError;
if (error) {
displayError = (