From 5c92e7bf2ed215a28c83ead9e6468a4febba1db3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 23 Nov 2018 18:49:35 -0500 Subject: [PATCH] fix online/offline display; sort users by online state + username --- app/components/ChatRoom.js | 31 +++++++++++++++++++++---------- app/components/Home.js | 2 -- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/components/ChatRoom.js b/app/components/ChatRoom.js index af11e79..f9a0adf 100644 --- a/app/components/ChatRoom.js +++ b/app/components/ChatRoom.js @@ -21,8 +21,6 @@ import { uploadFileAndSend } from '../utils/ipfs'; import 'emoji-mart/css/emoji-mart.css'; - - class WhoIsTyping extends PureComponent { whoIsTyping() { @@ -96,6 +94,19 @@ class ChatRoom extends Component { render() { const { messages, sendMessage, currentChannel, usersTyping, typingEvent, channelUsers, allUsers, ipfs } = this.props; + + 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 } + return 0; + }) + const {showEmojis} = this.state; return ( @@ -184,15 +195,15 @@ class ChatRoom extends Component { - {Object.keys(channelUsers).map(user => ( + {sortedUsers.map(user => ( - + 10*1000 ? 'lightgrey' : 'lightgreen'), + 'border-radius': '50%', + 'margin-right': '10px' + }}/> diff --git a/app/components/Home.js b/app/components/Home.js index bc41182..4b2eb14 100644 --- a/app/components/Home.js +++ b/app/components/Home.js @@ -14,8 +14,6 @@ import { getKeyData, createVault, restoreVault, wipeVault } from '../utils/keyMa import { FullScreenLoader } from './Loaders'; import { openBrowserWindow, addWindowEventListeners } from '../utils/windows'; - - const typingNotificationsTimestamp = {}; const DEFAULT_CHANNEL = "mytest";