From e89484dddb9e0942fc43d55392b272f130109762 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 8 May 2020 14:36:55 -0300 Subject: [PATCH] [FIX] Delete Subs (#2091) Co-authored-by: Diego Mello --- app/sagas/rooms.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/sagas/rooms.js b/app/sagas/rooms.js index 24506d88..7204a33a 100644 --- a/app/sagas/rooms.js +++ b/app/sagas/rooms.js @@ -46,12 +46,12 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { const subCollection = db.collections.get('subscriptions'); const messagesCollection = db.collections.get('messages'); - if (subscriptions.length) { - const subsIds = subscriptions.map(sub => sub.rid); + const subsIds = subscriptions.map(sub => sub.rid).concat(roomsResult.remove.map(room => room._id)); + if (subsIds.length) { const existingSubs = yield subCollection.query(Q.where('id', Q.oneOf(subsIds))).fetch(); const subsToUpdate = existingSubs.filter(i1 => subscriptions.find(i2 => i1._id === i2._id)); const subsToCreate = subscriptions.filter(i1 => !existingSubs.find(i2 => i1._id === i2._id)); - // TODO: subsToDelete? + const subsToDelete = existingSubs.filter(i1 => !subscriptions.find(i2 => i1._id === i2._id)); const lastMessages = subscriptions .map(sub => sub.lastMessage && buildMessage(sub.lastMessage)) @@ -77,6 +77,7 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { Object.assign(subscription, newSub); }); }), + ...subsToDelete.map(subscription => subscription.prepareDestroyPermanently()), ...messagesToCreate.map(message => messagesCollection.prepareCreate(protectedFunction((m) => { m._raw = sanitizedRaw({ id: message._id }, messagesCollection.schema); m.subscription.id = message.rid;