[FIX] Delete Subs (#2091)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-05-08 14:36:55 -03:00 committed by GitHub
parent 9e89316e2a
commit e89484dddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -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;