Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Sidebar Room List not working properly. #26950

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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