From 6269780f4b943ce4216faa6d29771dde3a599804 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 28 Feb 2020 13:57:56 -0700 Subject: [PATCH] Suggest the server's results as lower quality This is a quick win for fixing https://github.com/vector-im/riot-web/issues/12488 but might not be a long-term solution. Idea is to see how this feels and go from there, which may mean scoring the results again to filter them in or altering the debounce timers. --- src/components/views/dialogs/InviteDialog.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/views/dialogs/InviteDialog.js b/src/components/views/dialogs/InviteDialog.js index e8c39b6d5a..b1ad4a34d0 100644 --- a/src/components/views/dialogs/InviteDialog.js +++ b/src/components/views/dialogs/InviteDialog.js @@ -906,24 +906,24 @@ export default class InviteDialog extends React.PureComponent { // Mix in the server results if we have any, but only if we're searching. We track the additional // members separately because we want to filter sourceMembers but trust the mixin arrays to have // the right members in them. - let additionalMembers = []; + let priorityAdditionalMembers = []; // Shows up before our own suggestions, higher quality + let otherAdditionalMembers = []; // Shows up after our own suggestions, lower quality const hasMixins = this.state.serverResultsMixin || this.state.threepidResultsMixin; if (this.state.filterText && hasMixins && kind === 'suggestions') { // We don't want to duplicate members though, so just exclude anyone we've already seen. const notAlreadyExists = (u: Member): boolean => { return !sourceMembers.some(m => m.userId === u.userId) - && !additionalMembers.some(m => m.userId === u.userId); + && !priorityAdditionalMembers.some(m => m.userId === u.userId) + && !otherAdditionalMembers.some(m => m.userId === u.userId); }; - const uniqueServerResults = this.state.serverResultsMixin.filter(notAlreadyExists); - additionalMembers = additionalMembers.concat(...uniqueServerResults); - - const uniqueThreepidResults = this.state.threepidResultsMixin.filter(notAlreadyExists); - additionalMembers = additionalMembers.concat(...uniqueThreepidResults); + otherAdditionalMembers = this.state.serverResultsMixin.filter(notAlreadyExists); + priorityAdditionalMembers = this.state.threepidResultsMixin.filter(notAlreadyExists); } + const hasAdditionalMembers = priorityAdditionalMembers.length > 0 || otherAdditionalMembers.length > 0; // Hide the section if there's nothing to filter by - if (sourceMembers.length === 0 && additionalMembers.length === 0) return null; + if (sourceMembers.length === 0 && !hasAdditionalMembers) return null; // Do some simple filtering on the input before going much further. If we get no results, say so. if (this.state.filterText) { @@ -931,7 +931,7 @@ export default class InviteDialog extends React.PureComponent { sourceMembers = sourceMembers .filter(m => m.user.name.toLowerCase().includes(filterBy) || m.userId.toLowerCase().includes(filterBy)); - if (sourceMembers.length === 0 && additionalMembers.length === 0) { + if (sourceMembers.length === 0 && !hasAdditionalMembers) { return (

{sectionName}

@@ -943,7 +943,7 @@ export default class InviteDialog extends React.PureComponent { // Now we mix in the additional members. Again, we presume these have already been filtered. We // also assume they are more relevant than our suggestions and prepend them to the list. - sourceMembers = [...additionalMembers, ...sourceMembers]; + sourceMembers = [...priorityAdditionalMembers, ...sourceMembers, ...otherAdditionalMembers]; // If we're going to hide one member behind 'show more', just use up the space of the button // with the member's tile instead.