Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Convert the user's last filter into a selection if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Feb 21, 2020
1 parent 62aaa0d commit f491e42
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/views/dialogs/InviteDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,26 @@ export default class InviteDialog extends React.PureComponent {
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 () => {
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.
const existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds);
Expand Down Expand Up @@ -573,7 +590,9 @@ export default class InviteDialog extends React.PureComponent {

_inviteUsers = () => {
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);
if (!room) {
Expand Down Expand Up @@ -1038,6 +1057,7 @@ export default class InviteDialog extends React.PureComponent {
goButtonFn = this._inviteUsers;
}

const hasSelection = this.state.targets.length > 0 || (this.state.filterText && this.state.filterText.includes('@'));
return (
<BaseDialog
className='mx_InviteDialog'
Expand All @@ -1054,7 +1074,7 @@ export default class InviteDialog extends React.PureComponent {
kind="primary"
onClick={goButtonFn}
className='mx_InviteDialog_goButton'
disabled={this.state.busy}
disabled={this.state.busy || !hasSelection}
>
{buttonText}
</AccessibleButton>
Expand Down

0 comments on commit f491e42

Please sign in to comment.