[FIX] Fix synchronization of removed subscriptions (#3768)

When a subscription is removed from the server via another client, when the
mobile app is relaunched the subscriptions were not being removed properly.
Changed the logic to use the subscriptionResult.remove array from the server
and the _id property to fix.

Co-authored-by: Christian King <cking@vonix.io>
This commit is contained in:
Diego Mello 2022-03-11 11:19:23 -03:00 committed by GitHub
parent 65c9aec2b4
commit 58c9e98e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -51,9 +51,9 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
const subCollection = db.get('subscriptions');
const messagesCollection = db.get('messages');
const subsIds = subscriptions.map(sub => sub.rid).concat(roomsResult.remove.map(room => room._id));
const subsIds = subscriptions.map(sub => sub._id).concat(subscriptionsResult.remove.map(sub => sub._id));
if (subsIds.length) {
const existingSubs = yield subCollection.query(Q.where('id', Q.oneOf(subsIds))).fetch();
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));
const subsToDelete = existingSubs.filter(i1 => !subscriptions.find(i2 => i1._id === i2._id));