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

110 lines
3.0 KiB
React
Raw Normal View History

2017-07-13 00:47:58 +08:00
import React from 'react';
2016-06-14 01:00:38 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2016-04-29 03:02:51 +08:00
import { createContainer } from 'meteor/react-meteor-data';
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;
2016-07-01 01:10:36 +08:00
2016-06-02 00:33:19 +08:00
2016-06-14 01:00:38 +08:00
const intlMessages = defineMessages({
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',
},
});
2017-07-13 00:47:58 +08:00
const ChatContainer = props =>
(
<Chat {...props}>
{props.children}
</Chat>
);
2016-04-29 03:02:51 +08:00
2016-06-14 01:00:38 +08:00
export default injectIntl(createContainer(({ params, intl }) => {
2016-06-02 00:33:19 +08:00
const chatID = params.chatID || PUBLIC_CHAT_KEY;
let messages = [];
2016-06-14 01:00:38 +08:00
let isChatLocked = ChatService.isChatLocked(chatID);
let title = intl.formatMessage(intlMessages.titlePublic);
let chatName = title;
2016-06-02 00:33:19 +08:00
if (chatID === PUBLIC_CHAT_KEY) {
messages = ChatService.reduceAndMapMessages((ChatService.getPublicMessages()));
2016-06-02 00:33:19 +08:00
} else {
messages = ChatService.getPrivateMessages(chatID);
}
2017-06-03 03:25:02 +08:00
const user = ChatService.getUser(chatID, '{{NAME}}');
2017-04-12 20:03:14 +08:00
let partnerIsLoggedOut = false;
if (user) {
partnerIsLoggedOut = !user.isOnline;
if (messages && chatID !== PUBLIC_CHAT_KEY) {
2017-07-13 00:47:58 +08:00
const chatUser = ChatService.getUser(chatID, '{{NAME}}');
2017-04-12 20:03:14 +08:00
2017-07-13 00:47:58 +08:00
title = intl.formatMessage(intlMessages.titlePrivate, { 0: chatUser.name });
chatName = chatUser.name;
2017-04-12 20:03:14 +08:00
2017-07-13 00:47:58 +08:00
if (!chatUser.isOnline) {
2017-06-03 03:25:02 +08:00
const time = Date.now();
const id = `partner-disconnected-${time}`;
const messagePartnerLoggedOut = {
2017-04-13 04:19:39 +08:00
id,
2017-04-12 20:03:14 +08:00
content: [{
2017-04-13 04:19:39 +08:00
id,
2017-07-13 00:47:58 +08:00
text: intl.formatMessage(intlMessages.partnerDisconnected, { 0: chatUser.name }),
2017-04-13 04:19:39 +08:00
time,
2017-06-03 03:25:02 +08:00
}],
2017-04-13 04:19:39 +08:00
time,
2017-04-12 20:03:14 +08:00
sender: null,
};
2017-04-12 20:03:14 +08:00
messages.push(messagePartnerLoggedOut);
isChatLocked = true;
}
2016-06-14 01:00:38 +08:00
}
2016-06-02 00:33:19 +08:00
}
2016-07-01 01:10:36 +08:00
const scrollPosition = ChatService.getScrollPosition(chatID);
2016-07-06 00:47:40 +08:00
const hasUnreadMessages = ChatService.hasUnreadMessages(chatID);
2016-07-12 03:42:54 +08:00
const lastReadMessageTime = ChatService.lastReadMessageTime(chatID);
2016-07-01 01:10:36 +08:00
2016-06-02 00:33:19 +08:00
return {
2016-07-01 01:10:36 +08:00
chatID,
chatName,
2016-06-02 00:33:19 +08:00
title,
messages,
2016-07-12 03:42:54 +08:00
lastReadMessageTime,
2016-07-05 02:53:47 +08:00
hasUnreadMessages,
2017-04-07 05:08:20 +08:00
partnerIsLoggedOut,
2016-06-07 22:19:19 +08:00
isChatLocked,
2016-07-01 01:10:36 +08:00
scrollPosition,
minMessageLength: CHAT_CONFIG.min_message_length,
maxMessageLength: CHAT_CONFIG.max_message_length,
2016-06-03 02:40:27 +08:00
actions: {
2017-07-13 00:47:58 +08:00
handleClosePrivateChat: chatId => ChatService.closePrivateChat(chatId),
2017-06-03 03:25:02 +08:00
handleSendMessage: (message) => {
2017-04-28 22:52:54 +08:00
ChatService.updateScrollPosition(chatID, null);
return ChatService.sendMessage(chatID, message);
2016-07-01 01:10:36 +08:00
},
handleScrollUpdate: position => ChatService.updateScrollPosition(chatID, position),
2016-07-05 02:53:47 +08:00
handleReadMessage: timestamp => ChatService.updateUnreadMessage(chatID, timestamp),
2016-06-03 02:40:27 +08:00
},
2016-06-02 00:33:19 +08:00
};
2016-06-14 01:00:38 +08:00
}, ChatContainer));