Skip to content

Commit

Permalink
Regression: Sidebar Room List not working properly. (#26950)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh authored Sep 27, 2022
1 parent 6287004 commit 74cd22b
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ export class CachedCollection extends Emitter {
const data = await call(this.methodName);
this.log(`${data.length} records loaded from server`);
data.forEach((record) => {
callbacks.run(`cachedCollection-loadFromServer-${this.name}`, record, 'changed');
this.collection.direct.upsert({ _id: record._id }, omit(record, '_id'));
const newRecord = callbacks.run(`cachedCollection-loadFromServer-${this.name}`, record, 'changed');
this.collection.direct.upsert({ _id: newRecord._id }, omit(newRecord, '_id'));

this.onSyncData('changed', record);
this.onSyncData('changed', newRecord);

if (record._updatedAt && record._updatedAt > this.updatedAt) {
this.updatedAt = record._updatedAt;
if (newRecord._updatedAt && newRecord._updatedAt > this.updatedAt) {
this.updatedAt = newRecord._updatedAt;
}
});
this.updatedAt = this.updatedAt === lastTime ? startTime : this.updatedAt;
Expand Down Expand Up @@ -278,22 +278,22 @@ export class CachedCollection extends Emitter {
const { ChatRoom, CachedChatRoom } = await import('../../../models');
Notifications[eventType || this.eventType](eventName || this.eventName, (t, record) => {
this.log('record received', t, record);
callbacks.run(`cachedCollection-received-${this.name}`, record, t);
const newRecord = callbacks.run(`cachedCollection-received-${this.name}`, record, t);
if (t === 'removed') {
let room;
if (this.eventName === 'subscriptions-changed') {
room = ChatRoom.findOne(record.rid);
room = ChatRoom.findOne(newRecord.rid);
if (room) {
this.removeRoomFromCacheWhenUserLeaves(room._id, ChatRoom, CachedChatRoom);
}
} else {
room = this.collection.findOne({
_id: record._id,
_id: newRecord._id,
});
}
this.collection.remove(record._id);
this.collection.remove(newRecord._id);
} else {
const { _id, ...recordData } = record;
const { _id, ...recordData } = newRecord;
this.collection.direct.upsert({ _id }, recordData);
}
this.save();
Expand Down Expand Up @@ -351,18 +351,18 @@ export class CachedCollection extends Emitter {

for (const record of changes) {
const action = record._deletedAt ? 'removed' : 'changed';
callbacks.run(`cachedCollection-sync-${this.name}`, record, action);
const actionTime = record._deletedAt || record._updatedAt;
const { _id, ...recordData } = record;
if (record._deletedAt) {
const newRecord = callbacks.run(`cachedCollection-sync-${this.name}`, record, action);
const actionTime = newRecord._deletedAt || newRecord._updatedAt;
const { _id, ...recordData } = newRecord;
if (newRecord._deletedAt) {
this.collection.direct.remove({ _id });
} else {
this.collection.direct.upsert({ _id }, recordData);
}
if (actionTime > this.updatedAt) {
this.updatedAt = actionTime;
}
this.onSyncData(action, record);
this.onSyncData(action, newRecord);
}
this.updatedAt = this.updatedAt === lastTime ? startTime : this.updatedAt;

Expand Down

0 comments on commit 74cd22b

Please sign in to comment.