Skip to content

Commit

Permalink
fix undefined lm on subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Jun 27, 2018
1 parent 2b6e32c commit 7923bd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/client/lib/cachedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CachedCollectionManager {

RocketChat.CachedCollectionManager = new CachedCollectionManager;

const debug = false;
const debug = true;

const nullLog = function() {};

Expand All @@ -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
26 changes: 13 additions & 13 deletions packages/rocketchat-ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7923bd0

Please sign in to comment.