Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty draft when the message is sent #5595

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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