/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/anchor-is-valid */ /* eslint-disable no-console */ /* eslint-disable import/no-unresolved */ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import React from 'react'; import { Cell, Grid, Heading, useNotificationDispatch, } from 'amazon-chime-sdk-component-library-react'; import { useTheme } from 'styled-components'; import ChannelsWrapper from '../../containers/channels/ChannelsWrapper'; import ChannelPresence from '../../containers/Presence/ChannelPresence'; import Messages from '../../containers/messages/Messages'; import Input from '../../containers/input/Input'; import TypingIndicator from '../../containers/TypingIndicator'; import { useChatChannelState, useChatMessagingState, } from '../../providers/ChatMessagesProvider'; import { useAuthContext } from '../../providers/AuthProvider'; import { PresenceAutoStatus, PresenceMode, toPresenceMap, toPresenceMessage, } from '../../utilities/presence'; import { MessageType, Persistence, sendChannelMessage, } from '../../api/ChimeAPI'; import './style.css'; const Channels = () => { const currentTheme = useTheme(); const { activeChannelMemberships } = useChatChannelState(); const { member, userSignOut } = useAuthContext(); const { messages, messagesRef, setMessages, onReceiveMessage, } = useChatMessagingState(); const notificationDispatch = useNotificationDispatch(); const { setChannelMessageToken, setSubChannelList, setChannelList, setChannelListModerator, setActiveView, activeView, activeChannel, activeChannelRef, channelList, channelListModerator, subChannelList, hasMembership, moderatedChannel, } = useChatChannelState(); const handleUserNameCopyClick = (_e) => { // Create new element const el = document.createElement('textarea'); // Set value (string to be copied) el.value = member.userId; // Set non-editable to avoid focus and move outside of view el.setAttribute('readonly', ''); el.style = { position: 'absolute', left: '-9999px' }; document.body.appendChild(el); // Select text inside element el.select(); // Copy text to clipboard document.execCommand('copy'); // Remove temporary element document.body.removeChild(el); notificationDispatch({ type: 0, payload: { message: 'UserId copied to clipboard!', severity: 'info', autoClose: true, autoCloseDelay: 1000, }, }); }; async function publishOfflineStatus() { if (activeChannel && activeChannel.ChannelArn) { const presenceMap = toPresenceMap(activeChannel.Metadata); const customPresenceExists = presenceMap && presenceMap[member.userId]; if (!customPresenceExists) { await sendChannelMessage( activeChannel.ChannelArn, toPresenceMessage(PresenceMode.Auto, PresenceAutoStatus.Offline, true), Persistence.NON_PERSISTENT, MessageType.CONTROL, member, activeChannel.SubChannelId ); } } } function handleLogout() { return async () => { if ( !activeChannel.ElasticChannelConfiguration && !activeChannel.SubChannelId ) { await publishOfflineStatus(); } userSignOut(); }; } const showChannelMembers = () => !(activeChannel && JSON.parse(activeChannel.Metadata || '{}').isMeeting) && activeChannelMemberships.length > 1; return ( {/* HEADING */} {activeView === 'Moderator' && moderatedChannel.Name} Chat App
{member.username || 'Unknown'} Click to copy UserId to clipboard! Log out
{/* SIDEPANEL CHANNELS LIST */}
{/* MAIN CHAT CONTENT WINDOW */} {activeChannel.ChannelArn && (!activeChannel.ElasticChannelConfiguration || activeChannel.SubChannelId) ? ( <>
{showChannelMembers() && !activeChannel.SubChannelId && JSON.parse(activeChannel.Metadata || '{}').ChannelType != 'PUBLIC_ELASTIC' && (
)}
) : (
Welcome
)}
); }; export default Channels;