From a9885ac2832d84a23e57b3b9fc454eae3ae0a92c Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 22 Feb 2021 16:25:21 -0400 Subject: [PATCH 1/4] Update mergeSubscriptionsRooms.js --- .../methods/helpers/mergeSubscriptionsRooms.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.js b/app/lib/methods/helpers/mergeSubscriptionsRooms.js index 1bc3f18b25..0927b891af 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.js +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.js @@ -1,11 +1,14 @@ import EJSON from 'ejson'; +import { gte, 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); @@ -15,6 +18,11 @@ export const merge = (subscription, room) => { if (room) { if (room._updatedAt) { subscription.lastMessage = normalizeMessage(room.lastMessage); + if (serverVersion && lt(coerce(serverVersion), '3.11.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); + } subscription.description = room.description; subscription.topic = room.topic; subscription.announcement = room.announcement; @@ -25,9 +33,11 @@ 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 && gte(coerce(serverVersion), '3.11.0')) { + // 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; From 2ce7a30c17b19ad78b23b6f89dc58cfddd88393b Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 22 Feb 2021 16:31:15 -0400 Subject: [PATCH 2/4] Update mergeSubscriptionsRooms.js --- app/lib/methods/helpers/mergeSubscriptionsRooms.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.js b/app/lib/methods/helpers/mergeSubscriptionsRooms.js index 0927b891af..6dc62fafb2 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.js +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.js @@ -18,7 +18,7 @@ export const merge = (subscription, room) => { if (room) { if (room._updatedAt) { subscription.lastMessage = normalizeMessage(room.lastMessage); - if (serverVersion && lt(coerce(serverVersion), '3.11.0')) { + if (serverVersion && lt(coerce(serverVersion), '3.10.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); @@ -33,7 +33,7 @@ export const merge = (subscription, room) => { subscription.usernames = room.usernames; subscription.uids = room.uids; } - if (serverVersion && gte(coerce(serverVersion), '3.11.0')) { + if (serverVersion && gte(coerce(serverVersion), '3.10.0')) { // 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; From 630f0799650fad8df136050206fef7140a01a878 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Fri, 26 Feb 2021 13:47:56 -0400 Subject: [PATCH 3/4] Update mergeSubscriptionsRooms.js --- app/lib/methods/helpers/mergeSubscriptionsRooms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.js b/app/lib/methods/helpers/mergeSubscriptionsRooms.js index 6dc62fafb2..7fddb2910a 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.js +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.js @@ -1,5 +1,5 @@ import EJSON from 'ejson'; -import { gte, lt, coerce } from 'semver'; +import { gt, lte, coerce } from 'semver'; import normalizeMessage from './normalizeMessage'; import findSubscriptionsRooms from './findSubscriptionsRooms'; @@ -18,7 +18,7 @@ export const merge = (subscription, room) => { if (room) { if (room._updatedAt) { subscription.lastMessage = normalizeMessage(room.lastMessage); - if (serverVersion && lt(coerce(serverVersion), '3.10.0')) { + if (serverVersion && lte(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); @@ -33,7 +33,7 @@ export const merge = (subscription, room) => { subscription.usernames = room.usernames; subscription.uids = room.uids; } - if (serverVersion && gte(coerce(serverVersion), '3.10.0')) { + if (serverVersion && gt(coerce(serverVersion), '3.7.0')) { // 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; From 623fd441a269e84a0f8b98a59de2b796bc17e4ea Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 26 Feb 2021 15:23:01 -0300 Subject: [PATCH 4/4] Minor refactor --- app/lib/methods/helpers/mergeSubscriptionsRooms.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/lib/methods/helpers/mergeSubscriptionsRooms.js b/app/lib/methods/helpers/mergeSubscriptionsRooms.js index 7fddb2910a..1e5afa3b21 100644 --- a/app/lib/methods/helpers/mergeSubscriptionsRooms.js +++ b/app/lib/methods/helpers/mergeSubscriptionsRooms.js @@ -1,5 +1,5 @@ import EJSON from 'ejson'; -import { gt, lte, coerce } from 'semver'; +import { lt, coerce } from 'semver'; import normalizeMessage from './normalizeMessage'; import findSubscriptionsRooms from './findSubscriptionsRooms'; @@ -18,11 +18,6 @@ export const merge = (subscription, room) => { if (room) { if (room._updatedAt) { subscription.lastMessage = normalizeMessage(room.lastMessage); - if (serverVersion && lte(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); - } subscription.description = room.description; subscription.topic = room.topic; subscription.announcement = room.announcement; @@ -33,7 +28,11 @@ export const merge = (subscription, room) => { subscription.usernames = room.usernames; subscription.uids = room.uids; } - if (serverVersion && gt(coerce(serverVersion), '3.7.0')) { + 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;