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