From dc59dfca52e1b626a1226297ec65b88a438c734f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 24 Nov 2018 12:42:55 -0500 Subject: [PATCH] fix user ordering --- app/components/ChatRoom.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/components/ChatRoom.js b/app/components/ChatRoom.js index 38774d6..9e8301d 100644 --- a/app/components/ChatRoom.js +++ b/app/components/ChatRoom.js @@ -111,15 +111,16 @@ class ChatRoom extends Component { this.sendMessage = sendMessage; this.ipfs = ipfs; + // TODO: terrible, later to be moved to another layer of the stack const sortedUsers = Object.keys(channelUsers).sort((x,y) => { let currentTime = (new Date().getTime()); let x_is_online = ((currentTime - allUsers[x].lastSeen) > 10*1000) ? 1 : -1; let y_is_online = ((currentTime - allUsers[y].lastSeen) > 10*1000) ? 1 : -1; - let diff = x_is_online - y_is_online; - if (diff != 0) { return diff } - if (x.username < y.username) { return -1 } - if (x.username > y.username) { return 1 } + if (x_is_online > y_is_online) { return 1 } + if (x_is_online < y_is_online) { return -1 } + if (allUsers[x].username < allUsers[y].username) { return -1 } + if (allUsers[x].username > allUsers[y].username) { return 1 } return 0; })