Skip to content

Commit

Permalink
[IMPROVE] Add support for ephemeral messages inside threads (#3687)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello authored Feb 15, 2022
1 parent 765c5c5 commit c7f4e55
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c7f4e55

Please sign in to comment.