From 00e20d20885afb51c98797281f566abc7b98fca2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Aug 2020 14:11:26 +0200 Subject: [PATCH] take null timestamps into account --- src/domain/session/roomlist/RoomTileViewModel.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/domain/session/roomlist/RoomTileViewModel.js b/src/domain/session/roomlist/RoomTileViewModel.js index 13a01309..03a9f0a3 100644 --- a/src/domain/session/roomlist/RoomTileViewModel.js +++ b/src/domain/session/roomlist/RoomTileViewModel.js @@ -62,8 +62,16 @@ export class RoomTileViewModel extends ViewModel { } return 1; } - - const timeDiff = theirRoom.lastMessageTimestamp - myRoom.lastMessageTimestamp; + const myTimestamp = myRoom.lastMessageTimestamp; + const theirTimestamp = theirRoom.lastMessageTimestamp; + // rooms with a timestamp come before rooms without one + if ((myTimestamp === null) !== (theirTimestamp === null)) { + if (theirTimestamp === null) { + return -1; + } + return 1; + } + const timeDiff = theirTimestamp - myTimestamp; if (timeDiff === 0) { // sort alphabetically const nameCmp = this._room.name.localeCompare(other._room.name);