fix: empty draft when the message is sent (#5595)
* chore: move draftMessage to helpers * fix: set draft when the message is sent
This commit is contained in:
parent
f3ee2dc7d9
commit
54f2cea4e9
|
@ -7,7 +7,7 @@ import { RouteProp, useFocusEffect, useRoute } from '@react-navigation/native';
|
||||||
import I18n from '../../../i18n';
|
import I18n from '../../../i18n';
|
||||||
import { IAutocompleteItemProps, IComposerInput, IComposerInputProps, IInputSelection, TSetInput } from '../interfaces';
|
import { IAutocompleteItemProps, IComposerInput, IComposerInputProps, IInputSelection, TSetInput } from '../interfaces';
|
||||||
import { useAutocompleteParams, useFocused, useMessageComposerApi } from '../context';
|
import { useAutocompleteParams, useFocused, useMessageComposerApi } from '../context';
|
||||||
import { loadDraftMessage, fetchIsAllOrHere, getMentionRegexp } from '../helpers';
|
import { fetchIsAllOrHere, getMentionRegexp } from '../helpers';
|
||||||
import { useSubscription, useAutoSaveDraft } from '../hooks';
|
import { useSubscription, useAutoSaveDraft } from '../hooks';
|
||||||
import sharedStyles from '../../../views/Styles';
|
import sharedStyles from '../../../views/Styles';
|
||||||
import { useTheme } from '../../../theme';
|
import { useTheme } from '../../../theme';
|
||||||
|
@ -24,6 +24,7 @@ import { Services } from '../../../lib/services';
|
||||||
import log from '../../../lib/methods/helpers/log';
|
import log from '../../../lib/methods/helpers/log';
|
||||||
import { useAppSelector, usePrevious } from '../../../lib/hooks';
|
import { useAppSelector, usePrevious } from '../../../lib/hooks';
|
||||||
import { ChatsStackParamList } from '../../../stacks/types';
|
import { ChatsStackParamList } from '../../../stacks/types';
|
||||||
|
import { loadDraftMessage } from '../../../lib/methods/draftMessage';
|
||||||
|
|
||||||
const defaultSelection: IInputSelection = { start: 0, end: 0 };
|
const defaultSelection: IInputSelection = { start: 0, end: 0 };
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
export * from './draftMessage';
|
|
||||||
export * from './fetchIsAllOrHere';
|
export * from './fetchIsAllOrHere';
|
||||||
export * from './forceJpgExtension';
|
export * from './forceJpgExtension';
|
||||||
export * from './getMentionRegexp';
|
export * from './getMentionRegexp';
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { useCallback, useEffect, useRef } from 'react';
|
import { useCallback, useEffect, useRef } from 'react';
|
||||||
|
|
||||||
import { saveDraftMessage } from '../helpers';
|
|
||||||
import { useRoomContext } from '../../../views/RoomView/context';
|
import { useRoomContext } from '../../../views/RoomView/context';
|
||||||
import { useFocused } from '../context';
|
import { useFocused } from '../context';
|
||||||
|
import { saveDraftMessage } from '../../../lib/methods/draftMessage';
|
||||||
|
|
||||||
export const useAutoSaveDraft = (text = '') => {
|
export const useAutoSaveDraft = (text = '') => {
|
||||||
const { rid, tmid, action, selectedMessages } = useRoomContext();
|
const { rid, tmid, action, selectedMessages } = useRoomContext();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import log from '../../../lib/methods/helpers/log';
|
import database from '../database';
|
||||||
import database from '../../../lib/database';
|
import { getSubscriptionByRoomId } from '../database/services/Subscription';
|
||||||
import { getSubscriptionByRoomId } from '../../../lib/database/services/Subscription';
|
import { getThreadById } from '../database/services/Thread';
|
||||||
import { getThreadById } from '../../../lib/database/services/Thread';
|
import log from './helpers/log';
|
||||||
|
|
||||||
export const loadDraftMessage = async ({ rid, tmid }: { rid?: string; tmid?: string }): Promise<string> => {
|
export const loadDraftMessage = async ({ rid, tmid }: { rid?: string; tmid?: string }): Promise<string> => {
|
||||||
if (tmid) {
|
if (tmid) {
|
|
@ -8,6 +8,7 @@ import { Encryption } from '../encryption';
|
||||||
import { E2EType, IMessage, IUser, TMessageModel } from '../../definitions';
|
import { E2EType, IMessage, IUser, TMessageModel } from '../../definitions';
|
||||||
import sdk from '../services/sdk';
|
import sdk from '../services/sdk';
|
||||||
import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../constants';
|
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 changeMessageStatus = async (id: string, status: number, tmid?: string, message?: IMessage) => {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
|
@ -231,6 +232,9 @@ export async function sendMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendMessageCall(message);
|
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) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue