fix: fixes sending files to start a thread (#5670)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
c42d196b15
commit
0ffa528e2a
|
@ -136,7 +136,7 @@ export const useChooseMedia = ({
|
|||
// FIXME: use useNavigation
|
||||
Navigation.navigate('ShareView', {
|
||||
room,
|
||||
thread,
|
||||
thread: thread || tmid,
|
||||
attachments,
|
||||
action,
|
||||
finishShareView,
|
||||
|
|
|
@ -276,7 +276,7 @@ export type InsideStackParamList = {
|
|||
serverInfo: IServer;
|
||||
text: string;
|
||||
room: TSubscriptionModel;
|
||||
thread: TThreadModel;
|
||||
thread: TThreadModel | string;
|
||||
action: TMessageAction;
|
||||
finishShareView: (text?: string, selectedMessages?: string[]) => void | undefined;
|
||||
startShareView: () => { text: string; selectedMessages: string[] };
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
|
||||
import I18n from '../../i18n';
|
||||
|
@ -9,6 +9,7 @@ import sharedStyles from '../Styles';
|
|||
import { makeThreadName } from '../../lib/methods/helpers/room';
|
||||
import { ISubscription, TThreadModel } from '../../definitions';
|
||||
import { getRoomTitle, isGroupChat, isAndroid, isTablet } from '../../lib/methods/helpers';
|
||||
import { getMessageById } from '../../lib/database/services/Message';
|
||||
|
||||
const androidMarginLeft = isTablet ? 0 : 4;
|
||||
|
||||
|
@ -36,13 +37,14 @@ const styles = StyleSheet.create({
|
|||
|
||||
interface IHeader {
|
||||
room: ISubscription;
|
||||
thread: TThreadModel;
|
||||
thread: TThreadModel | string;
|
||||
}
|
||||
|
||||
const Header = React.memo(({ room, thread }: IHeader) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const { theme } = useTheme();
|
||||
let type;
|
||||
if (thread?.id) {
|
||||
if ((thread as TThreadModel)?.id || typeof thread === 'string') {
|
||||
type = 'thread';
|
||||
} else if (room?.prid) {
|
||||
type = 'discussion';
|
||||
|
@ -70,12 +72,28 @@ const Header = React.memo(({ room, thread }: IHeader) => {
|
|||
|
||||
const textColor = themes[theme].fontDefault;
|
||||
|
||||
let title;
|
||||
if (thread?.id) {
|
||||
title = makeThreadName(thread);
|
||||
} else {
|
||||
title = getRoomTitle(room);
|
||||
}
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if ((thread as TThreadModel)?.id) {
|
||||
const name = makeThreadName(thread as TThreadModel);
|
||||
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 (
|
||||
<View style={styles.container}>
|
||||
|
|
|
@ -43,7 +43,7 @@ interface IShareViewState {
|
|||
attachments: IShareAttachment[];
|
||||
text: string;
|
||||
room: TSubscriptionModel;
|
||||
thread: TThreadModel;
|
||||
thread: TThreadModel | string;
|
||||
maxFileSize?: number;
|
||||
mediaAllowList?: string;
|
||||
selectedMessages: string[];
|
||||
|
@ -88,7 +88,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
|||
attachments: [],
|
||||
text: props.route.params?.text ?? '',
|
||||
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,
|
||||
mediaAllowList: this.isShareExtension
|
||||
? this.serverInfo?.FileUpload_MediaTypeWhiteList
|
||||
|
@ -265,7 +265,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
|||
store: 'Uploads',
|
||||
msg
|
||||
},
|
||||
thread?.id,
|
||||
(thread as TThreadModel)?.id || (thread as string),
|
||||
server,
|
||||
{ id: user.id, token: user.token }
|
||||
);
|
||||
|
@ -276,7 +276,10 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
|||
|
||||
// Send text message
|
||||
} 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 {
|
||||
if (!this.isShareExtension) {
|
||||
|
@ -344,7 +347,7 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
|
|||
value={{
|
||||
rid: room.rid,
|
||||
t: room.t,
|
||||
tmid: thread.id,
|
||||
tmid: (thread as TThreadModel)?.id || (thread as string),
|
||||
sharing: true,
|
||||
action: route.params?.action,
|
||||
selectedMessages,
|
||||
|
|
Loading…
Reference in New Issue