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 sorting was being wrong in some cases where the rooms records were returned before the subscriptions #11273

Merged
merged 4 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/client/lib/cachedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CachedCollection {
listenChangesForLoggedUsersOnly = false,
useSync = true,
useCache = true,
version = 7,
version = 8,
maxCacheTime = 60*60*24*30,
onSyncData = (/* action, record */) => {}
}) {
Expand Down
39 changes: 24 additions & 15 deletions packages/rocketchat-ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,35 @@ const getLowerCaseNames = (room, nameDefault = '') => {
};
};

// RocketChat.Notifications['onUser']('rooms-changed', );

const mergeSubRoom = (record/*, t*/) => {
const room = Tracker.nonreactive(() => RocketChat.models.Rooms.findOne({ _id: record.rid }));
if (!room) {
return record;
}
record.lastMessage = room.lastMessage;
record.lm = room._updatedAt;
return _.extend(record, getLowerCaseNames(record));
const mergeSubRoom = subscription => {
const room = RocketChat.models.Rooms.findOne(subscription.rid) || { _updatedAt: subscription.ts };
subscription.lastMessage = room.lastMessage;
subscription.lm = room._updatedAt;
return Object.assign(subscription, getLowerCaseNames(subscription));
};

RocketChat.callbacks.add('cachedCollection-received-rooms', (room) => {
const mergeRoomSub = room => {
const sub = RocketChat.models.Subscriptions.findOne({ rid: room._id });
if (!sub) {
return;
return room;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually there are no difference (callbacks use the last value returned !== undefined, just to avoid some misunderstanding.

}
const $set = {lastMessage : room.lastMessage, lm: room._updatedAt, ...getLowerCaseNames(room, sub.name)};
RocketChat.models.Subscriptions.update({ rid: room._id }, {$set});
});

RocketChat.models.Subscriptions.update({
rid: room._id
}, {
$set: {
lastMessage: room.lastMessage,
lm: room._updatedAt,
...getLowerCaseNames(room, sub.name)
}
});

return room;
};

RocketChat.callbacks.add('cachedCollection-received-rooms', mergeRoomSub);
RocketChat.callbacks.add('cachedCollection-sync-rooms', mergeRoomSub);
RocketChat.callbacks.add('cachedCollection-loadFromServer-rooms', mergeRoomSub);

RocketChat.callbacks.add('cachedCollection-received-subscriptions', mergeSubRoom);
RocketChat.callbacks.add('cachedCollection-sync-subscriptions', mergeSubRoom);
Expand Down