From 475d546a6d8a30145411d6f69ecf5c4d1bf8696e Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 21 Sep 2023 17:35:20 -0300 Subject: [PATCH 01/10] Nav to empty thread on "reply in thread" instead of quote layout --- app/containers/MessageActions/index.tsx | 8 ++++---- app/views/RoomView/index.tsx | 22 ++++++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/containers/MessageActions/index.tsx b/app/containers/MessageActions/index.tsx index f5822062ded..70fcaea2c45 100644 --- a/app/containers/MessageActions/index.tsx +++ b/app/containers/MessageActions/index.tsx @@ -27,7 +27,7 @@ export interface IMessageActionsProps { editInit: (messageId: string) => void; reactionInit: (messageId: string) => void; onReactionPress: (shortname: IEmoji, messageId: string) => void; - replyInit: (message: TAnyMessageModel, mention: boolean) => void; + replyInit: (messageId: string) => void; quoteInit: (messageId: string) => void; isMasterDetail: boolean; isReadOnly: boolean; @@ -172,9 +172,9 @@ const MessageActions = React.memo( const getPermalink = (message: TAnyMessageModel) => getPermalinkMessage(message); - const handleReply = (message: TAnyMessageModel) => { + const handleReply = (messageId: string) => { logEvent(events.ROOM_MSG_ACTION_REPLY); - replyInit(message, true); + replyInit(messageId); }; const handleEdit = (messageId: string) => { @@ -382,7 +382,7 @@ const MessageActions = React.memo( options.push({ title: I18n.t('Reply_in_Thread'), icon: 'threads', - onPress: () => handleReply(message) + onPress: () => handleReply(message.id) }); } diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 3d2b7c24922..74ee0851271 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -92,6 +92,7 @@ import { goRoom, TGoRoomItem } from '../../lib/methods/helpers/goRoom'; import { IMessageComposerRef, MessageComposerContainer } from '../../containers/MessageComposer'; import { RoomContext, TMessageAction } from './context'; import { IListContainerRef, TListRef } from './List/definitions'; +import { getMessageById } from '../../lib/database/services/Message'; type TStateAttrsUpdate = keyof IRoomViewState; @@ -785,15 +786,24 @@ class RoomView extends React.Component { } }; - onReplyInit = (message: TAnyMessageModel, mention: boolean) => { + onReplyInit = async (messageId: string) => { + const message = await getMessageById(messageId); + if (!message || !this.rid) { + return; + } + // If there's a thread already, we redirect to it - if (mention && !!message.tlm) { + if (message.tlm) { return this.onThreadPress(message); } - this.setState({ - selectedMessage: message, - replying: true, - replyWithMention: mention + const { roomUserId } = this.state; + const { navigation } = this.props; + navigation.push('RoomView', { + rid: this.rid, + tmid: messageId, + name: makeThreadName(message), + t: SubscriptionType.THREAD, + roomUserId }); }; From fbccbf803cbf9dc8975d5de4fd155bb4166ee27c Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 22 Sep 2023 09:31:13 -0300 Subject: [PATCH 02/10] Fetch thread header from messages --- app/views/RoomView/List/hooks/useMessages.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/views/RoomView/List/hooks/useMessages.ts b/app/views/RoomView/List/hooks/useMessages.ts index 0f5fa0c156a..7ab29a72111 100644 --- a/app/views/RoomView/List/hooks/useMessages.ts +++ b/app/views/RoomView/List/hooks/useMessages.ts @@ -4,6 +4,7 @@ import { Subscription } from 'rxjs'; import { TAnyMessageModel, TThreadModel } from '../../../../definitions'; import database from '../../../../lib/database'; +import { getMessageById } from '../../../../lib/database/services/Message'; import { getThreadById } from '../../../../lib/database/services/Thread'; import { animateNextTransition, compareServerVersion, isIOS, useDebounce } from '../../../../lib/methods/helpers'; import { Services } from '../../../../lib/services'; @@ -23,7 +24,7 @@ export const useMessages = ({ hideSystemMessages: string[]; }) => { const [messages, setMessages] = useState([]); - const thread = useRef(null); + const thread = useRef(null); const count = useRef(0); const subscription = useRef(null); const messagesIds = useRef([]); @@ -39,8 +40,13 @@ export const useMessages = ({ const db = database.active; let observable; if (tmid) { - if (!thread.current) { + // If the thread doesn't exist yet, we fetch it from messages, but trying to get it from threads when possible. + // As soon as we have it from threads table, we use it from cache only and never query again. + if (!thread.current || thread.current.collection.table !== 'threads') { thread.current = await getThreadById(tmid); + if (!thread.current) { + thread.current = await getMessageById(tmid); + } } observable = db .get('thread_messages') From d6781e5d3b04623232e35cf32f368c6ee492cf75 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 22 Sep 2023 10:41:48 -0300 Subject: [PATCH 03/10] SendThreadToChannel --- .../MessageComposer/MessageComposer.tsx | 18 +++++--- .../components/SendThreadToChannel.tsx | 42 +++++++++++++++++++ .../MessageComposer/components/index.ts | 2 + app/containers/MessageComposer/context.tsx | 19 +++++++-- app/i18n/locales/en.json | 2 +- app/views/RoomView/context.ts | 2 +- app/views/RoomView/index.tsx | 6 +-- 7 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 app/containers/MessageComposer/components/SendThreadToChannel.tsx diff --git a/app/containers/MessageComposer/MessageComposer.tsx b/app/containers/MessageComposer/MessageComposer.tsx index f0645810539..ae0099a2fd7 100644 --- a/app/containers/MessageComposer/MessageComposer.tsx +++ b/app/containers/MessageComposer/MessageComposer.tsx @@ -5,9 +5,15 @@ import { useBackHandler } from '@react-native-community/hooks'; import { Q } from '@nozbe/watermelondb'; import { useRoomContext } from '../../views/RoomView/context'; -import { Autocomplete, Toolbar, EmojiSearchbar, ComposerInput, Left, Right } from './components'; +import { Autocomplete, Toolbar, EmojiSearchbar, ComposerInput, Left, Right, Quotes, SendThreadToChannel } from './components'; import { MIN_HEIGHT, NO_CANNED_RESPONSES, TIMEOUT_CLOSE_EMOJI_KEYBOARD } from './constants'; -import { MessageInnerContext, useMessageComposerApi, useShowEmojiKeyboard, useShowEmojiSearchbar } from './context'; +import { + MessageInnerContext, + useAlsoSendThreadToChannel, + useMessageComposerApi, + useShowEmojiKeyboard, + useShowEmojiSearchbar +} from './context'; import { IAutocompleteItemProps, IComposerInput, ITrackingView } from './interfaces'; import { isIOS } from '../../lib/methods/helpers'; import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode'; @@ -24,7 +30,6 @@ import log, { events, logEvent } from '../../lib/methods/helpers/log'; import { fetchIsAllOrHere, prepareQuoteMessage } from './helpers'; import Navigation from '../../lib/navigation/appNavigation'; import { emitter } from './emitter'; -import { Quotes } from './components/Quotes'; const styles = StyleSheet.create({ container: { @@ -54,6 +59,7 @@ export const MessageComposer = ({ forwardedRef }: { forwardedRef: any }): ReactE const { rid, tmid, action, selectedMessages, editRequest, onSendMessage } = useRoomContext(); const showEmojiKeyboard = useShowEmojiKeyboard(); const showEmojiSearchbar = useShowEmojiSearchbar(); + const alsoSendThreadToChannel = useAlsoSendThreadToChannel(); const { setKeyboardHeight, openSearchEmojiKeyboard, closeEmojiKeyboard, closeSearchEmojiKeyboard } = useMessageComposerApi(); const isMasterDetail = useAppSelector(state => state.app.isMasterDetail); @@ -121,8 +127,7 @@ export const MessageComposer = ({ forwardedRef }: { forwardedRef: any }): ReactE const messageWithoutCommand = textFromInput.replace(/([^\s]+)/, '').trim(); const [{ appId }] = slashCommand; const triggerId = generateTriggerId(appId); - await Services.runSlashCommand(command, rid, messageWithoutCommand, triggerId, tmid); // || messageTmid); - // replyCancel(); + await Services.runSlashCommand(command, rid, messageWithoutCommand, triggerId, tmid); } catch (e) { log(e); } @@ -131,7 +136,7 @@ export const MessageComposer = ({ forwardedRef }: { forwardedRef: any }): ReactE } // Text message - onSendMessage(textFromInput); + onSendMessage(textFromInput, alsoSendThreadToChannel); }; const onKeyboardItemSelected = (_keyboardId: string, params: { eventType: EventTypes; emoji: IEmoji }) => { @@ -283,6 +288,7 @@ export const MessageComposer = ({ forwardedRef }: { forwardedRef: any }): ReactE + ); }, []); diff --git a/app/containers/MessageComposer/components/SendThreadToChannel.tsx b/app/containers/MessageComposer/components/SendThreadToChannel.tsx new file mode 100644 index 00000000000..420e73511c3 --- /dev/null +++ b/app/containers/MessageComposer/components/SendThreadToChannel.tsx @@ -0,0 +1,42 @@ +import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; +import { Text } from 'react-native'; +import React from 'react'; + +import { useRoomContext } from '../../../views/RoomView/context'; +import { useAlsoSendThreadToChannel, useMessageComposerApi } from '../context'; +import { CustomIcon } from '../../CustomIcon'; +import { useTheme } from '../../../theme'; +import sharedStyles from '../../../views/Styles'; +import I18n from '../../../i18n'; + +export const SendThreadToChannel = (): React.ReactElement | null => { + const alsoSendThreadToChannel = useAlsoSendThreadToChannel(); + const { setAlsoSendThreadToChannel } = useMessageComposerApi(); + const { tmid } = useRoomContext(); + const { colors } = useTheme(); + + if (!tmid) { + return null; + } + + return ( + setAlsoSendThreadToChannel(!alsoSendThreadToChannel)} + testID='composer-send-to-channel' + > + + + {I18n.t('Messagebox_Send_to_channel')} + + + ); +}; diff --git a/app/containers/MessageComposer/components/index.ts b/app/containers/MessageComposer/components/index.ts index c0c77cb1d7e..7d9e9e6caf1 100644 --- a/app/containers/MessageComposer/components/index.ts +++ b/app/containers/MessageComposer/components/index.ts @@ -4,3 +4,5 @@ export * from './ComposerInput'; export * from './EmojiSearchbar'; export * from './Toolbar'; export * from './Unfocused'; +export * from './Quotes'; +export * from './SendThreadToChannel'; diff --git a/app/containers/MessageComposer/context.tsx b/app/containers/MessageComposer/context.tsx index f911e4619f4..125a06531a5 100644 --- a/app/containers/MessageComposer/context.tsx +++ b/app/containers/MessageComposer/context.tsx @@ -13,6 +13,7 @@ type TMessageComposerContextApi = { setFocused(focused: boolean): void; setMicOrSend(micOrSend: TMicOrSend): void; setMarkdownToolbar(showMarkdownToolbar: boolean): void; + setAlsoSendThreadToChannel(alsoSendThreadToChannel: boolean): void; }; const FocusedContext = createContext({} as State['focused']); @@ -22,6 +23,7 @@ const ShowEmojiKeyboardContext = createContext({} as const ShowEmojiSearchbarContext = createContext({} as State['showEmojiSearchbar']); const KeyboardHeightContext = createContext({} as State['keyboardHeight']); const TrackingViewHeightContext = createContext({} as State['trackingViewHeight']); +const AlsoSendThreadToChannelContext = createContext({} as State['alsoSendThreadToChannel']); const MessageComposerContextApi = createContext({} as TMessageComposerContextApi); export const useMessageComposerApi = (): TMessageComposerContextApi => useContext(MessageComposerContextApi); @@ -32,6 +34,7 @@ export const useShowEmojiKeyboard = (): State['showEmojiKeyboard'] => useContext export const useShowEmojiSearchbar = (): State['showEmojiSearchbar'] => useContext(ShowEmojiSearchbarContext); export const useKeyboardHeight = (): State['keyboardHeight'] => useContext(KeyboardHeightContext); export const useTrackingViewHeight = (): State['trackingViewHeight'] => useContext(TrackingViewHeightContext); +export const useAlsoSendThreadToChannel = (): State['alsoSendThreadToChannel'] => useContext(AlsoSendThreadToChannelContext); // TODO: rename type TMessageInnerContext = { @@ -56,6 +59,7 @@ type State = { keyboardHeight: number; micOrSend: TMicOrSend; showMarkdownToolbar: boolean; + alsoSendThreadToChannel: boolean; }; type Actions = @@ -69,7 +73,8 @@ type Actions = | { type: 'openSearchEmojiKeyboard' } | { type: 'closeSearchEmojiKeyboard' } | { type: 'setMicOrSend'; micOrSend: TMicOrSend } - | { type: 'setMarkdownToolbar'; showMarkdownToolbar: boolean }; + | { type: 'setMarkdownToolbar'; showMarkdownToolbar: boolean } + | { type: 'setAlsoSendThreadToChannel'; alsoSendThreadToChannel: boolean }; const reducer = (state: State, action: Actions): State => { switch (action.type) { @@ -95,6 +100,8 @@ const reducer = (state: State, action: Actions): State => { return { ...state, micOrSend: action.micOrSend }; case 'setMarkdownToolbar': return { ...state, showMarkdownToolbar: action.showMarkdownToolbar }; + case 'setAlsoSendThreadToChannel': + return { ...state, alsoSendThreadToChannel: action.alsoSendThreadToChannel }; } }; @@ -121,6 +128,9 @@ export const MessageComposerProvider = ({ children }: { children: ReactElement } const setMarkdownToolbar = (showMarkdownToolbar: boolean) => dispatch({ type: 'setMarkdownToolbar', showMarkdownToolbar }); + const setAlsoSendThreadToChannel = (alsoSendThreadToChannel: boolean) => + dispatch({ type: 'setAlsoSendThreadToChannel', alsoSendThreadToChannel }); + return { setFocused, setKeyboardHeight, @@ -130,7 +140,8 @@ export const MessageComposerProvider = ({ children }: { children: ReactElement } openSearchEmojiKeyboard, closeSearchEmojiKeyboard, setMicOrSend, - setMarkdownToolbar + setMarkdownToolbar, + setAlsoSendThreadToChannel }; }, []); @@ -142,7 +153,9 @@ export const MessageComposerProvider = ({ children }: { children: ReactElement } - {children} + + {children} + diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index ccefeb38fc7..e74bf666f00 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -530,7 +530,7 @@ "No_threads": "There are no threads", "No_threads_following": "You are not following any threads", "No_threads_unread": "There are no unread threads", - "Messagebox_Send_to_channel": "Send to channel", + "Messagebox_Send_to_channel": "Also send to channel", "Leader": "Leader", "Moderator": "Moderator", "Owner": "Owner", diff --git a/app/views/RoomView/context.ts b/app/views/RoomView/context.ts index 2e7c408f16c..82ac922daac 100644 --- a/app/views/RoomView/context.ts +++ b/app/views/RoomView/context.ts @@ -11,7 +11,7 @@ export interface IRoomContext { editCancel: () => void; editRequest: (message: any) => void; - onSendMessage: (message: any) => void; + onSendMessage: (message: string, tshow?: boolean) => void; onRemoveQuoteMessage: (messageId: string) => void; } diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 74ee0851271..0d199ca82f8 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -90,7 +90,7 @@ import { Services } from '../../lib/services'; import { withActionSheet, IActionSheetProvider } from '../../containers/ActionSheet'; import { goRoom, TGoRoomItem } from '../../lib/methods/helpers/goRoom'; import { IMessageComposerRef, MessageComposerContainer } from '../../containers/MessageComposer'; -import { RoomContext, TMessageAction } from './context'; +import { IRoomContext, RoomContext, TMessageAction } from './context'; import { IListContainerRef, TListRef } from './List/definitions'; import { getMessageById } from '../../lib/database/services/Message'; @@ -1064,11 +1064,11 @@ class RoomView extends React.Component { this.setState(...args); }; - handleSendMessage = (message: string, tmid?: string, tshow?: boolean) => { + handleSendMessage: IRoomContext['onSendMessage'] = (message, tshow) => { logEvent(events.ROOM_SEND_MESSAGE); const { rid } = this.state.room; const { user } = this.props; - sendMessage(rid, message, this.tmid || tmid, user, tshow).then(() => { + sendMessage(rid, message, this.tmid, user, tshow).then(() => { this.setLastOpen(null); Review.pushPositiveEvent(); }); From c618818de3abe7f2e82ce3d8ceffab08ab18b822 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 22 Sep 2023 15:46:01 -0300 Subject: [PATCH 04/10] Add thread reply --- app/containers/MessageComposer/components/ComposerInput.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/containers/MessageComposer/components/ComposerInput.tsx b/app/containers/MessageComposer/components/ComposerInput.tsx index 0194d8dda11..55c37d1e8e5 100644 --- a/app/containers/MessageComposer/components/ComposerInput.tsx +++ b/app/containers/MessageComposer/components/ComposerInput.tsx @@ -45,8 +45,9 @@ export const ComposerInput = memo( const selectionRef = React.useRef(defaultSelection); const dispatch = useDispatch(); const subscription = useSubscription(rid); - let placeholder = 'Message '; - if (subscription) { + // TODO: i18n + let placeholder = tmid ? 'Add thread reply' : 'Message '; + if (subscription && !tmid) { placeholder += subscription.t === 'd' ? '@' : '#'; placeholder += getRoomTitle(subscription); } From 96e0581b14c7d9bcd0f8e36353b272eeae6a939d Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Sep 2023 13:19:39 -0300 Subject: [PATCH 05/10] Fix unselected checkbox color --- .../MessageComposer/components/SendThreadToChannel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/containers/MessageComposer/components/SendThreadToChannel.tsx b/app/containers/MessageComposer/components/SendThreadToChannel.tsx index 420e73511c3..ad8ce58098b 100644 --- a/app/containers/MessageComposer/components/SendThreadToChannel.tsx +++ b/app/containers/MessageComposer/components/SendThreadToChannel.tsx @@ -32,7 +32,7 @@ export const SendThreadToChannel = (): React.ReactElement | null => { testID={alsoSendThreadToChannel ? 'send-to-channel-checked' : 'send-to-channel-unchecked'} name={alsoSendThreadToChannel ? 'checkbox-checked' : 'checkbox-unchecked'} size={24} - color={alsoSendThreadToChannel ? colors.buttonBackgroundPrimaryDefault : colors.buttonBackgroundSecondaryDefault} + color={alsoSendThreadToChannel ? colors.buttonBackgroundPrimaryDefault : colors.strokeDark} /> {I18n.t('Messagebox_Send_to_channel')} From 8a967b2d12cb473a22c658964f37ed1758276b59 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Sep 2023 17:44:18 -0300 Subject: [PATCH 06/10] AlsoSendThreadToChannel user pref --- .../components/SendThreadToChannel.tsx | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/app/containers/MessageComposer/components/SendThreadToChannel.tsx b/app/containers/MessageComposer/components/SendThreadToChannel.tsx index ad8ce58098b..e25e683c16f 100644 --- a/app/containers/MessageComposer/components/SendThreadToChannel.tsx +++ b/app/containers/MessageComposer/components/SendThreadToChannel.tsx @@ -1,6 +1,8 @@ import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; import { Text } from 'react-native'; -import React from 'react'; +import React, { useEffect, useRef } from 'react'; +import { Subscription } from 'rxjs'; +import { Q } from '@nozbe/watermelondb'; import { useRoomContext } from '../../../views/RoomView/context'; import { useAlsoSendThreadToChannel, useMessageComposerApi } from '../context'; @@ -8,12 +10,57 @@ import { CustomIcon } from '../../CustomIcon'; import { useTheme } from '../../../theme'; import sharedStyles from '../../../views/Styles'; import I18n from '../../../i18n'; +import { useAppSelector } from '../../../lib/hooks'; +import database from '../../../lib/database'; +import { compareServerVersion } from '../../../lib/methods/helpers'; export const SendThreadToChannel = (): React.ReactElement | null => { const alsoSendThreadToChannel = useAlsoSendThreadToChannel(); const { setAlsoSendThreadToChannel } = useMessageComposerApi(); const { tmid } = useRoomContext(); const { colors } = useTheme(); + const subscription = useRef(); + const alsoSendThreadToChannelUserPref = useAppSelector(state => state.login.user.alsoSendThreadToChannel); + const serverVersion = useAppSelector(state => state.server.version); + + useEffect(() => { + if (!tmid) { + return; + } + + if (compareServerVersion(serverVersion, 'lowerThan', '5.0.0')) { + setAlsoSendThreadToChannel(false); + return; + } + + if (alsoSendThreadToChannelUserPref === 'always') { + setAlsoSendThreadToChannel(true); + return; + } + if (alsoSendThreadToChannelUserPref === 'never') { + setAlsoSendThreadToChannel(false); + return; + } + + /** + * "default" sends a to channel only in the first message of the thread. + * We check if the thread exists by observing/subscribing to the query with tmid. + * If it doesn't exist, it means that this is the first message of the thread. So it's true. + * Otherwise, it's false. + * */ + if (alsoSendThreadToChannelUserPref === 'default') { + const db = database.active; + const observable = db.get('threads').query(Q.where('tmid', tmid)).observe(); + + subscription.current = observable.subscribe(result => { + setAlsoSendThreadToChannel(!result.length); + }); + } + + return () => { + subscription.current?.unsubscribe(); + }; + }, [tmid, alsoSendThreadToChannelUserPref, serverVersion, setAlsoSendThreadToChannel]); if (!tmid) { return null; From 24675d9c0706db84119501461c23f22c0d962634 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Sep 2023 17:45:50 -0300 Subject: [PATCH 07/10] Cleanup --- app/views/RoomView/index.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index 0d199ca82f8..e5c4586d10f 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -807,10 +807,6 @@ class RoomView extends React.Component { }); }; - onReplyCancel = () => { - this.setState({ selectedMessage: undefined, replying: false, replyWithMention: false }); - }; - onQuoteInit = (messageId: string) => { const { action } = this.state; if (action === 'quote') { From a5f32426436de497ff606ac4a3277a3fd29cde7d Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Sep 2023 18:25:50 -0300 Subject: [PATCH 08/10] Reply in dm --- app/containers/MessageActions/index.tsx | 2 +- app/stacks/types.ts | 2 +- app/views/RoomView/index.tsx | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/containers/MessageActions/index.tsx b/app/containers/MessageActions/index.tsx index 70fcaea2c45..cab553fac73 100644 --- a/app/containers/MessageActions/index.tsx +++ b/app/containers/MessageActions/index.tsx @@ -270,7 +270,7 @@ const MessageActions = React.memo( name: getRoomTitle(room), t: room.t, roomUserId: getUidDirectMessage(room), - replyInDM: message + replyInDM: message.id }; Navigation.replace('RoomView', params); } diff --git a/app/stacks/types.ts b/app/stacks/types.ts index 32715c66230..2f8f0280e43 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -36,7 +36,7 @@ export type ChatsStackParamList = { roomUserId?: string | null; usedCannedResponse?: string; status?: string; - replyInDM?: TAnyMessageModel; + replyInDM?: string; } | undefined; // Navigates back to RoomView already on stack RoomActionsView: { diff --git a/app/views/RoomView/index.tsx b/app/views/RoomView/index.tsx index e5c4586d10f..4dedbde04c3 100644 --- a/app/views/RoomView/index.tsx +++ b/app/views/RoomView/index.tsx @@ -211,7 +211,6 @@ class RoomView extends React.Component { // FlatList inside ListContainer private flatList: TListRef; private mounted: boolean; - private offset = 0; private subObserveQuery?: Subscription; private subSubscription?: Subscription; private queryUnreads?: Subscription; @@ -219,7 +218,7 @@ class RoomView extends React.Component { private retryInitTimeout?: ReturnType; private messageErrorActions?: IMessageErrorActions | null; private messageActions?: IMessageActions | null; - private replyInDM?: TAnyMessageModel; + private replyInDM?: string; // Type of InteractionManager.runAfterInteractions private didMountInteraction?: { then: (onfulfilled?: (() => any) | undefined, onrejected?: (() => any) | undefined) => Promise; @@ -327,7 +326,7 @@ class RoomView extends React.Component { this.updateUnreadCount(); } if (this.replyInDM) { - this.onReplyInit(this.replyInDM, false); + this.onQuoteInit(this.replyInDM); } }); EventEmitter.addEventListener('ROOM_REMOVED', this.handleRoomRemoved); From 8fe36ad819ccac2761e8355bd1ccd19ce6bcd60a Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 25 Sep 2023 18:30:41 -0300 Subject: [PATCH 09/10] lint --- app/containers/message/index.tsx | 5 +++-- app/views/RoomView/List/hooks/useMessages.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/containers/message/index.tsx b/app/containers/message/index.tsx index 1771b5f3043..ff2335b6ab9 100644 --- a/app/containers/message/index.tsx +++ b/app/containers/message/index.tsx @@ -9,6 +9,7 @@ import { TSupportedThemes, withTheme } from '../../theme'; import openLink from '../../lib/methods/helpers/openLink'; import { IAttachment, TAnyMessageModel, TGetCustomEmoji } from '../../definitions'; import { IRoomInfoParam } from '../../views/SearchMessagesView'; +import { IRoomContext } from '../../views/RoomView/context'; import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../../lib/constants'; interface IMessageContainerProps { @@ -51,7 +52,7 @@ interface IMessageContainerProps { navToRoomInfo?: (navParam: IRoomInfoParam) => void; handleEnterCall?: () => void; blockAction?: (params: { actionId: string; appId: string; value: string; blockId: string; rid: string; mid: string }) => void; - onAnswerButtonPress?: (message: string, tmid?: string, tshow?: boolean) => void; + onAnswerButtonPress?: IRoomContext['onSendMessage']; threadBadgeColor?: string; toggleFollowThread?: (isFollowingThread: boolean, tmid?: string) => Promise; jumpToMessage?: (link: string) => void; @@ -225,7 +226,7 @@ class MessageContainer extends React.Component { const { onAnswerButtonPress } = this.props; if (onAnswerButtonPress) { - onAnswerButtonPress(msg, undefined, false); + onAnswerButtonPress(msg, false); } }; diff --git a/app/views/RoomView/List/hooks/useMessages.ts b/app/views/RoomView/List/hooks/useMessages.ts index 7ab29a72111..b0f3543f0fb 100644 --- a/app/views/RoomView/List/hooks/useMessages.ts +++ b/app/views/RoomView/List/hooks/useMessages.ts @@ -2,7 +2,7 @@ import { useCallback, useLayoutEffect, useRef, useState } from 'react'; import { Q } from '@nozbe/watermelondb'; import { Subscription } from 'rxjs'; -import { TAnyMessageModel, TThreadModel } from '../../../../definitions'; +import { TAnyMessageModel } from '../../../../definitions'; import database from '../../../../lib/database'; import { getMessageById } from '../../../../lib/database/services/Message'; import { getThreadById } from '../../../../lib/database/services/Thread'; From 5ae561b6b4fd40149ffe8e3113e344d20bb54b71 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 26 Sep 2023 10:13:38 -0300 Subject: [PATCH 10/10] Fix tests --- .../MessageComposer/MessageComposer.test.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/containers/MessageComposer/MessageComposer.test.tsx b/app/containers/MessageComposer/MessageComposer.test.tsx index 50cd9c4ed6d..c91145d119f 100644 --- a/app/containers/MessageComposer/MessageComposer.test.tsx +++ b/app/containers/MessageComposer/MessageComposer.test.tsx @@ -105,7 +105,7 @@ test('send message', async () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('test'); + expect(onSendMessage).toHaveBeenCalledWith('test', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -158,7 +158,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('**'); + expect(onSendMessage).toHaveBeenCalledWith('**', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -177,7 +177,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('*test*'); + expect(onSendMessage).toHaveBeenCalledWith('*test*', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -192,7 +192,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('__'); + expect(onSendMessage).toHaveBeenCalledWith('__', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -211,7 +211,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('_test_'); + expect(onSendMessage).toHaveBeenCalledWith('_test_', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -226,7 +226,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('~~'); + expect(onSendMessage).toHaveBeenCalledWith('~~', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -245,7 +245,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('~test~'); + expect(onSendMessage).toHaveBeenCalledWith('~test~', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -260,7 +260,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('``'); + expect(onSendMessage).toHaveBeenCalledWith('``', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -279,7 +279,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('`test`'); + expect(onSendMessage).toHaveBeenCalledWith('`test`', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -294,7 +294,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('``````'); + expect(onSendMessage).toHaveBeenCalledWith('``````', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); @@ -313,7 +313,7 @@ describe('Markdown', () => { await fireEvent.press(screen.getByTestId('message-composer-send')); }); expect(onSendMessage).toHaveBeenCalledTimes(1); - expect(onSendMessage).toHaveBeenCalledWith('```test```'); + expect(onSendMessage).toHaveBeenCalledWith('```test```', undefined); expect(screen.toJSON()).toMatchSnapshot(); }); });