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

69 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';
import { NLayoutContext } from '../../layout/context/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) => {
const newLayoutContext = useContext(NLayoutContext);
2021-05-28 01:46:27 +08:00
const { newLayoutContextState, newLayoutContextDispatch } = newLayoutContext;
const { idChatOpen, input } = newLayoutContextState;
const { sidebarContent } = input;
const { sidebarContentPanel } = sidebarContent;
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
? JSON.stringify(activeChats.map(chat => {
return {chatId: chat.chatId, unreadCounter: chat.unreadCounter};
}))
: null;
// push alerts
const unreadMessagesByChat = pushAlertEnabled
? JSON.stringify(activeChats.filter((chat) => chat.unreadCounter > 0).map(chat => {
const chatId = (chat.chatId === 'public') ? PUBLIC_CHAT_ID : chat.chatId;
return UnreadMessages.getUnreadMessages(chatId, groupChatsMessages);
}))
: null;
return (
2021-05-18 04:25:07 +08:00
<ChatAlert
{...props}
2021-05-28 01:46:27 +08:00
newLayoutContextDispatch={newLayoutContextDispatch}
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;