Merge pull request #19612 from ramonlsouza/fix-tp-15

fix: poll results on chat export
This commit is contained in:
Ramón Souza 2024-02-13 09:03:27 -03:00 committed by GitHub
commit de8fbf824b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -22,6 +22,7 @@ query getChatMessageHistory {
message
messageId
messageType
messageMetadata
chatEmphasizedText
createdAt
user {

View File

@ -2,12 +2,17 @@ import { Message } from '/imports/ui/Types/message';
import { stripTags, unescapeHtml } from '/imports/utils/string-utils';
import { IntlShape, defineMessages } from 'react-intl';
import { ChatMessageType } from '/imports/ui/core/enums/chat';
import PollService from '/imports/ui/components/poll/service';
const intlMessages = defineMessages({
chatClear: {
id: 'app.chat.clearPublicChatMessage',
description: 'message of when clear the public chat',
},
pollResult: {
id: 'app.chat.pollResult',
description: 'used in place of user name who published poll to chat',
},
});
export const htmlDecode = (input: string) => {
@ -29,13 +34,22 @@ export const generateExportedMessages = (
const hour = date.getHours().toString().padStart(2, '0');
const min = date.getMinutes().toString().padStart(2, '0');
const hourMin = `[${hour}:${min}]`;
const userName = message.user ? `[${message.user.name} : ${message.user.role}]: ` : '';
let 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.POLL: {
userName = `${intl.formatMessage(intlMessages.pollResult)}:\n`;
const metadata = JSON.parse(message.messageMetadata);
const pollText = htmlDecode(PollService.getPollResultString(metadata, intl).split('<br/>').join('\n'));
// remove last \n to avoid empty line
messageText = pollText.slice(0, -1);
break;
}
case ChatMessageType.TEXT:
default:
messageText = htmlDecode(message.message);