* 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 * Merge conflict resolved * UI completed for Create Channel * API for create channel & invitations * 🚀 Combining Backend and Frontend * Test cases added * UI completed for Create Channel * API for create channel & invitations * 🚀 Combining Backend and Frontend * Test cases added * fix suggestions * add test cases * replace mod_relations_admin to tag_moderator * fix test cases * refactor and fix code climate issues * Update app/controllers/chat_channel_memberships_controller.rb Co-authored-by: Michael Kohl <me@citizen428.net> * fix suggestions * renaming the methods * Update app/javascript/chat/chat.jsx Co-authored-by: Nick Taylor <nick@iamdeveloper.com> * Update app/javascript/chat/components/createChatModal.jsx Co-authored-by: Nick Taylor <nick@iamdeveloper.com> * add jsDoc and add validation * add PR suggestions * renmae the file name to PascalCase * add styled component * refactor channel button component * fix specs * fix code smell issues * fix file name issue * handle error message * add jsDoc * Update app/controllers/chat_channels_controller.rb Co-authored-by: Michael Kohl <me@citizen428.net> * refactor chat_channel_helpers * update old hash to new hash * Update app/javascript/chat/components/ChannelButton.jsx Co-authored-by: Nick Taylor <nick@iamdeveloper.com> * Update app/views/chat_channels/index.html.erb Co-authored-by: Michael Kohl <me@citizen428.net> * fix syntax error * Update app/views/chat_channels/index.html.erb Co-authored-by: Nick Taylor <nick@iamdeveloper.com> * Policies changed * The Disable Button issue 🐞 * Fixing Disabled button Issue 🐞 * New group doesn't show up 🐞 Co-authored-by: Narender Singh <narender2031@gmail.com> Co-authored-by: Michael Kohl <me@citizen428.net> Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
136 lines
3.8 KiB
JavaScript
136 lines
3.8 KiB
JavaScript
import { h } from 'preact';
|
|
import PropTypes from 'prop-types';
|
|
// eslint-disable-next-line import/no-unresolved
|
|
import ConfigImage from 'images/overflow-horizontal.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}
|
|
isActiveChannel={
|
|
parseInt(activeChannelId, 10) === channel.chat_channel_id
|
|
}
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
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" role="alert">
|
|
<span role="img" aria-label="emoji">
|
|
👋
|
|
</span>{' '}
|
|
Welcome to
|
|
<b> 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) {
|
|
// TODO: The <div /> below should be converted into a real menu or <nav />
|
|
configFooter = (
|
|
<div className="chatchannels__config">
|
|
<img alt="configration" src={ConfigImage} style={{ height: '18px' }} />
|
|
<div className="chatchannels__configmenu" role="menu">
|
|
<a href="/settings" role="menuitem">
|
|
Settings
|
|
</a>
|
|
<a href="/report-abuse" role="menuitem">
|
|
Report Abuse
|
|
</a>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div className="chatchannels">
|
|
<div
|
|
className="chatchannels__channelslist"
|
|
id="chatchannels__channelslist"
|
|
data-testid="chat-channels-list"
|
|
>
|
|
{topNotice}
|
|
{channels}
|
|
{discoverableChannels.length > 0 && filterQuery.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;
|