Fix edit, delete, resend and delete after error state
This commit is contained in:
parent
aaef77a58f
commit
21dbc7e112
|
@ -347,7 +347,7 @@ const MessageActions = React.memo(
|
|||
onPress: async () => {
|
||||
try {
|
||||
logEvent(events.ROOM_MSG_ACTION_DELETE);
|
||||
await Services.deleteMessage(message.id, message.subscription ? message.subscription.id : '');
|
||||
await Services.deleteMessage(message.id, message.rid);
|
||||
} catch (e) {
|
||||
logEvent(events.ROOM_MSG_ACTION_DELETE_F);
|
||||
log(e);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { forwardRef, useImperativeHandle } from 'react';
|
||||
import Model from '@nozbe/watermelondb/Model';
|
||||
|
||||
import { getMessageById } from '../lib/database/services/Message';
|
||||
import { getThreadMessageById } from '../lib/database/services/ThreadMessage';
|
||||
import database from '../lib/database';
|
||||
import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
||||
import { useActionSheet } from './ActionSheet';
|
||||
|
@ -27,16 +29,16 @@ const MessageErrorActions = forwardRef<IMessageErrorActions, { tmid?: string }>(
|
|||
const msgCollection = db.get('messages');
|
||||
const threadCollection = db.get('threads');
|
||||
|
||||
// Delete the object (it can be Message or ThreadMessage instance)
|
||||
deleteBatch.push(message.prepareDestroyPermanently());
|
||||
const msg = await getMessageById(message.id);
|
||||
if (msg) {
|
||||
deleteBatch.push(msg.prepareDestroyPermanently());
|
||||
}
|
||||
|
||||
// If it's a thread, we find and delete the whole tree, if necessary
|
||||
if (tmid) {
|
||||
try {
|
||||
const msg = await msgCollection.find(message.id);
|
||||
const msg = await getThreadMessageById(message.id);
|
||||
if (msg) {
|
||||
deleteBatch.push(msg.prepareDestroyPermanently());
|
||||
} catch {
|
||||
// Do nothing: message not found
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||
import { Model } from '@nozbe/watermelondb';
|
||||
|
||||
import { getMessageById } from '../database/services/Message';
|
||||
import database from '../database';
|
||||
import log from './helpers/log';
|
||||
import { random } from './helpers';
|
||||
|
@ -66,14 +67,17 @@ async function sendMessageCall(message: any) {
|
|||
export async function resendMessage(message: TMessageModel, tmid?: string) {
|
||||
const db = database.active;
|
||||
try {
|
||||
await db.write(async () => {
|
||||
await message.update(m => {
|
||||
m.status = messagesStatus.TEMP;
|
||||
const messageRecord = await getMessageById(message.id);
|
||||
if (messageRecord) {
|
||||
await db.write(async () => {
|
||||
await messageRecord.update(m => {
|
||||
m.status = messagesStatus.TEMP;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
const m = await Encryption.encryptMessage({
|
||||
_id: message.id,
|
||||
rid: message.subscription ? message.subscription.id : '',
|
||||
rid: message.rid,
|
||||
msg: message.msg,
|
||||
...(tmid && { tmid })
|
||||
} as IMessage);
|
||||
|
|
|
@ -795,8 +795,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
const newMessage = {
|
||||
id: message.id,
|
||||
subscription: {
|
||||
// @ts-ignore TODO: we can remove this after we merge a PR separating IMessage vs IMessageFromServer
|
||||
id: message.subscription.id
|
||||
id: message.rid
|
||||
},
|
||||
msg: message?.attachments?.[0]?.description || message.msg
|
||||
} as TMessageModel;
|
||||
|
|
Loading…
Reference in New Issue