fix: fixes sending files to start a thread (#5670)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gleidson Daniel Silva 2024-05-20 15:01:45 -04:00 committed by GitHub
parent c42d196b15
commit 0ffa528e2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 16 deletions

View File

@ -136,7 +136,7 @@ export const useChooseMedia = ({
// FIXME: use useNavigation // FIXME: use useNavigation
Navigation.navigate('ShareView', { Navigation.navigate('ShareView', {
room, room,
thread, thread: thread || tmid,
attachments, attachments,
action, action,
finishShareView, finishShareView,

View File

@ -276,7 +276,7 @@ export type InsideStackParamList = {
serverInfo: IServer; serverInfo: IServer;
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread: TThreadModel; thread: TThreadModel | string;
action: TMessageAction; action: TMessageAction;
finishShareView: (text?: string, selectedMessages?: string[]) => void | undefined; finishShareView: (text?: string, selectedMessages?: string[]) => void | undefined;
startShareView: () => { text: string; selectedMessages: string[] }; startShareView: () => { text: string; selectedMessages: string[] };

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native'; import { StyleSheet, Text, View } from 'react-native';
import I18n from '../../i18n'; import I18n from '../../i18n';
@ -9,6 +9,7 @@ import sharedStyles from '../Styles';
import { makeThreadName } from '../../lib/methods/helpers/room'; import { makeThreadName } from '../../lib/methods/helpers/room';
import { ISubscription, TThreadModel } from '../../definitions'; import { ISubscription, TThreadModel } from '../../definitions';
import { getRoomTitle, isGroupChat, isAndroid, isTablet } from '../../lib/methods/helpers'; import { getRoomTitle, isGroupChat, isAndroid, isTablet } from '../../lib/methods/helpers';
import { getMessageById } from '../../lib/database/services/Message';
const androidMarginLeft = isTablet ? 0 : 4; const androidMarginLeft = isTablet ? 0 : 4;
@ -36,13 +37,14 @@ const styles = StyleSheet.create({
interface IHeader { interface IHeader {
room: ISubscription; room: ISubscription;
thread: TThreadModel; thread: TThreadModel | string;
} }
const Header = React.memo(({ room, thread }: IHeader) => { const Header = React.memo(({ room, thread }: IHeader) => {
const [title, setTitle] = useState('');
const { theme } = useTheme(); const { theme } = useTheme();
let type; let type;
if (thread?.id) { if ((thread as TThreadModel)?.id || typeof thread === 'string') {
type = 'thread'; type = 'thread';
} else if (room?.prid) { } else if (room?.prid) {
type = 'discussion'; type = 'discussion';
@ -70,12 +72,28 @@ const Header = React.memo(({ room, thread }: IHeader) => {
const textColor = themes[theme].fontDefault; const textColor = themes[theme].fontDefault;
let title; useEffect(() => {
if (thread?.id) { (async () => {
title = makeThreadName(thread); if ((thread as TThreadModel)?.id) {
} else { const name = makeThreadName(thread as TThreadModel);
title = getRoomTitle(room); if (name) {
setTitle(name);
return;
} }
}
if (typeof thread === 'string') {
// only occurs when sending images and there is no message in the thread
const data = await getMessageById(thread);
const msg = data?.asPlain()?.msg;
if (msg) {
setTitle(msg);
return;
}
}
const name = getRoomTitle(room);
setTitle(name);
})();
}, []);
return ( return (
<View style={styles.container}> <View style={styles.container}>

View File

@ -43,7 +43,7 @@ interface IShareViewState {
attachments: IShareAttachment[]; attachments: IShareAttachment[];
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread: TThreadModel; thread: TThreadModel | string;
maxFileSize?: number; maxFileSize?: number;
mediaAllowList?: string; mediaAllowList?: string;
selectedMessages: string[]; selectedMessages: string[];
@ -88,7 +88,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
attachments: [], attachments: [],
text: props.route.params?.text ?? '', text: props.route.params?.text ?? '',
room: props.route.params?.room ?? {}, room: props.route.params?.room ?? {},
thread: props.route.params?.thread ?? {}, thread: props.route.params?.thread ?? '',
maxFileSize: this.isShareExtension ? this.serverInfo?.FileUpload_MaxFileSize : props.FileUpload_MaxFileSize, maxFileSize: this.isShareExtension ? this.serverInfo?.FileUpload_MaxFileSize : props.FileUpload_MaxFileSize,
mediaAllowList: this.isShareExtension mediaAllowList: this.isShareExtension
? this.serverInfo?.FileUpload_MediaTypeWhiteList ? this.serverInfo?.FileUpload_MediaTypeWhiteList
@ -265,7 +265,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
store: 'Uploads', store: 'Uploads',
msg msg
}, },
thread?.id, (thread as TThreadModel)?.id || (thread as string),
server, server,
{ id: user.id, token: user.token } { id: user.id, token: user.token }
); );
@ -276,7 +276,10 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
// Send text message // Send text message
} else if (text.length) { } else if (text.length) {
await sendMessage(room.rid, text, thread?.id, { id: user.id, token: user.token } as IUser); await sendMessage(room.rid, text, (thread as TThreadModel)?.id || (thread as string), {
id: user.id,
token: user.token
} as IUser);
} }
} catch { } catch {
if (!this.isShareExtension) { if (!this.isShareExtension) {
@ -344,7 +347,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
value={{ value={{
rid: room.rid, rid: room.rid,
t: room.t, t: room.t,
tmid: thread.id, tmid: (thread as TThreadModel)?.id || (thread as string),
sharing: true, sharing: true,
action: route.params?.action, action: route.params?.action,
selectedMessages, selectedMessages,