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