From c9e1c6872653372abe5ffa7cc3eb279b8b0cc81a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 25 Jul 2019 21:45:32 +0100 Subject: [PATCH 1/3] Handle onPaste AddressPickerDialog, allow addressing CSV/NL/Space delim list Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/dialogs/AddressPickerDialog.js | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/src/components/views/dialogs/AddressPickerDialog.js b/src/components/views/dialogs/AddressPickerDialog.js index 8dc348d2b0..edb29181a9 100644 --- a/src/components/views/dialogs/AddressPickerDialog.js +++ b/src/components/views/dialogs/AddressPickerDialog.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017, 2018, 2019 New Vector Ltd +Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -102,7 +103,7 @@ module.exports = React.createClass({ // Check the text input field to see if user has an unconverted address // If there is and it's valid add it to the local selectedList if (this.refs.textinput.value !== '') { - selectedList = this._addInputToList(); + selectedList = this._addAddressesToList([this.refs.textinput.value]); if (selectedList === null) return; } this.props.onFinished(true, selectedList); @@ -140,12 +141,12 @@ module.exports = React.createClass({ // if there's nothing in the input box, submit the form this.onButtonClick(); } else { - this._addInputToList(); + this._addAddressesToList([this.refs.textinput.value]); } } else if (e.keyCode === 188 || e.keyCode === 9) { // comma or tab e.stopPropagation(); e.preventDefault(); - this._addInputToList(); + this._addAddressesToList([this.refs.textinput.value]); } }, @@ -453,35 +454,40 @@ module.exports = React.createClass({ }); }, - _addInputToList: function() { - const addressText = this.refs.textinput.value.trim(); - const addrType = getAddressType(addressText); - const addrObj = { - addressType: addrType, - address: addressText, - isKnown: false, - }; - if (!this.props.validAddressTypes.includes(addrType)) { - this.setState({ error: true }); - return null; - } else if (addrType === 'mx-user-id') { - const user = MatrixClientPeg.get().getUser(addrObj.address); - if (user) { - addrObj.displayName = user.displayName; - addrObj.avatarMxc = user.avatarUrl; - addrObj.isKnown = true; - } - } else if (addrType === 'mx-room-id') { - const room = MatrixClientPeg.get().getRoom(addrObj.address); - if (room) { - addrObj.displayName = room.name; - addrObj.avatarMxc = room.avatarUrl; - addrObj.isKnown = true; - } - } - + _addAddressesToList: function(addressTexts) { const selectedList = this.state.selectedList.slice(); - selectedList.push(addrObj); + + addressTexts.forEach((addressText) => { + addressText = addressText.trim(); + const addrType = getAddressType(addressText); + const addrObj = { + addressType: addrType, + address: addressText, + isKnown: false, + }; + + if (!this.props.validAddressTypes.includes(addrType)) { + this.setState({ error: true }); + return null; + } else if (addrType === 'mx-user-id') { + const user = MatrixClientPeg.get().getUser(addrObj.address); + if (user) { + addrObj.displayName = user.displayName; + addrObj.avatarMxc = user.avatarUrl; + addrObj.isKnown = true; + } + } else if (addrType === 'mx-room-id') { + const room = MatrixClientPeg.get().getRoom(addrObj.address); + if (room) { + addrObj.displayName = room.name; + addrObj.avatarMxc = room.avatarUrl; + addrObj.isKnown = true; + } + } + + selectedList.push(addrObj); + }); + this.setState({ selectedList, suggestedList: [], @@ -540,6 +546,12 @@ module.exports = React.createClass({ }); }, + _onPaste: function(e) { + const text = e.clipboardData.getData("text"); + this._addAddressesToList(text.split(/[\s,]+/)); + e.preventDefault(); + }, + render: function() { const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); @@ -564,7 +576,9 @@ module.exports = React.createClass({ // Add the query at the end query.push( -