From 93f266a4faf89e9a2a56368f0efaece09462bcf1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 9 Oct 2015 17:26:28 +0100 Subject: [PATCH] Update to new memberlist api and hopefully sort out presence (list wasn't being re-sorted at the right time) Hopefully fix #11 --- .../vector/views/organisms/MemberList.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/skins/vector/views/organisms/MemberList.js b/src/skins/vector/views/organisms/MemberList.js index 06aa3ba6..08f4e45c 100644 --- a/src/skins/vector/views/organisms/MemberList.js +++ b/src/skins/vector/views/organisms/MemberList.js @@ -33,15 +33,38 @@ module.exports = React.createClass({ return { editing: false }; }, + memberSort: function(userIdA, userIdB) { + var userA = this.memberDict[userIdA].user; + var userB = this.memberDict[userIdB].user; + + var presenceMap = { + online: 3, + unavailable: 2, + offline: 1 + }; + + var presenceOrdA = userA ? presenceMap[userA.presence] : 0; + var presenceOrdB = userB ? presenceMap[userB.presence] : 0; + + if (presenceOrdA != presenceOrdB) { + return presenceOrdB - presenceOrdA; + } + + var latA = userA ? (userA.lastPresenceTs - (userA.lastActiveAgo || userA.lastPresenceTs)) : 0; + var latB = userB ? (userB.lastPresenceTs - (userB.lastActiveAgo || userB.lastPresenceTs)) : 0; + + return latB - latA; + }, + makeMemberTiles: function(membership) { var MemberTile = sdk.getComponent("molecules.MemberTile"); var self = this; - return Object.keys(self.state.memberDict).filter(function(userId) { - var m = self.state.memberDict[userId]; + return self.state.members.filter(function(userId) { + var m = self.memberDict[userId]; return m.membership == membership; }).map(function(userId) { - var m = self.state.memberDict[userId]; + var m = self.memberDict[userId]; return ( );