Merge pull request #3 from status-im/fix_user_order

fix user ordering
This commit is contained in:
Iuri Matias 2018-11-25 13:16:08 -05:00 committed by GitHub
commit a55b607d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -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;
})