From 8bd5990edf0ec9b2b7034353c0b64e4cd2870a21 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 27 Jun 2018 14:46:43 -0300 Subject: [PATCH 1/4] fix sort sidebar --- .../client/lib/cachedCollection.js | 2 +- .../rocketchat-ui-sidenav/client/roomList.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/rocketchat-lib/client/lib/cachedCollection.js b/packages/rocketchat-lib/client/lib/cachedCollection.js index d1f6b3484f96..c6438caca19d 100644 --- a/packages/rocketchat-lib/client/lib/cachedCollection.js +++ b/packages/rocketchat-lib/client/lib/cachedCollection.js @@ -110,7 +110,7 @@ class CachedCollection { listenChangesForLoggedUsersOnly = false, useSync = true, useCache = true, - version = 7, + version = 8, maxCacheTime = 60*60*24*30, onSyncData = (/* action, record */) => {} }) { diff --git a/packages/rocketchat-ui-sidenav/client/roomList.js b/packages/rocketchat-ui-sidenav/client/roomList.js index fcb0116a6b77..8951f12a299a 100644 --- a/packages/rocketchat-ui-sidenav/client/roomList.js +++ b/packages/rocketchat-ui-sidenav/client/roomList.js @@ -110,26 +110,26 @@ 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; } const $set = {lastMessage : room.lastMessage, lm: room._updatedAt, ...getLowerCaseNames(room, sub.name)}; RocketChat.models.Subscriptions.update({ rid: room._id }, {$set}); -}); + 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); From dbce005215a20b2d3e01a8f18de4a0850c05991a Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 27 Jun 2018 17:44:29 -0300 Subject: [PATCH 2/4] fix review --- packages/rocketchat-ui-sidenav/client/roomList.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-ui-sidenav/client/roomList.js b/packages/rocketchat-ui-sidenav/client/roomList.js index 8951f12a299a..2970d7aa7a0b 100644 --- a/packages/rocketchat-ui-sidenav/client/roomList.js +++ b/packages/rocketchat-ui-sidenav/client/roomList.js @@ -122,8 +122,17 @@ const mergeRoomSub = room => { if (!sub) { return room; } - 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; }; From 4f88dd6cd85dffb25ebab3a46e0eac8113694bdd Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 27 Jun 2018 19:50:59 -0300 Subject: [PATCH 3/4] Update roomList.js --- packages/rocketchat-ui-sidenav/client/roomList.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/rocketchat-ui-sidenav/client/roomList.js b/packages/rocketchat-ui-sidenav/client/roomList.js index 2970d7aa7a0b..8088f8d67376 100644 --- a/packages/rocketchat-ui-sidenav/client/roomList.js +++ b/packages/rocketchat-ui-sidenav/client/roomList.js @@ -1,6 +1,5 @@ /* globals RocketChat */ import { UiTextContext } from 'meteor/rocketchat:lib'; -import _ from 'underscore'; Template.roomList.helpers({ rooms() { From 273a3f8086f3f434ffa7541fd1da8f8170fa8d19 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Wed, 27 Jun 2018 19:51:22 -0300 Subject: [PATCH 4/4] Update cachedCollection.js --- packages/rocketchat-lib/client/lib/cachedCollection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-lib/client/lib/cachedCollection.js b/packages/rocketchat-lib/client/lib/cachedCollection.js index c6438caca19d..d1f6b3484f96 100644 --- a/packages/rocketchat-lib/client/lib/cachedCollection.js +++ b/packages/rocketchat-lib/client/lib/cachedCollection.js @@ -110,7 +110,7 @@ class CachedCollection { listenChangesForLoggedUsersOnly = false, useSync = true, useCache = true, - version = 8, + version = 7, maxCacheTime = 60*60*24*30, onSyncData = (/* action, record */) => {} }) {