This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Don't show addresses that have already been picked #1678
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cc05903
Don't show addresses that have already been picked
t3chguy df7d545
change check to be explicit such that both address and type must match
t3chguy 029d9a5
Exclude rooms/users already in group in invite/add dialogs
t3chguy ab14c0c
Exclude rooms already in room in invite user to room dialog
t3chguy 01f4801
Exclude users/rooms already in group in GroupView/featured
t3chguy 7cc6243
fix typo and small layout tweaks
t3chguy a7f317a
fix comment typo
t3chguy a73715e
remove includeSelf and slight refactor
t3chguy cae812c
now that includeSelf (def=false) is gone, use generic replacement
t3chguy 7ff2ef3
remove redundant var cli
t3chguy a27bafd
improve comments
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,14 @@ module.exports = React.createClass({ | |
button: PropTypes.string, | ||
focus: PropTypes.bool, | ||
validAddressTypes: PropTypes.arrayOf(PropTypes.oneOf(addressTypes)), | ||
excludedAddresses: PropTypes.arrayOf(PropTypes.shape({ | ||
addressType: PropTypes.oneOf(addressTypes), | ||
address: PropTypes.string.isRequired, | ||
})), | ||
onFinished: PropTypes.func.isRequired, | ||
groupId: PropTypes.string, | ||
// The type of entity to search for. Default: 'user'. | ||
pickerType: PropTypes.oneOf(['user', 'room']), | ||
// Whether the current user should be included in the addresses returned. Only | ||
// applicable when pickerType is `user`. Default: false. | ||
includeSelf: PropTypes.bool, | ||
}, | ||
|
||
getDefaultProps: function() { | ||
|
@@ -57,7 +58,6 @@ module.exports = React.createClass({ | |
focus: true, | ||
validAddressTypes: addressTypes, | ||
pickerType: 'user', | ||
includeSelf: false, | ||
}; | ||
}, | ||
|
||
|
@@ -130,7 +130,7 @@ module.exports = React.createClass({ | |
} else if (e.keyCode === 13) { // enter | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
if (this.refs.textinput.value == '') { | ||
if (this.refs.textinput.value === '') { | ||
// if there's nothing in the input box, submit the form | ||
this.onButtonClick(); | ||
} else { | ||
|
@@ -149,7 +149,7 @@ module.exports = React.createClass({ | |
clearTimeout(this.queryChangedDebouncer); | ||
} | ||
// Only do search if there is something to search | ||
if (query.length > 0 && query != '@' && query.length >= 2) { | ||
if (query.length > 0 && query !== '@' && query.length >= 2) { | ||
this.queryChangedDebouncer = setTimeout(() => { | ||
if (this.props.pickerType === 'user') { | ||
if (this.props.groupId) { | ||
|
@@ -383,31 +383,33 @@ module.exports = React.createClass({ | |
_processResults: function(results, query) { | ||
const queryList = []; | ||
results.forEach((result) => { | ||
let newEntry; | ||
|
||
if (result.room_id) { | ||
queryList.push({ | ||
newEntry = { | ||
addressType: 'mx-room-id', | ||
address: result.room_id, | ||
displayName: result.name, | ||
avatarMxc: result.avatar_url, | ||
isKnown: true, | ||
}); | ||
return; | ||
} | ||
if (!this.props.includeSelf && | ||
result.user_id === MatrixClientPeg.get().credentials.userId | ||
) { | ||
return; | ||
}; | ||
} else { | ||
// Return objects, structure of which is defined | ||
// by UserAddressType | ||
newEntry = { | ||
addressType: 'mx-user-id', | ||
address: result.user_id, | ||
displayName: result.display_name, | ||
avatarMxc: result.avatar_url, | ||
isKnown: true, | ||
}; | ||
} | ||
|
||
// Return objects, structure of which is defined | ||
// by UserAddressType | ||
queryList.push({ | ||
addressType: 'mx-user-id', | ||
address: result.user_id, | ||
displayName: result.display_name, | ||
avatarMxc: result.avatar_url, | ||
isKnown: true, | ||
}); | ||
// Don't add it if it is in the excludedAddresses | ||
if (this.props.excludedAddresses.find((entry) => { | ||
return entry.address === newEntry.address && entry.addressType === newEntry.addressType; | ||
})) return; | ||
queryList.push(newEntry); | ||
}); | ||
|
||
// If the query is a valid address, add an entry for that | ||
|
@@ -421,7 +423,7 @@ module.exports = React.createClass({ | |
isKnown: false, | ||
}); | ||
if (this._cancelThreepidLookup) this._cancelThreepidLookup(); | ||
if (addrType == 'email') { | ||
if (addrType === 'email') { | ||
this._lookupThreepid(addrType, query).done(); | ||
} | ||
} | ||
|
@@ -444,14 +446,14 @@ module.exports = React.createClass({ | |
if (!this.props.validAddressTypes.includes(addrType)) { | ||
this.setState({ error: true }); | ||
return null; | ||
} else if (addrType == 'mx-user-id') { | ||
} 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') { | ||
} else if (addrType === 'mx-room-id') { | ||
const room = MatrixClientPeg.get().getRoom(addrObj.address); | ||
if (room) { | ||
addrObj.displayName = room.name; | ||
|
@@ -511,6 +513,12 @@ module.exports = React.createClass({ | |
const AddressSelector = sdk.getComponent("elements.AddressSelector"); | ||
this.scrollElement = null; | ||
|
||
const queryList = this.state.queryList.filter((query) => { | ||
return !this.state.userList.find((entry) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is |
||
return entry.address === query.address && entry.addressType === query.addressType; | ||
}); | ||
}); | ||
|
||
const query = []; | ||
// create the invite list | ||
if (this.state.userList.length > 0) { | ||
|
@@ -544,15 +552,14 @@ module.exports = React.createClass({ | |
let error; | ||
let addressSelector; | ||
if (this.state.error) { | ||
let tryUsing = ''; | ||
const validTypeDescriptions = this.props.validAddressTypes.map((t) => { | ||
return { | ||
'mx-user-id': _t("Matrix ID"), | ||
'mx-room-id': _t("Matrix Room ID"), | ||
'email': _t("email address"), | ||
}[t]; | ||
}); | ||
tryUsing = _t("Try using one of the following valid address types: %(validTypesList)s.", { | ||
const tryUsing = _t("Try using one of the following valid address types: %(validTypesList)s.", { | ||
validTypesList: validTypeDescriptions.join(", "), | ||
}); | ||
error = <div className="mx_ChatInviteDialog_error"> | ||
|
@@ -562,16 +569,12 @@ module.exports = React.createClass({ | |
</div>; | ||
} else if (this.state.searchError) { | ||
error = <div className="mx_ChatInviteDialog_error">{ this.state.searchError }</div>; | ||
} else if ( | ||
this.state.query.length > 0 && | ||
this.state.queryList.length === 0 && | ||
!this.state.busy | ||
) { | ||
} else if (this.state.query.length > 0 && queryList.length === 0 && !this.state.busy) { | ||
error = <div className="mx_ChatInviteDialog_error">{ _t("No results") }</div>; | ||
} else { | ||
addressSelector = ( | ||
<AddressSelector ref={(ref) => {this.addressSelector = ref;}} | ||
addressList={this.state.queryList} | ||
addressList={queryList} | ||
showAddress={this.props.pickerType === 'user'} | ||
onSelected={this.onSelected} | ||
truncateAt={TRUNCATE_QUERY_LIST} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is
O(n^2)
but optimising it would probably be premature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one could be optimized by changing the format of exludedAddresses to be a map, for constant time access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but I'd suggest we wait until there's an actual perf problem (so for now we choose readability over speed)