Skip to content

Commit

Permalink
Merge pull request bigbluebutton#18691 from Tainan404/add-chat-enums
Browse files Browse the repository at this point in the history
Add: Chat enums
  • Loading branch information
ramonlsouza authored Sep 1, 2023
2 parents e91f5ca + 99e4987 commit c5f79b1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { uid } from 'radash';
import Button from '/imports/ui/components/common/button/component';
import { clearPublicChatHistory, generateExportedMessages } from './services'
import { getDateString } from '/imports/utils/string-utils';
import Events from '/imports/ui/core/events/events';

import { isEmpty } from 'ramda';
import { ChatCommands } from '/imports/ui/core/enums/chat';

// @ts-ignore - temporary, while meteor exists in the project
const CHAT_CONFIG = Meteor.settings.public.chat;
Expand Down Expand Up @@ -144,7 +145,7 @@ export const ChatActions: React.FC = () => {
dataTest: 'restoreWelcomeMessages',
label: intl.formatMessage(intlMessages.showWelcomeMessage),
onClick: () => {
const restoreWelcomeMessagesEvent = new CustomEvent(Events.RESTORE_WELCOME_MESSAGES);
const restoreWelcomeMessagesEvent = new CustomEvent(ChatCommands.RESTORE_WELCOME_MESSAGES);
window.dispatchEvent(restoreWelcomeMessagesEvent);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
import { Chat } from '/imports/ui/Types/chat';
import { Layout } from '../../../layout/layoutTypes';
import { useMeeting } from '/imports/ui/core/hooks/useMeeting';
import Events from '/imports/ui/core/events/events';

import ChatOfflineIndicator from './chat-offline-indicator/component';
import { ChatEvents } from '/imports/ui/core/enums/chat';

interface ChatMessageFormProps {
minMessageLength: number,
Expand Down Expand Up @@ -194,7 +195,7 @@ const ChatMessageForm: React.FC<ChatMessageFormProps> = ({
setHasErrors(false);
setShowEmojiPicker(false);
if (ENABLE_TYPING_INDICATOR) stopUserTyping();
const sentMessageEvent = new CustomEvent(Events.SENT_MESSAGE);
const sentMessageEvent = new CustomEvent(ChatEvents.SENT_MESSAGE);
window.dispatchEvent(sentMessageEvent);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
import { layoutSelect } from "../../../layout/context";
import ChatListPage from "./page/component";
import { defineMessages, useIntl } from "react-intl";
import Events from "/imports/ui/core/events/events";
import useChat from "/imports/ui/core/hooks/useChat";
import { Chat } from "/imports/ui/Types/chat";
import { Message } from "/imports/ui/Types/message";
import { useCurrentUser } from "/imports/ui/core/hooks/useCurrentUser";
import { User } from "/imports/ui/Types/user";
import ChatPopupContainer from "../chat-popup/component";
import { ChatEvents } from "/imports/ui/core/enums/chat";

// @ts-ignore - temporary, while meteor exists in the project
const CHAT_CONFIG = Meteor.settings.public.chat;
Expand Down Expand Up @@ -204,10 +204,10 @@ const ChatMessageList: React.FC<ChatListProps> = ({
}

};
window.addEventListener(Events.SENT_MESSAGE, setScrollToTailEventHandler);
window.addEventListener(ChatEvents.SENT_MESSAGE, setScrollToTailEventHandler);

return () => {
window.removeEventListener(Events.SENT_MESSAGE, setScrollToTailEventHandler);
window.removeEventListener(ChatEvents.SENT_MESSAGE, setScrollToTailEventHandler);
}
}, [contentRef.current]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ChatMessageTextContent from "./message-content/text-content/component";
import ChatPollContent from "./message-content/poll-content/component";
import ChatMessagePresentationContent from "./message-content/presentation-content/component";
import { defineMessages, useIntl } from "react-intl";

import { ChatMessageType } from '/imports/ui/core/enums/chat';

interface ChatMessageProps {
message: Message;
Expand All @@ -20,12 +20,6 @@ interface ChatMessageProps {
markMessageAsSeen: Function;
}

const enum MessageType {
TEXT = 'default',
POLL = 'poll',
PRESENTATION = 'presentation',
CHAT_CLEAR = 'publicChatHistoryCleared'
}

const intlMessages = defineMessages({
pollResult: {
Expand Down Expand Up @@ -99,7 +93,7 @@ const ChatMesssage: React.FC<ChatMessageProps> = ({
component: React.ReactElement,
} = useMemo(() => {
switch (message.messageType) {
case MessageType.POLL:
case ChatMessageType.POLL:
return {
name: intl.formatMessage(intlMessages.pollResult),
color: '#3B48A9',
Expand All @@ -108,7 +102,7 @@ const ChatMesssage: React.FC<ChatMessageProps> = ({
<ChatPollContent metadata={message.messageMetadata} />
),
};
case MessageType.PRESENTATION:
case ChatMessageType.PRESENTATION:
return {
name: intl.formatMessage(intlMessages.presentationLabel),
color: '#0F70D7',
Expand All @@ -117,7 +111,7 @@ const ChatMesssage: React.FC<ChatMessageProps> = ({
<ChatMessagePresentationContent metadata={message.messageMetadata} />
),
};
case MessageType.CHAT_CLEAR:
case ChatMessageType.CHAT_CLEAR:
return {
name: intl.formatMessage(intlMessages.systemLabel),
color: '#0F70D7',
Expand All @@ -129,7 +123,7 @@ const ChatMesssage: React.FC<ChatMessageProps> = ({
/>
),
};
case MessageType.TEXT:
case ChatMessageType.TEXT:
default:
return {
name: message.user?.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { PopupContainer, PopupContents } from './styles';
import { GET_WELCOME_MESSAGE, WelcomeMsgsResponse } from './queries';
import { useQuery } from '@apollo/client';
import PopupContent from './popup-content/component';
import Events from '/imports/ui/core/events/events';
import { layoutSelect } from '../../../layout/context';
import { Layout } from '../../../layout/layoutTypes';
import { ChatCommands } from '/imports/ui/core/enums/chat';

interface ChatPopupProps {
welcomeMessage?: string | null;
Expand Down Expand Up @@ -55,10 +55,10 @@ const ChatPopup: React.FC<ChatPopupProps> = ({
setWelcomeMsgsOnSession(WELCOME_MSG_FOR_MODERATORS_KEY, true);
}
};
window.addEventListener(Events.RESTORE_WELCOME_MESSAGES, eventCallback);
window.addEventListener(ChatCommands.RESTORE_WELCOME_MESSAGES, eventCallback);

return () => {
removeEventListener(Events.RESTORE_WELCOME_MESSAGES, eventCallback);
removeEventListener(ChatCommands.RESTORE_WELCOME_MESSAGES, eventCallback);
}
}, []);
if (!showWelcomeMessage && !showWelcomeMessageForModerators) return null;
Expand Down
14 changes: 14 additions & 0 deletions bigbluebutton-html5/imports/ui/core/enums/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const enum ChatEvents {
SENT_MESSAGE = 'sentMessage',
}

export const enum ChatCommands {
RESTORE_WELCOME_MESSAGES = 'restoreWelcomeMessages',
}

export const enum ChatMessageType {
TEXT = 'default',
POLL = 'poll',
PRESENTATION = 'presentation',
CHAT_CLEAR = 'publicChatHistoryCleared'
}
7 changes: 0 additions & 7 deletions bigbluebutton-html5/imports/ui/core/events/events.ts

This file was deleted.

0 comments on commit c5f79b1

Please sign in to comment.