Skip to content

Commit 4c77add

Browse files
authored
fix: Empty placeholder on message composer (#6560)
1 parent 6ca966a commit 4c77add

File tree

7 files changed

+18
-43
lines changed

7 files changed

+18
-43
lines changed

app/containers/MessageComposer/MessageComposer.test.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ const initialStoreState = () => {
4343
};
4444
initialStoreState();
4545

46-
jest.mock('./hooks/useSubscription', () => ({
47-
useSubscription: jest.fn(() => ({
48-
rid: 'rid',
49-
t: 'd',
50-
tmid: undefined,
51-
name: 'Rocket Chat',
52-
fname: 'Rocket Chat',
53-
usernames: ['user1', 'user2'],
54-
prid: undefined,
55-
federated: false
56-
}))
57-
}));
58-
5946
jest.mock('../../lib/database/services/Message', () => ({
6047
getMessageById: (messageId: any) => ({
6148
id: messageId,
@@ -75,6 +62,16 @@ jest.mock('../../lib/database/services/Message', () => ({
7562
const initialContext = {
7663
rid: 'rid',
7764
tmid: undefined,
65+
room: {
66+
rid: 'rid',
67+
t: 'd',
68+
tmid: undefined,
69+
name: 'Rocket Chat',
70+
fname: 'Rocket Chat',
71+
usernames: ['user1', 'user2'],
72+
prid: undefined,
73+
federated: false
74+
},
7875
sharing: false,
7976
action: null,
8077
selectedMessages: [],

app/containers/MessageComposer/components/ComposerInput.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import I18n from '../../../i18n';
99
import { IAutocompleteItemProps, IComposerInput, IComposerInputProps, IInputSelection, TSetInput } from '../interfaces';
1010
import { useAutocompleteParams, useFocused, useMessageComposerApi, useMicOrSend } from '../context';
1111
import { fetchIsAllOrHere, getMentionRegexp } from '../helpers';
12-
import { useSubscription, useAutoSaveDraft } from '../hooks';
12+
import { useAutoSaveDraft } from '../hooks';
1313
import sharedStyles from '../../../views/Styles';
1414
import { useTheme } from '../../../theme';
1515
import { userTyping } from '../../../actions/room';
@@ -38,19 +38,18 @@ const defaultSelection: IInputSelection = { start: 0, end: 0 };
3838
export const ComposerInput = memo(
3939
forwardRef<IComposerInput, IComposerInputProps>(({ inputRef }, ref) => {
4040
const { colors, theme } = useTheme();
41-
const { rid, tmid, sharing, action, selectedMessages, setQuotesAndText } = useRoomContext();
41+
const { rid, tmid, sharing, action, selectedMessages, setQuotesAndText, room } = useRoomContext();
4242
const focused = useFocused();
4343
const { setFocused, setMicOrSend, setAutocompleteParams } = useMessageComposerApi();
4444
const autocompleteType = useAutocompleteParams()?.type;
4545
const textRef = React.useRef('');
4646
const firstRender = React.useRef(true);
4747
const selectionRef = React.useRef<IInputSelection>(defaultSelection);
4848
const dispatch = useDispatch();
49-
const subscription = useSubscription(rid);
5049
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
5150
let placeholder = tmid ? I18n.t('Add_thread_reply') : '';
52-
if (subscription && !tmid) {
53-
placeholder = I18n.t('Message_roomname', { roomName: (subscription.t === 'd' ? '@' : '#') + getRoomTitle(subscription) });
51+
if (room && !tmid) {
52+
placeholder = I18n.t('Message_roomname', { roomName: (room.t === 'd' ? '@' : '#') + getRoomTitle(room) });
5453
if (!isTablet && placeholder.length > COMPOSER_INPUT_PLACEHOLDER_MAX_LENGTH) {
5554
placeholder = `${placeholder.slice(0, COMPOSER_INPUT_PLACEHOLDER_MAX_LENGTH)}...`;
5655
}
@@ -333,7 +332,7 @@ export const ComposerInput = memo(
333332
setAutocompleteParams({ text: autocompleteText, type: ':' });
334333
return;
335334
}
336-
if (lastWord.match(/^!/) && subscription?.t === 'l') {
335+
if (lastWord.match(/^!/) && room?.t === 'l') {
337336
setAutocompleteParams({ text: autocompleteText, type: '!' });
338337
return;
339338
}

app/containers/MessageComposer/hooks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export * from './useAutocomplete';
22
export * from './useAutoSaveDraft';
33
export * from './useCanUploadFile';
44
export * from './useChooseMedia';
5-
export * from './useSubscription';
65
export * from './useMessage';

app/containers/MessageComposer/hooks/useSubscription.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/views/RoomView/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IRoomContext {
66
rid?: string;
77
t?: string;
88
tmid?: string;
9+
room: any; // FIXME: type it properly after we migrate RoomView to hooks
910
sharing?: boolean;
1011
action?: TMessageAction;
1112
isAutocompleteVisible?: boolean;

app/views/RoomView/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
15231523
value={{
15241524
rid,
15251525
t,
1526+
room,
15261527
tmid: this.tmid,
15271528
sharing: false,
15281529
action,

app/views/ShareView/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
366366
value={{
367367
rid: room.rid,
368368
t: room.t,
369+
room,
369370
tmid: this.getThreadId(thread),
370371
sharing: true,
371372
action: route.params?.action,

0 commit comments

Comments
 (0)