From 340c24cfa71757c1fe5c09d50296cb40fb225c18 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 26 Mar 2019 15:13:20 -0600 Subject: [PATCH 1/2] Filter out upgraded rooms from autocomplete results Fixes https://github.com/vector-im/riot-web/issues/9289 Theory is that this shouldn't happen in the first place (aliases should be transferred), but there's evidently some cases where this doesn't work, or gets state reset. --- src/autocomplete/RoomProvider.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/autocomplete/RoomProvider.js b/src/autocomplete/RoomProvider.js index 483506557f..ab5c3a259f 100644 --- a/src/autocomplete/RoomProvider.js +++ b/src/autocomplete/RoomProvider.js @@ -56,7 +56,7 @@ export default class RoomProvider extends AutocompleteProvider { const {command, range} = this.getCurrentCommand(query, selection, force); if (command) { // the only reason we need to do this is because Fuse only matches on properties - this.matcher.setObjects(client.getRooms().filter( + let matcherObjects = client.getRooms().filter( (room) => !!room && !!getDisplayAliasForRoom(room), ).map((room) => { return { @@ -64,7 +64,23 @@ export default class RoomProvider extends AutocompleteProvider { name: room.name, displayedAlias: getDisplayAliasForRoom(room), }; - })); + }); + + // Filter out any matches where the user will have also autocompleted new rooms + matcherObjects = matcherObjects.filter((r) => { + const tombstone = r.room.currentState.getStateEvents("m.room.tombstone", ""); + if (tombstone && tombstone.getContent() && tombstone.getContent()['replacement_room']) { + console.log(r.displayedAlias); + const hasReplacementRoom = matcherObjects.some( + (r2) => r2.room.roomId === tombstone.getContent()['replacement_room'], + ); + console.log(hasReplacementRoom); + return !hasReplacementRoom; + } + return true; + }); + + this.matcher.setObjects(matcherObjects); const matchedString = command[0]; completions = this.matcher.match(matchedString); completions = _sortBy(completions, [ From 85c8d4d0e5ebf69a1f7298158a9aa56b6c12313b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 27 Mar 2019 13:03:25 -0600 Subject: [PATCH 2/2] Remove extra debug lines --- src/autocomplete/RoomProvider.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/autocomplete/RoomProvider.js b/src/autocomplete/RoomProvider.js index ab5c3a259f..f118a06b9e 100644 --- a/src/autocomplete/RoomProvider.js +++ b/src/autocomplete/RoomProvider.js @@ -70,11 +70,9 @@ export default class RoomProvider extends AutocompleteProvider { matcherObjects = matcherObjects.filter((r) => { const tombstone = r.room.currentState.getStateEvents("m.room.tombstone", ""); if (tombstone && tombstone.getContent() && tombstone.getContent()['replacement_room']) { - console.log(r.displayedAlias); const hasReplacementRoom = matcherObjects.some( (r2) => r2.room.roomId === tombstone.getContent()['replacement_room'], ); - console.log(hasReplacementRoom); return !hasReplacementRoom; } return true;