From c7f4e5531c3ae8e1c2e4b95f535ce32aab4a0774 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 15 Feb 2022 15:46:17 -0300 Subject: [PATCH] [IMPROVE] Add support for ephemeral messages inside threads (#3687) --- app/lib/methods/subscriptions/rooms.js | 38 +++++++++----------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/app/lib/methods/subscriptions/rooms.js b/app/lib/methods/subscriptions/rooms.js index ee986908a..9e1cf8519 100644 --- a/app/lib/methods/subscriptions/rooms.js +++ b/app/lib/methods/subscriptions/rooms.js @@ -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); }