[IMPROVE] Add support for ephemeral messages inside threads (#3687)

This commit is contained in:
Diego Mello 2022-02-15 15:46:17 -03:00 committed by GitHub
parent 765c5c50f8
commit c7f4e5531c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 25 deletions

View File

@ -1,5 +1,6 @@
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import { InteractionManager } from 'react-native';
import EJSON from 'ejson';
import database from '../../database';
import { merge } from '../helpers/mergeSubscriptionsRooms';
@ -17,6 +18,7 @@ import { setUser } from '../../../actions/login';
import { INAPP_NOTIFICATION_EMITTER } from '../../../containers/InAppNotification';
import { Encryption } from '../../encryption';
import { E2E_MESSAGE_TYPE } from '../../encryption/constants';
import updateMessages from '../updateMessages';
const removeListener = listener => listener.stop();
@ -309,32 +311,18 @@ export default function subscribeRooms() {
}
}
if (/message/.test(ev)) {
const [args] = ddpMessage.fields.args;
const _id = random(17);
const message = {
_id,
rid: args.rid,
msg: args.msg,
blocks: args.blocks,
ts: new Date(),
_updatedAt: new Date(),
status: messagesStatus.SENT,
u: {
_id,
username: 'rocket.cat'
}
};
try {
const msgCollection = db.get('messages');
await db.action(async () => {
await msgCollection.create(
protectedFunction(m => {
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
m.subscription.id = args.rid;
Object.assign(m, message);
})
);
});
const [args] = ddpMessage.fields.args;
const _id = random(17);
const message = {
u: {
_id,
username: 'rocket.cat',
name: 'Rocket Cat'
},
...buildMessage(EJSON.fromJSONValue(args))
};
await updateMessages({ rid: args.rid, update: [message] });
} catch (e) {
log(e);
}