From 99a32479f4b1cf42c3272b5f5931d99717c55a8f Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Fri, 26 Feb 2021 14:31:35 -0400 Subject: [PATCH] [FIX] Support chats order for older versions of the server (#2934) * Update mergeSubscriptionsRooms.js * Update mergeSubscriptionsRooms.js * Update mergeSubscriptionsRooms.js * Minor refactor Co-authored-by: Diego Mello --- .../methods/helpers/mergeSubscriptionsRooms.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.js b/app/lib/methods/helpers/mergeSubscriptionsRooms.js index 1bc3f18b2..1e5afa3b2 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.js +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.js @@ -1,11 +1,14 @@ import EJSON from 'ejson'; +import { lt, coerce } from 'semver'; import normalizeMessage from './normalizeMessage'; import findSubscriptionsRooms from './findSubscriptionsRooms'; import { Encryption } from '../../encryption'; +import reduxStore from '../../createStore'; // TODO: delete and update export const merge = (subscription, room) => { + const serverVersion = reduxStore.getState().server.version; subscription = EJSON.fromJSONValue(subscription); room = EJSON.fromJSONValue(room); @@ -25,9 +28,15 @@ export const merge = (subscription, room) => { subscription.usernames = room.usernames; subscription.uids = room.uids; } - // https://github.com/RocketChat/Rocket.Chat/blob/develop/app/ui-sidenav/client/roomList.js#L180 - const lastRoomUpdate = room.lm || subscription.ts || subscription._updatedAt; - subscription.roomUpdatedAt = subscription.lr ? Math.max(new Date(subscription.lr), new Date(lastRoomUpdate)) : lastRoomUpdate; + if (serverVersion && lt(coerce(serverVersion), '3.7.0')) { + const updatedAt = room?._updatedAt ? new Date(room._updatedAt) : null; + const lastMessageTs = subscription?.lastMessage?.ts ? new Date(subscription.lastMessage.ts) : null; + subscription.roomUpdatedAt = Math.max(updatedAt, lastMessageTs); + } else { + // https://github.com/RocketChat/Rocket.Chat/blob/develop/app/ui-sidenav/client/roomList.js#L180 + const lastRoomUpdate = room.lm || subscription.ts || subscription._updatedAt; + subscription.roomUpdatedAt = subscription.lr ? Math.max(new Date(subscription.lr), new Date(lastRoomUpdate)) : lastRoomUpdate; + } subscription.ro = room.ro; subscription.broadcast = room.broadcast; subscription.encrypted = room.encrypted;