Skip to content

Commit

Permalink
Merge pull request bigbluebutton#18692 from ramonlsouza/fix-save-clea…
Browse files Browse the repository at this point in the history
…red-chat

fix: save/copy chat if chat has been cleared
  • Loading branch information
ramonlsouza authored Sep 1, 2023
2 parents c5f79b1 + d32a122 commit 92b64d4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const ChatActions: React.FC = () => {
const exportedString = generateExportedMessages(
dataHistory.chat_message_public,
dataHistory.user_welcomeMsgs[0],
intl,
);
if (downloadOrCopyRef.current === 'download') {
const link = document.createElement('a');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ query getChatMessageHistory {
chat_message_public(order_by: {createdTime: asc}) {
message
messageId
messageType
createdTime
user {
userId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
import { Message } from "/imports/ui/Types/message";
import { makeCall } from "/imports/ui/services/api";
import { stripTags, unescapeHtml } from '/imports/utils/string-utils';
import { defineMessages } from 'react-intl';
import { ChatMessageType } from '/imports/ui/core/enums/chat';

const intlMessages = defineMessages({
chatClear: {
id: 'app.chat.clearPublicChatMessage',
description: 'message of when clear the public chat',
},
});

export const htmlDecode = (input: string) => {
const replacedBRs = input.replaceAll('<br/>', '\n');
return unescapeHtml(stripTags(replacedBRs));
};

export const generateExportedMessages = (messages: Array<Message>, welcomeSettings: {welcomeMsg: string, welcomeMsgForModerators: string | null} ): string => {
export const generateExportedMessages = (messages: Array<Message>, welcomeSettings: { welcomeMsg: string, welcomeMsgForModerators: string | null }, intl): string => {
const welcomeMessage = htmlDecode(welcomeSettings.welcomeMsg);
const modOnlyMessage = welcomeSettings.welcomeMsgForModerators && htmlDecode(welcomeSettings.welcomeMsgForModerators);
const systemMessages = `${welcomeMessage ? `system: ${welcomeMessage}`: ''}\n ${modOnlyMessage ? `system: ${modOnlyMessage}`: ''}\n`
const systemMessages = `${welcomeMessage ? `system: ${welcomeMessage}` : ''}\n ${modOnlyMessage ? `system: ${modOnlyMessage}` : ''}\n`

const text = messages.reduce((acc, message) => {
const date = new Date(message.createdTime);
const hour = date.getHours().toString().padStart(2, '0');
const min = date.getMinutes().toString().padStart(2, '0');
const hourMin = `[${hour}:${min}]`;
const userName = message.user.name;
const messageText = htmlDecode(message.message);
return `${acc}${hourMin} [${userName} : ${message.user.role}]: ${messageText}\n`;
},welcomeMessage? systemMessages : '');
const userName = message.user ? `[${message.user.name} : ${message.user.role}]: ` : '';
let messageText = '';

switch (message.messageType) {
case ChatMessageType.CHAT_CLEAR:
messageText = intl.formatMessage(intlMessages.chatClear);
break;
case ChatMessageType.TEXT:
default:
messageText = htmlDecode(message.message);
break;
}
return `${acc}${hourMin} ${userName}${messageText}\n`;
}, welcomeMessage ? systemMessages : '');
return text;
};

Expand All @@ -34,7 +53,5 @@ export const getDateString = (date = new Date()) => {
return dateString;
};


// TODO: Make action using mutations
export const clearPublicChatHistory = () => (makeCall('clearPublicChatHistory'));

0 comments on commit 92b64d4

Please sign in to comment.