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

162 lines
4.4 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
2016-06-14 01:00:38 +08:00
import { defineMessages, injectIntl } from 'react-intl';
import { withTracker } from 'meteor/react-meteor-data';
import { Session } from 'meteor/session';
import Auth from '/imports/ui/services/auth';
2017-07-13 00:47:58 +08:00
import Chat from './component';
import ChatService from './service';
2016-04-29 03:02:51 +08:00
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_id;
const CHAT_CLEAR = CHAT_CONFIG.system_messages_keys.chat_clear;
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
const CONNECTION_STATUS = 'online';
2016-06-02 00:33:19 +08:00
2016-06-14 01:00:38 +08:00
const intlMessages = defineMessages({
[CHAT_CLEAR]: {
2017-11-23 21:00:41 +08:00
id: 'app.chat.clearPublicChatMessage',
description: 'message of when clear the public chat',
},
2016-06-14 01:00:38 +08:00
titlePublic: {
id: 'app.chat.titlePublic',
description: 'Public chat title',
},
titlePrivate: {
id: 'app.chat.titlePrivate',
description: 'Private chat title',
},
partnerDisconnected: {
id: 'app.chat.partnerDisconnected',
description: 'System chat message when the private chat partnet disconnect from the meeting',
},
});
class ChatContainer extends PureComponent {
componentDidMount() {
2017-12-19 04:12:31 +08:00
// in case of reopening a chat, need to make sure it's removed from closed list
ChatService.removeFromClosedChatsSession();
}
2017-12-19 03:56:08 +08:00
render() {
const { children } = this.props;
2017-12-19 03:56:08 +08:00
return (
<Chat {...this.props}>
{children}
2017-12-19 03:56:08 +08:00
</Chat>
);
}
}
2016-04-29 03:02:51 +08:00
export default injectIntl(withTracker(({ intl }) => {
const chatID = Session.get('idChatOpen') || PUBLIC_CHAT_KEY;
2016-06-02 00:33:19 +08:00
let messages = [];
let isChatLocked = ChatService.isChatLocked(chatID);
let title = intl.formatMessage(intlMessages.titlePublic);
let chatName = title;
2017-12-01 20:01:07 +08:00
let partnerIsLoggedOut = false;
let systemMessageIntl = {};
2016-06-02 00:33:19 +08:00
if (chatID === PUBLIC_CHAT_KEY) {
const { welcomeProp } = ChatService.getWelcomeProp();
const currentUser = ChatService.getUser(Auth.userID);
messages = ChatService.getPublicGroupMessages();
const time = currentUser.loginTime;
const welcomeId = `welcome-msg-${time}`;
const welcomeMsg = {
id: welcomeId,
content: [{
id: welcomeId,
text: welcomeProp.welcomeMsg,
time,
}],
time,
sender: null,
};
const moderatorTime = time + 1;
const moderatorId = `moderator-msg-${moderatorTime}`;
const moderatorMsg = {
id: moderatorId,
content: [{
id: moderatorId,
text: welcomeProp.modOnlyMessage,
time: moderatorTime,
}],
time: moderatorTime,
sender: null,
};
2019-03-26 07:02:37 +08:00
const messagesBeforeWelcomeMsg = ChatService.reduceAndMapGroupMessages(
2019-07-31 10:37:50 +08:00
messages.filter(message => message.timestamp < time),
);
2019-03-26 07:02:37 +08:00
const messagesAfterWelcomeMsg = ChatService.reduceAndMapGroupMessages(
2019-07-31 10:37:50 +08:00
messages.filter(message => message.timestamp >= time),
);
const messagesFormated = messagesBeforeWelcomeMsg
2019-03-05 01:33:59 +08:00
.concat(welcomeMsg)
.concat(currentUser.role === ROLE_MODERATOR ? moderatorMsg : [])
.concat(messagesAfterWelcomeMsg);
messages = messagesFormated.sort((a, b) => (a.time - b.time));
2016-06-02 00:33:19 +08:00
} else {
messages = ChatService.getPrivateGroupMessages();
const receiverUser = ChatService.getUser(chatID);
chatName = receiverUser.name;
systemMessageIntl = { 0: receiverUser.name };
2017-12-01 20:01:07 +08:00
title = intl.formatMessage(intlMessages.titlePrivate, systemMessageIntl);
2019-08-23 02:04:39 +08:00
partnerIsLoggedOut = receiverUser.connectionStatus !== CONNECTION_STATUS;
2017-12-01 20:01:07 +08:00
if (partnerIsLoggedOut) {
const time = Date.now();
const id = `partner-disconnected-${time}`;
const messagePartnerLoggedOut = {
id,
content: [{
id,
text: 'partnerDisconnected',
time,
}],
time,
sender: null,
};
2017-12-01 20:01:07 +08:00
messages.push(messagePartnerLoggedOut);
isChatLocked = true;
}
}
2017-04-12 20:03:14 +08:00
messages = messages.map((message) => {
if (message.sender) return message;
return {
...message,
content: message.content.map(content => ({
...content,
2019-03-26 07:02:37 +08:00
text: content.text in intlMessages
? `<b><i>${intl.formatMessage(intlMessages[content.text], systemMessageIntl)}</i></b>` : content.text,
})),
};
});
2019-06-27 00:29:34 +08:00
const { connected: isMeteorConnected } = Meteor.status();
2016-06-02 00:33:19 +08:00
return {
chatID,
chatName,
2016-06-02 00:33:19 +08:00
title,
messages,
2017-04-07 05:08:20 +08:00
partnerIsLoggedOut,
2016-06-07 22:19:19 +08:00
isChatLocked,
2019-06-27 00:29:34 +08:00
isMeteorConnected,
2016-06-03 02:40:27 +08:00
actions: {
handleClosePrivateChat: ChatService.closePrivateChat,
2016-06-03 02:40:27 +08:00
},
2016-06-02 00:33:19 +08:00
};
})(ChatContainer));