[FIX] Quote message and reply with image (#4715)

* send msg with attachment

* send quote inside image

* minor tweak

* remove msg from return

* fix the lint and prettier

* fix visual bug for iOS

* fixing the message box input
This commit is contained in:
Reinaldo Neto 2023-01-05 15:23:11 -03:00 committed by GitHub
parent b6b5e7294f
commit 8102bef1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 31 deletions

View File

@ -302,7 +302,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
if (usedCannedResponse !== nextProps.usedCannedResponse) { if (usedCannedResponse !== nextProps.usedCannedResponse) {
this.onChangeText(nextProps.usedCannedResponse ?? ''); this.onChangeText(nextProps.usedCannedResponse ?? '');
} }
if (sharing) { if (sharing && !replying) {
this.setInput(nextProps.message.msg ?? ''); this.setInput(nextProps.message.msg ?? '');
return; return;
} }
@ -857,14 +857,21 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
}; };
openShareView = (attachments: any) => { openShareView = (attachments: any) => {
const { message, replyCancel, replyWithMention } = this.props; const { message, replyCancel, replyWithMention, replying } = this.props;
// Start a thread with an attachment // Start a thread with an attachment
let value: TThreadModel | IMessage = this.thread; let value: TThreadModel | IMessage = this.thread;
if (replyWithMention) { if (replyWithMention) {
value = message; value = message;
replyCancel(); replyCancel();
} }
Navigation.navigate('ShareView', { room: this.room, thread: value, attachments }); Navigation.navigate('ShareView', {
room: this.room,
thread: value,
attachments,
replying,
replyingMessage: message,
closeReply: replyCancel
});
}; };
createDiscussion = () => { createDiscussion = () => {
@ -1042,16 +1049,7 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
// Legacy reply or quote (quote is a reply without mention) // Legacy reply or quote (quote is a reply without mention)
} else { } else {
const { user, roomType } = this.props; const msg = await this.formatReplyMessage(replyingMessage, message);
const permalink = await this.getPermalink(replyingMessage);
let msg = `[ ](${permalink}) `;
// if original message wasn't sent by current user and neither from a direct room
if (user.username !== replyingMessage?.u?.username && roomType !== 'd' && replyWithMention) {
msg += `@${replyingMessage?.u?.username} `;
}
msg = `${msg} ${message}`;
onSubmit(msg); onSubmit(msg);
} }
replyCancel(); replyCancel();
@ -1063,6 +1061,19 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
} }
}; };
formatReplyMessage = async (replyingMessage: IMessage, message = '') => {
const { user, roomType, replyWithMention } = this.props;
const permalink = await this.getPermalink(replyingMessage);
let msg = `[ ](${permalink}) `;
// if original message wasn't sent by current user and neither from a direct room
if (user.username !== replyingMessage?.u?.username && roomType !== 'd' && replyWithMention) {
msg += `@${replyingMessage?.u?.username} `;
}
return `${msg} ${message}`;
};
updateMentions = (keyword: any, type: string) => { updateMentions = (keyword: any, type: string) => {
if (type === MENTIONS_TRACKING_TYPE_USERS) { if (type === MENTIONS_TRACKING_TYPE_USERS) {
this.getUsers(keyword); this.getUsers(keyword);

View File

@ -8,7 +8,15 @@ import { TThreadMessageModel } from './IThreadMessage';
import { TThreadModel } from './IThread'; import { TThreadModel } from './IThread';
import { IUrl, IUrlFromServer } from './IUrl'; import { IUrl, IUrlFromServer } from './IUrl';
export type MessageType = 'jitsi_call_started' | 'discussion-created' | 'e2e' | 'load_more' | 'rm' | 'uj' | MessageTypeLoad | MessageTypesValues; export type MessageType =
| 'jitsi_call_started'
| 'discussion-created'
| 'e2e'
| 'load_more'
| 'rm'
| 'uj'
| MessageTypeLoad
| MessageTypesValues;
export interface IUserMessage { export interface IUserMessage {
_id: string; _id: string;

View File

@ -13,6 +13,7 @@ export interface IUpload {
progress?: number; progress?: number;
error?: boolean; error?: boolean;
subscription?: { id: string }; subscription?: { id: string };
msg?: string;
} }
export type TUploadModel = IUpload & Model; export type TUploadModel = IUpload & Model;

View File

@ -100,6 +100,13 @@ export function sendFileMessage(
}); });
} }
if (fileInfo.msg) {
formData.push({
name: 'msg',
data: fileInfo.msg
});
}
if (tmid) { if (tmid) {
formData.push({ formData.push({
name: 'tmid', name: 'tmid',

View File

@ -272,6 +272,9 @@ export type InsideStackParamList = {
text: string; text: string;
room: TSubscriptionModel; room: TSubscriptionModel;
thread: TThreadModel; thread: TThreadModel;
replying?: boolean;
replyingMessage?: IMessage;
closeReply?: Function;
}; };
ModalBlockView: { ModalBlockView: {
data: any; // TODO: Change; data: any; // TODO: Change;

View File

@ -174,18 +174,18 @@ interface IRoomViewState {
[key: string]: any; [key: string]: any;
joined: boolean; joined: boolean;
room: room:
| TSubscriptionModel | TSubscriptionModel
| { | {
rid: string; rid: string;
t: string; t: string;
name?: string; name?: string;
fname?: string; fname?: string;
prid?: string; prid?: string;
joinCodeRequired?: boolean; joinCodeRequired?: boolean;
status?: string; status?: string;
lastMessage?: ILastMessage; lastMessage?: ILastMessage;
sysMes?: boolean; sysMes?: boolean;
onHold?: boolean; onHold?: boolean;
}; };
roomUpdate: { roomUpdate: {
[K in TRoomUpdate]?: any; [K in TRoomUpdate]?: any;
@ -1502,7 +1502,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
return ( return (
<> <>
<MessageActions <MessageActions
ref={ref => (this.messageActions = ref)} ref={ref => this.messageActions = ref}
tmid={this.tmid} tmid={this.tmid}
room={room} room={room}
user={user} user={user}
@ -1512,7 +1512,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
onReactionPress={this.onReactionPress} onReactionPress={this.onReactionPress}
isReadOnly={readOnly} isReadOnly={readOnly}
/> />
<MessageErrorActions ref={ref => (this.messageErrorActions = ref)} tmid={this.tmid} /> <MessageErrorActions ref={ref => this.messageErrorActions = ref} tmid={this.tmid} />
</> </>
); );
}; };

View File

@ -22,7 +22,15 @@ import Thumbs from './Thumbs';
import Preview from './Preview'; import Preview from './Preview';
import Header from './Header'; import Header from './Header';
import styles from './styles'; import styles from './styles';
import { IApplicationState, IServer, IShareAttachment, IUser, TSubscriptionModel, TThreadModel } from '../../definitions'; import {
IApplicationState,
IMessage,
IServer,
IShareAttachment,
IUser,
TSubscriptionModel,
TThreadModel
} from '../../definitions';
import { sendFileMessage, sendMessage } from '../../lib/methods'; import { sendFileMessage, sendMessage } from '../../lib/methods';
import { hasPermission, isAndroid, canUploadFile, isReadOnly, isBlocked } from '../../lib/methods/helpers'; import { hasPermission, isAndroid, canUploadFile, isReadOnly, isBlocked } from '../../lib/methods/helpers';
@ -50,11 +58,14 @@ interface IShareViewProps {
server: string; server: string;
FileUpload_MediaTypeWhiteList?: string; FileUpload_MediaTypeWhiteList?: string;
FileUpload_MaxFileSize?: number; FileUpload_MaxFileSize?: number;
replying?: boolean;
replyingMessage?: IMessage;
} }
interface IMessageBoxShareView { interface IMessageBoxShareView {
text: string; text: string;
forceUpdate(): void; forceUpdate(): void;
formatReplyMessage: (replyingMessage: IMessage, message?: any) => Promise<string>;
} }
class ShareView extends Component<IShareViewProps, IShareViewState> { class ShareView extends Component<IShareViewProps, IShareViewState> {
@ -62,6 +73,9 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
private files: any[]; private files: any[];
private isShareExtension: boolean; private isShareExtension: boolean;
private serverInfo: IServer; private serverInfo: IServer;
private replying?: boolean;
private replyingMessage?: IMessage;
private closeReply?: Function;
constructor(props: IShareViewProps) { constructor(props: IShareViewProps) {
super(props); super(props);
@ -69,6 +83,9 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
this.files = props.route.params?.attachments ?? []; this.files = props.route.params?.attachments ?? [];
this.isShareExtension = props.route.params?.isShareExtension; this.isShareExtension = props.route.params?.isShareExtension;
this.serverInfo = props.route.params?.serverInfo ?? {}; this.serverInfo = props.route.params?.serverInfo ?? {};
this.replying = props.route.params?.replying;
this.replyingMessage = props.route.params?.replyingMessage;
this.closeReply = props.route.params?.closeReply;
this.state = { this.state = {
selected: {} as IShareAttachment, selected: {} as IShareAttachment,
@ -92,6 +109,12 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
componentWillUnmount = () => { componentWillUnmount = () => {
console.countReset(`${this.constructor.name}.render calls`); console.countReset(`${this.constructor.name}.render calls`);
// close reply from the RoomView
setTimeout(() => {
if (this.closeReply) {
this.closeReply();
}
}, 300);
}; };
setHeader = () => { setHeader = () => {
@ -214,6 +237,11 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
navigation.pop(); navigation.pop();
} }
let msg: string | undefined;
if (this.replying && this.replyingMessage) {
msg = await this.messagebox.current?.formatReplyMessage(this.replyingMessage);
}
try { try {
// Send attachment // Send attachment
if (attachments.length) { if (attachments.length) {
@ -228,7 +256,8 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
size, size,
type, type,
path, path,
store: 'Uploads' store: 'Uploads',
msg
}, },
thread?.id, thread?.id,
server, server,
@ -313,11 +342,12 @@ class ShareView extends Component<IShareViewProps, IShareViewState> {
roomType={room.t} roomType={room.t}
theme={theme} theme={theme}
onSubmit={this.send} onSubmit={this.send}
message={{ msg: selected?.description ?? '' }} message={this.replyingMessage}
navigation={navigation} navigation={navigation}
isFocused={navigation.isFocused} isFocused={navigation.isFocused}
iOSScrollBehavior={NativeModules.KeyboardTrackingViewManager?.KeyboardTrackingScrollBehaviorNone} iOSScrollBehavior={NativeModules.KeyboardTrackingViewManager?.KeyboardTrackingScrollBehaviorNone}
isActionsEnabled={false} isActionsEnabled={false}
replying={this.replying}
> >
<Thumbs <Thumbs
attachments={attachments} attachments={attachments}