Convert the user's last filter into a selection if possible

Fixes https://github.com/vector-im/riot-web/issues/12440
This commit is contained in:
Travis Ralston 2020-02-20 23:10:43 -07:00
parent 62aaa0db9a
commit f491e4222a

View file

@ -512,9 +512,26 @@ export default class InviteDialog extends React.PureComponent {
return false; return false;
} }
_convertFilter(): Member[] {
if (!this.state.filterText || !this.state.filterText.includes('@')) return; // nothing to convert
let newMember: Member;
if (this.state.filterText.startsWith('@')) {
// Assume mxid
newMember = new DirectoryMember({user_id: this.state.filterText, display_name: null, avatar_url: null});
} else {
// Assume email
newMember = new ThreepidMember(this.state.filterText);
}
const newTargets = [...this.state.targets, newMember];
this.setState({targets: newTargets, filterText: ''});
return newTargets;
}
_startDm = async () => { _startDm = async () => {
this.setState({busy: true}); this.setState({busy: true});
const targetIds = this.state.targets.map(t => t.userId); const targets = this._convertFilter();
const targetIds = targets.map(t => t.userId);
// Check if there is already a DM with these people and reuse it if possible. // Check if there is already a DM with these people and reuse it if possible.
const existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds); const existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds);
@ -573,7 +590,9 @@ export default class InviteDialog extends React.PureComponent {
_inviteUsers = () => { _inviteUsers = () => {
this.setState({busy: true}); this.setState({busy: true});
const targetIds = this.state.targets.map(t => t.userId); this._convertFilter();
const targets = this._convertFilter();
const targetIds = targets.map(t => t.userId);
const room = MatrixClientPeg.get().getRoom(this.props.roomId); const room = MatrixClientPeg.get().getRoom(this.props.roomId);
if (!room) { if (!room) {
@ -1038,6 +1057,7 @@ export default class InviteDialog extends React.PureComponent {
goButtonFn = this._inviteUsers; goButtonFn = this._inviteUsers;
} }
const hasSelection = this.state.targets.length > 0 || (this.state.filterText && this.state.filterText.includes('@'));
return ( return (
<BaseDialog <BaseDialog
className='mx_InviteDialog' className='mx_InviteDialog'
@ -1054,7 +1074,7 @@ export default class InviteDialog extends React.PureComponent {
kind="primary" kind="primary"
onClick={goButtonFn} onClick={goButtonFn}
className='mx_InviteDialog_goButton' className='mx_InviteDialog_goButton'
disabled={this.state.busy} disabled={this.state.busy || !hasSelection}
> >
{buttonText} {buttonText}
</AccessibleButton> </AccessibleButton>