bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/alert/container.jsx

71 lines
2.5 KiB
React
Raw Normal View History

2021-05-28 01:46:27 +08:00
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import ChatAlert from './component';
2021-09-11 04:48:52 +08:00
import { layoutSelect, layoutSelectInput, layoutDispatch } from '../../layout/context';
2021-05-18 04:25:07 +08:00
import { PANELS } from '../../layout/enums';
import { UsersContext } from '/imports/ui/components/components-data/users-context/context';
2021-04-10 04:35:05 +08:00
import { ChatContext } from '/imports/ui/components/components-data/chat-context/context';
import { GroupChatContext } from '/imports/ui/components/components-data/group-chat-context/context';
import userListService from '/imports/ui/components/user-list/service';
2021-05-28 01:46:27 +08:00
import UnreadMessages from '/imports/ui/services/unread-messages';
const PUBLIC_CHAT_ID = Meteor.settings.public.chat.public_group_id;
const propTypes = {
audioAlertEnabled: PropTypes.bool.isRequired,
pushAlertEnabled: PropTypes.bool.isRequired,
};
const ChatAlertContainer = (props) => {
2021-09-11 04:48:52 +08:00
const idChatOpen = layoutSelect((i) => i.idChatOpen);
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const { sidebarContentPanel } = sidebarContent;
2021-09-11 04:48:52 +08:00
const layoutContextDispatch = layoutDispatch();
2021-05-28 01:46:27 +08:00
const { audioAlertEnabled, pushAlertEnabled } = props;
2021-05-18 04:25:07 +08:00
let idChat = idChatOpen;
if (sidebarContentPanel !== PANELS.CHAT) idChat = '';
const usingUsersContext = useContext(UsersContext);
2021-04-10 04:35:05 +08:00
const usingChatContext = useContext(ChatContext);
const usingGroupChatContext = useContext(GroupChatContext);
const { users } = usingUsersContext;
2021-04-10 04:35:05 +08:00
const { chats: groupChatsMessages } = usingChatContext;
const { groupChat: groupChats } = usingGroupChatContext;
const activeChats = userListService.getActiveChats({ groupChatsMessages, groupChats, users });
2021-05-28 01:46:27 +08:00
// audio alerts
const unreadMessagesCountByChat = audioAlertEnabled
2021-05-28 03:11:36 +08:00
? activeChats.map((chat) => ({
2021-05-28 02:12:49 +08:00
chatId: chat.chatId, unreadCounter: chat.unreadCounter,
2021-05-28 03:11:36 +08:00
}))
2021-05-28 02:12:49 +08:00
: null;
2021-05-28 01:46:27 +08:00
// push alerts
const unreadMessagesByChat = pushAlertEnabled
2021-05-28 03:11:36 +08:00
? activeChats.filter(
(chat) => chat.unreadCounter > 0 && chat.chatId !== idChat,
).map((chat) => {
2021-05-28 02:12:49 +08:00
const chatId = (chat.chatId === 'public') ? PUBLIC_CHAT_ID : chat.chatId;
return UnreadMessages.getUnreadMessages(chatId, groupChatsMessages);
2021-05-28 03:11:36 +08:00
})
2021-05-28 02:12:49 +08:00
: null;
2021-05-28 01:46:27 +08:00
return (
2021-05-18 04:25:07 +08:00
<ChatAlert
{...props}
2021-08-05 19:03:24 +08:00
layoutContextDispatch={layoutContextDispatch}
2021-05-28 01:46:27 +08:00
unreadMessagesCountByChat={unreadMessagesCountByChat}
unreadMessagesByChat={unreadMessagesByChat}
2021-05-18 04:25:07 +08:00
idChatOpen={idChat}
/>
);
};
2021-05-28 01:46:27 +08:00
ChatAlertContainer.propTypes = propTypes;
2021-05-28 01:46:27 +08:00
export default ChatAlertContainer;