Skip to content

Commit

Permalink
fix: empty draft when the message is sent (#5595)
Browse files Browse the repository at this point in the history
* chore: move draftMessage to helpers

* fix: set draft when the message is sent
  • Loading branch information
dnlsilva authored Feb 28, 2024
1 parent f3ee2dc commit 54f2cea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/containers/MessageComposer/components/ComposerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RouteProp, useFocusEffect, useRoute } from '@react-navigation/native';
import I18n from '../../../i18n';
import { IAutocompleteItemProps, IComposerInput, IComposerInputProps, IInputSelection, TSetInput } from '../interfaces';
import { useAutocompleteParams, useFocused, useMessageComposerApi } from '../context';
import { loadDraftMessage, fetchIsAllOrHere, getMentionRegexp } from '../helpers';
import { fetchIsAllOrHere, getMentionRegexp } from '../helpers';
import { useSubscription, useAutoSaveDraft } from '../hooks';
import sharedStyles from '../../../views/Styles';
import { useTheme } from '../../../theme';
Expand All @@ -24,6 +24,7 @@ import { Services } from '../../../lib/services';
import log from '../../../lib/methods/helpers/log';
import { useAppSelector, usePrevious } from '../../../lib/hooks';
import { ChatsStackParamList } from '../../../stacks/types';
import { loadDraftMessage } from '../../../lib/methods/draftMessage';

const defaultSelection: IInputSelection = { start: 0, end: 0 };

Expand Down
1 change: 0 additions & 1 deletion app/containers/MessageComposer/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './draftMessage';
export * from './fetchIsAllOrHere';
export * from './forceJpgExtension';
export * from './getMentionRegexp';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/MessageComposer/hooks/useAutoSaveDraft.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback, useEffect, useRef } from 'react';

import { saveDraftMessage } from '../helpers';
import { useRoomContext } from '../../../views/RoomView/context';
import { useFocused } from '../context';
import { saveDraftMessage } from '../../../lib/methods/draftMessage';

export const useAutoSaveDraft = (text = '') => {
const { rid, tmid, action, selectedMessages } = useRoomContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import log from '../../../lib/methods/helpers/log';
import database from '../../../lib/database';
import { getSubscriptionByRoomId } from '../../../lib/database/services/Subscription';
import { getThreadById } from '../../../lib/database/services/Thread';
import database from '../database';
import { getSubscriptionByRoomId } from '../database/services/Subscription';
import { getThreadById } from '../database/services/Thread';
import log from './helpers/log';

export const loadDraftMessage = async ({ rid, tmid }: { rid?: string; tmid?: string }): Promise<string> => {
if (tmid) {
Expand Down
4 changes: 4 additions & 0 deletions app/lib/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Encryption } from '../encryption';
import { E2EType, IMessage, IUser, TMessageModel } from '../../definitions';
import sdk from '../services/sdk';
import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../constants';
import { saveDraftMessage } from './draftMessage';

const changeMessageStatus = async (id: string, status: number, tmid?: string, message?: IMessage) => {
const db = database.active;
Expand Down Expand Up @@ -231,6 +232,9 @@ export async function sendMessage(
}

await sendMessageCall(message);
// clear draft message when message is sent and app is in background or closed
// do not affect the user experience when the app is in the foreground because the hook useAutoSaveDraft will handle it
saveDraftMessage({ rid, tmid, draftMessage: '' });
} catch (e) {
log(e);
}
Expand Down

0 comments on commit 54f2cea

Please sign in to comment.