Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolmello committed Feb 26, 2021
1 parent 630f079 commit 623fd44
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions app/lib/methods/helpers/mergeSubscriptionsRooms.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 623fd44

Please sign in to comment.