bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/nav-bar/container.jsx

109 lines
3.7 KiB
React
Raw Normal View History

2021-02-19 04:11:02 +08:00
import React, { useContext } from 'react';
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import Meetings from '/imports/api/meetings';
import Auth from '/imports/ui/services/auth';
import getFromUserSettings from '/imports/ui/services/users-settings';
2021-05-18 04:25:07 +08:00
import userListService from '/imports/ui/components/user-list/service';
2021-02-19 04:11:02 +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 { UsersContext } from '/imports/ui/components/components-data/users-context/context';
2019-12-17 05:06:41 +08:00
import NoteService from '/imports/ui/components/note/service';
import Service from './service';
import NavBar from './component';
2021-09-11 04:48:52 +08:00
import { layoutSelectInput, layoutSelectOutput, layoutDispatch } from '../layout/context';
2016-04-29 03:02:51 +08:00
const PUBLIC_CONFIG = Meteor.settings.public;
2019-08-22 02:57:34 +08:00
const ROLE_MODERATOR = PUBLIC_CONFIG.user.role_moderator;
2021-02-19 04:11:02 +08:00
2021-05-18 04:25:07 +08:00
const checkUnreadMessages = ({
groupChatsMessages, groupChats, users, idChatOpen,
}) => {
2021-02-19 04:11:02 +08:00
const activeChats = userListService.getActiveChats({ groupChatsMessages, groupChats, users });
const hasUnreadMessages = activeChats
2021-05-18 04:25:07 +08:00
.filter((chat) => chat.userId !== idChatOpen)
.some((chat) => chat.unreadCounter > 0);
2021-02-19 04:11:02 +08:00
return hasUnreadMessages;
};
const NavBarContainer = ({ children, ...props }) => {
const usingChatContext = useContext(ChatContext);
const usingUsersContext = useContext(UsersContext);
const usingGroupChatContext = useContext(GroupChatContext);
const { chats: groupChatsMessages } = usingChatContext;
const { users } = usingUsersContext;
const { groupChat: groupChats } = usingGroupChatContext;
2021-08-05 12:22:07 +08:00
const { ...rest } = props;
2021-09-11 04:48:52 +08:00
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const sidebarNavigation = layoutSelectInput((i) => i.sidebarNavigation);
const navBar = layoutSelectOutput((i) => i.navBar);
const layoutContextDispatch = layoutDispatch();
const { sidebarContentPanel } = sidebarContent;
const { sidebarNavPanel } = sidebarNavigation;
2021-05-18 04:25:07 +08:00
const hasUnreadNotes = NoteService.hasUnreadNotes(sidebarContentPanel);
const hasUnreadMessages = checkUnreadMessages(
{ groupChatsMessages, groupChats, users: users[Auth.meetingID] },
);
const isExpanded = !!sidebarContentPanel || !!sidebarNavPanel;
2021-02-19 04:11:02 +08:00
2021-04-15 20:12:21 +08:00
const currentUser = users[Auth.meetingID][Auth.userID];
const amIModerator = currentUser.role === ROLE_MODERATOR;
2021-02-19 04:11:02 +08:00
return (
2021-05-18 04:25:07 +08:00
<NavBar
{...{
amIModerator,
hasUnreadMessages,
hasUnreadNotes,
sidebarNavPanel,
sidebarContentPanel,
sidebarNavigation,
sidebarContent,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
2021-05-18 04:25:07 +08:00
isExpanded,
...rest,
}}
style={{ ...navBar }}
>
2021-02-19 04:11:02 +08:00
{children}
</NavBar>
);
2021-05-18 04:25:07 +08:00
};
2021-02-19 04:11:02 +08:00
export default withTracker(() => {
const CLIENT_TITLE = getFromUserSettings('bbb_client_title', PUBLIC_CONFIG.app.clientTitle);
2016-07-11 20:34:58 +08:00
let meetingTitle;
const meetingId = Auth.meetingID;
2016-06-29 02:50:44 +08:00
const meetingObject = Meetings.findOne({
2017-06-03 03:25:02 +08:00
meetingId,
}, { fields: { 'meetingProp.name': 1, 'breakoutProps.sequence': 1 } });
2016-06-29 02:50:44 +08:00
if (meetingObject != null) {
2017-08-16 01:24:58 +08:00
meetingTitle = meetingObject.meetingProp.name;
let titleString = `${CLIENT_TITLE} - ${meetingTitle}`;
if (meetingObject.breakoutProps) {
const breakoutNum = meetingObject.breakoutProps.sequence;
if (breakoutNum > 0) {
titleString = `${breakoutNum} - ${titleString}`;
}
}
document.title = titleString;
2016-06-29 02:50:44 +08:00
}
2016-06-18 06:15:11 +08:00
2019-01-09 06:17:11 +08:00
const { connectRecordingObserver, processOutsideToggleRecording } = Service;
2021-05-18 04:25:07 +08:00
2016-07-21 22:24:50 +08:00
return {
2019-09-05 02:32:58 +08:00
currentUserId: Auth.userID,
2019-01-09 06:17:11 +08:00
processOutsideToggleRecording,
connectRecordingObserver,
2016-11-29 03:48:02 +08:00
meetingId,
2016-06-25 07:09:32 +08:00
presentationTitle: meetingTitle,
2016-04-29 03:02:51 +08:00
};
})(NavBarContainer);