import { h } from 'preact'; import PropTypes from 'prop-types'; import ConfigImage from 'images/three-dots.svg'; import GroupImage from 'images/organization.svg'; const Channels = ({ activeChannelId, chatChannels, handleSwitchChannel, expanded, filterQuery, channelsLoaded, incomingVideoCallChannelIds, }) => { const channels = chatChannels.map(channel => { if (!channel) { return; } const isActive = parseInt(activeChannelId, 10) === channel.id; let lastOpened = channel.last_opened_at; if (!lastOpened) { if (channel.channel_users[window.currentUser.username]) { lastOpened = channel.channel_users[window.currentUser.username].last_opened_at; } else { lastOpened = new Date(); } } const isUnopened = new Date(channel.last_message_at) > new Date(lastOpened) && channel.messages_count > 0; const otherClassname = isActive ? 'chatchanneltab--active' : 'chatchanneltab--inactive'; const name = channel.channel_type === 'direct' ? `@${channel.slug .replace(`${window.currentUser.username}/`, '') .replace(`/${window.currentUser.username}`, '')}` : channel.channel_name; const newMessagesIndicatorClass = isUnopened ? 'new' : 'old'; const modififedSlug = channel.channel_type === 'direct' ? name : channel.slug; const indicatorPic = channel.channel_type === 'direct' ? ( {channel.channel_name} ) : ( {channel.channel_name} ); let channelColor = 'transparent'; if (channel.channel_type === 'direct' && isActive) { channelColor = channel.channel_users[name.replace('@', '')].darker_color; } else if (isActive) { channelColor = '#4e57ef'; } let content = ''; const contentInner = ( {indicatorPic} ); if (expanded) { content = ( {contentInner} {name} ); } else if (channel.channel_type === 'direct') { content = contentInner; } else { content = name; } let callIndicator = ''; if ( incomingVideoCallChannelIds && incomingVideoCallChannelIds.includes(channel.id) ) { callIndicator = ( 📞 ); } return ( ); }); let channelsListFooter = ''; if (channels.length === 30) { channelsListFooter = (
...
); } let topNotice = ''; if ( expanded && filterQuery.length === 0 && channelsLoaded && (channels.length === 0 || channels[0].messages_count === 0) ) { topNotice = (
👋 {' '} Welcome to DEV Connect ! You may message anyone you mutually follow.
); } let configFooter = ''; if (expanded) { configFooter = (
DEV Settings Report Abuse
); } return (
{topNotice} {channels} {channelsListFooter}
{configFooter}
); }; Channels.propTypes = { activeChannelId: PropTypes.number.isRequired, chatChannels: PropTypes.array.isRequired, handleSwitchChannel: PropTypes.func.isRequired, expanded: PropTypes.bool.isRequired, filterQuery: PropTypes.string.isRequired, channelsLoaded: PropTypes.bool.isRequired, incomingVideoCallChannelIds: PropTypes.array.isRequired, }; export default Channels;