Skip to content

Commit

Permalink
chore: Add roomName on Composer placeholder (RocketChat#29255)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <[email protected]>
  • Loading branch information
dougfabris and ggazzo authored May 17, 2023
1 parent bbc21e9 commit e116d88
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-bats-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

chore: Add `roomName` on Composer placeholder
25 changes: 25 additions & 0 deletions apps/meteor/client/hooks/useRoomName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { isDirectMessageRoom } from '@rocket.chat/core-typings';
import { useUserSubscription } from '@rocket.chat/ui-contexts';

import { useUserDisplayName } from './useUserDisplayName';

/**
*
* Hook to get the name of the room
*
* @param room - Room object
* @returns Room name
* @public
*
*/
export const useRoomName = (room: IRoom) => {
const subscription = useUserSubscription(room._id);
const username = useUserDisplayName({ name: subscription?.fname, username: subscription?.name });

if (isDirectMessageRoom(room)) {
return username;
}

return room.fname || room.name;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
MessageComposerActionsDivider,
MessageComposerToolbarSubmit,
} from '@rocket.chat/ui-composer';
import { useTranslation, useUserPreference, useLayout } from '@rocket.chat/ui-contexts';
import { useTranslation, useUserPreference, useLayout, useUserRoom } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';
import type { ReactElement, MouseEventHandler, FormEvent, KeyboardEventHandler, KeyboardEvent, Ref, ClipboardEventHandler } from 'react';
import React, { memo, useRef, useReducer, useCallback } from 'react';
Expand Down Expand Up @@ -40,6 +40,7 @@ import MessageBoxActionsToolbar from './MessageBoxActionsToolbar';
import MessageBoxFormattingToolbar from './MessageBoxFormattingToolbar';
import MessageBoxReplies from './MessageBoxReplies';
import { useMessageBoxAutoFocus } from './hooks/useMessageBoxAutoFocus';
import { useMessageBoxPlaceholder } from './hooks/useMessageBoxPlaceholder';

const reducer = (_: unknown, event: FormEvent<HTMLInputElement>): boolean => {
const target = event.target as HTMLInputElement;
Expand Down Expand Up @@ -107,16 +108,17 @@ const MessageBox = ({
readOnly,
tshow,
}: MessageBoxProps): ReactElement => {
const chat = useChat();
const t = useTranslation();
const room = useUserRoom(rid);
const composerPlaceholder = useMessageBoxPlaceholder(t('Message'), room);

const [typing, setTyping] = useReducer(reducer, false);

const { isMobile } = useLayout();
const sendOnEnterBehavior = useUserPreference<'normal' | 'alternative' | 'desktop'>('sendOnEnter') || isMobile;
const sendOnEnter = sendOnEnterBehavior == null || sendOnEnterBehavior === 'normal' || (sendOnEnterBehavior === 'desktop' && !isMobile);

const t = useTranslation();

const chat = useChat();

if (!chat) {
throw new Error('Chat context not found');
}
Expand Down Expand Up @@ -373,12 +375,12 @@ const MessageBox = ({
{isRecordingAudio && <AudioMessageRecorder rid={rid} isMicrophoneDenied={isMicrophoneDenied} />}
<MessageComposerInput
ref={mergedRefs as unknown as Ref<HTMLInputElement>}
aria-label={t('Message')}
aria-label={composerPlaceholder}
name='msg'
disabled={isRecording || !canSend}
onChange={setTyping}
style={textAreaStyle}
placeholder={t('Message')}
placeholder={composerPlaceholder}
onKeyDown={handler}
onPaste={handlePaste}
aria-activedescendant={ariaActiveDescendant}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { isDirectMessageRoom } from '@rocket.chat/core-typings';

import { useRoomName } from '../../../../../../../hooks/useRoomName';

export const useMessageBoxPlaceholder = (placeholder: string, room?: IRoom) => {
if (!room) {
throw new Error('In order to get the placeholder a `room` must be provided');
}

const roomName = useRoomName(room);

if (isDirectMessageRoom(room)) {
return `${placeholder} @${roomName}`;
}

return `${placeholder} #${roomName}`;
};
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/message-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.describe.serial('message-actions', () => {
await poHomeChannel.content.sendMessage('this is a message for reply');
await poHomeChannel.content.openLastMessageMenu();
await page.locator('[data-qa-id="reply-in-thread"]').click();
await page.locator('.rcx-vertical-bar').locator('role=textbox[name="Message"]').type('this is a reply message');
await page.locator('.rcx-vertical-bar').locator(`role=textbox[name="Message #${targetChannel}"]`).type('this is a reply message');
await page.keyboard.press('Enter');

await expect(poHomeChannel.tabs.flexTabViewThreadMessage).toHaveText('this is a reply message');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/team-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe.serial('teams-management', () => {
await poHomeTeam.content.openLastMessageMenu();

await page.locator('[data-qa-id="reply-in-thread"]').click();
await page.locator('.rcx-vertical-bar').locator('role=textbox[name="Message"]').type('any-reply-message');
await page.locator('.rcx-vertical-bar').locator(`role=textbox[name="Message #${targetTeam}"]`).type('any-reply-message');
await page.keyboard.press('Enter');

await expect(poHomeTeam.tabs.flexTabViewThreadMessage).toHaveText('any-reply-message');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/threads.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test.describe.serial('Threads', () => {
});

test('expect delete the thread message and keep thread open if has more than one message', async ({ page }) => {
await page.locator('.rcx-vertical-bar').locator('role=textbox[name="Message"]').type('another reply message');
await page.locator('.rcx-vertical-bar').locator(`role=textbox[name="Message #${targetChannel}"]`).type('another reply message');
await page.keyboard.press('Enter');

await poHomeChannel.content.openLastThreadMessageMenu();
Expand Down

0 comments on commit e116d88

Please sign in to comment.