* Feature 🚀 : Ability to delete messages in chat channels - Sending message ID to frontend - Deleting Message - Use pusher to delete message realtime * Minor Bug 🐞: Show message action only for current user - User can delete or edit their own messages * Test cases added * Bug 🐞: Update message id for receiver Message id was not sent to receiver by pusher * Refactoring🛠: Message controller refactoring * Test Cases📝 : Specs for Delete message added * Feature 🚀 : Ability to edit messages * Test Cases📝 : Specs for Edit message added * 🐞 Channel List bug in mobile view * changes in joining request responses * 🛠 Request Managers Frontend ready * changes in routes for adding and removing remembership * 🚀 New routes implemented for request manager * fix issues * changes in api for remove membership * Merge conflict resolved * 🐞 Channel List bug in mobile view * changes in joining request responses * 🛠 Request Managers Frontend ready * changes in routes for adding and removing remembership * 🚀 New routes implemented for request manager * fix issues * changes in api for remove membership * 🛠Optimizing for CodeClimate * 🛠Optimizing again for CodeClimate * 🛠Optimizing again 2 for CodeClimate * 🛠 Added more test cases * 🛠 Optimizing code * 🛠 vscode file changed * 🛠 Updated schema as requested Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
128 lines
3.5 KiB
JavaScript
128 lines
3.5 KiB
JavaScript
import { h } from 'preact';
|
|
import PropTypes from 'prop-types';
|
|
// eslint-disable-next-line import/no-unresolved
|
|
import ConfigImage from 'images/three-dots.svg';
|
|
import ChannelButton from './components/channelButton';
|
|
import { channelSorter } from './util';
|
|
|
|
const Channels = ({
|
|
activeChannelId,
|
|
chatChannels,
|
|
unopenedChannelIds,
|
|
handleSwitchChannel,
|
|
expanded,
|
|
filterQuery = '',
|
|
channelsLoaded,
|
|
currentUserId,
|
|
triggerActiveContent,
|
|
}) => {
|
|
const sortedChatChannels = channelSorter(
|
|
chatChannels,
|
|
currentUserId,
|
|
filterQuery,
|
|
);
|
|
const discoverableChannels = sortedChatChannels.discoverableChannels.map(
|
|
(channel) => {
|
|
return (
|
|
<ChannelButton
|
|
channel={channel}
|
|
discoverableChannel
|
|
triggerActiveContent={triggerActiveContent}
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
const channels = sortedChatChannels.activeChannels.map((channel) => {
|
|
const isActive = parseInt(activeChannelId, 10) === channel.chat_channel_id;
|
|
const isUnopened =
|
|
!isActive && unopenedChannelIds.includes(channel.chat_channel_id);
|
|
const newMessagesIndicator = isUnopened ? 'new' : 'old';
|
|
const otherClassname = isActive
|
|
? 'chatchanneltab--active'
|
|
: 'chatchanneltab--inactive';
|
|
|
|
return (
|
|
<ChannelButton
|
|
channel={channel}
|
|
newMessagesIndicator={newMessagesIndicator}
|
|
otherClassname={otherClassname}
|
|
handleSwitchChannel={handleSwitchChannel}
|
|
isUnopened={isUnopened}
|
|
/>
|
|
);
|
|
});
|
|
let topNotice = '';
|
|
if (
|
|
expanded &&
|
|
filterQuery.length === 0 &&
|
|
channelsLoaded &&
|
|
(channels.length === 0 || channels[0].messages_count === 0)
|
|
) {
|
|
topNotice = (
|
|
<div className="chatchannels__channelslistheader">
|
|
<span role="img" aria-label="emoji">
|
|
👋
|
|
</span>
|
|
{' '}
|
|
Welcome to
|
|
<b> DEV Connect</b>
|
|
! You may message anyone you mutually follow.
|
|
</div>
|
|
);
|
|
}
|
|
let channelsListFooter = '';
|
|
if (channels.length === 30) {
|
|
channelsListFooter = (
|
|
<div className="chatchannels__channelslistfooter">...</div>
|
|
);
|
|
}
|
|
let configFooter = '';
|
|
if (expanded) {
|
|
configFooter = (
|
|
<div className="chatchannels__config">
|
|
<img alt="" src={ConfigImage} style={{ height: '18px' }} />
|
|
<div className="chatchannels__configmenu">
|
|
<a href="/settings">DEV Settings</a>
|
|
<a href="/report-abuse">Report Abuse</a>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div className="chatchannels">
|
|
<div
|
|
className="chatchannels__channelslist"
|
|
id="chatchannels__channelslist"
|
|
>
|
|
{topNotice}
|
|
{channels}
|
|
{discoverableChannels.length > 0 ? (
|
|
<div>
|
|
<span className="crayons-indicator crayons-indicator--">
|
|
Global Channel Search
|
|
</span>
|
|
{discoverableChannels}
|
|
</div>
|
|
) : (
|
|
''
|
|
)}
|
|
{channelsListFooter}
|
|
</div>
|
|
{configFooter}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
Channels.propTypes = {
|
|
activeChannelId: PropTypes.number.isRequired,
|
|
chatChannels: PropTypes.arrayOf(PropTypes.objectOf()).isRequired,
|
|
unopenedChannelIds: PropTypes.arrayOf().isRequired,
|
|
handleSwitchChannel: PropTypes.func.isRequired,
|
|
triggerActiveContent: PropTypes.func.isRequired,
|
|
expanded: PropTypes.bool.isRequired,
|
|
filterQuery: PropTypes.string.isRequired,
|
|
channelsLoaded: PropTypes.bool.isRequired,
|
|
currentUserId: PropTypes.string.isRequired,
|
|
};
|
|
|
|
export default Channels;
|