From 460f68caef1486afdfc3d6c41362462025336aaf Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 22 Dec 2015 15:38:23 +0000 Subject: [PATCH] Move RoomMember[] -> MemberEntry[] conversion somewhere sensible This is required for automatically entering tab-complete mode because onKeyDown is NOT called in that case, so we need to make sure to have a membership list hanging around. --- src/TabCompleteEntries.js | 29 ++++++++++++++++ src/components/structures/RoomView.js | 18 ++++++++++ src/components/views/rooms/MessageComposer.js | 34 ------------------- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/TabCompleteEntries.js b/src/TabCompleteEntries.js index 81a51c10bd..6d1a51c9b2 100644 --- a/src/TabCompleteEntries.js +++ b/src/TabCompleteEntries.js @@ -68,5 +68,34 @@ class MemberEntry extends Entry { } } +MemberEntry.fromMemberList = function(members) { + return members.sort(function(a, b) { + var userA = a.user; + var userB = b.user; + if (userA && !userB) { + return -1; // a comes first + } + else if (!userA && userB) { + return 1; // b comes first + } + else if (!userA && !userB) { + return 0; // don't care + } + else { // both User objects exist + if (userA.lastActiveAgo < userB.lastActiveAgo) { + return -1; // a comes first + } + else if (userA.lastActiveAgo > userB.lastActiveAgo) { + return 1; // b comes first + } + else { + return 0; // same last active ago + } + } + }).map(function(m) { + return new MemberEntry(m); + }); +} + module.exports.Entry = Entry; module.exports.MemberEntry = MemberEntry; diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 2e649b71c0..20f724c609 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -35,6 +35,7 @@ var Modal = require("../../Modal"); var sdk = require('../../index'); var CallHandler = require('../../CallHandler'); var TabComplete = require("../../TabComplete"); +var MemberEntry = require("../../TabCompleteEntries").MemberEntry; var Resend = require("../../Resend"); var dis = require("../../dispatcher"); @@ -264,6 +265,11 @@ module.exports = React.createClass({ }, onRoomStateMember: function(ev, state, member) { + if (member.roomId === this.props.roomId) { + // a member state changed in this room, refresh the tab complete list + this._updateTabCompleteList(this.state.room); + } + if (!this.props.ConferenceHandler) { return; } @@ -326,6 +332,18 @@ module.exports = React.createClass({ window.addEventListener('resize', this.onResize); this.onResize(); + + this._updateTabCompleteList(this.state.room); + }, + + _updateTabCompleteList: function(room) { + if (!room || !this.tabComplete) { + return; + } + console.log("_updateTabCompleteList"); + this.tabComplete.setCompletionList( + MemberEntry.fromMemberList(room.getJoinedMembers()) + ); }, _initialiseMessagePanel: function() { diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index acfdd55694..5ac4a24908 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -200,40 +200,6 @@ module.exports = React.createClass({ this.sentHistory.push(input); this.onEnter(ev); } - else if (ev.keyCode === KeyCode.TAB) { - if (this.props.tabComplete && this.props.room) { - var memberList = []; - // TODO: We should cache this list and only update it when the - // member list changes. It's also horrendous that this is done here. - memberList = this.props.room.getJoinedMembers().sort(function(a, b) { - var userA = a.user; - var userB = b.user; - if (userA && !userB) { - return -1; // a comes first - } - else if (!userA && userB) { - return 1; // b comes first - } - else if (!userA && !userB) { - return 0; // don't care - } - else { // both User objects exist - if (userA.lastActiveAgo < userB.lastActiveAgo) { - return -1; // a comes first - } - else if (userA.lastActiveAgo > userB.lastActiveAgo) { - return 1; // b comes first - } - else { - return 0; // same last active ago - } - } - }).map(function(m) { - return new MemberEntry(m); - }); - this.props.tabComplete.setCompletionList(memberList); - } - } else if (ev.keyCode === KeyCode.UP) { var input = this.refs.textarea.value; var offset = this.refs.textarea.selectionStart || 0;