From 41be46a7120075b5792194bcdf2c56f6e9b240fa Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 13 Jun 2018 09:51:35 +0100 Subject: [PATCH 1/2] apply roomlist searchFilter to aliases if it begins with a `#` Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/RoomSubList.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index fb82ee067b..17daa8553b 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -105,8 +105,15 @@ var RoomSubList = React.createClass({ applySearchFilter: function(list, filter) { if (filter === "") return list; + const lcFilter = filter.toLowerCase(); return list.filter((room) => { - return room.name && room.name.toLowerCase().indexOf(filter.toLowerCase()) >= 0 + if (room.name && room.name.toLowerCase().includes(lcFilter)) return true; + // only apply search filter to aliases if it looks like an alias (starts with `#`) + // to prevent loads of false positives with server names, e.g `matrix` + if (filter[0] === '#' && room.getAliases().some((alias) => { + return alias.toLowerCase().startsWith(lcFilter); + })) return true; + return false; }); }, From 384c9745896fa79311a3e4be474eb200d64656f9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 14 Jun 2018 11:16:57 +0100 Subject: [PATCH 2/2] tidy up if statements and fix up comments Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/RoomSubList.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/components/structures/RoomSubList.js b/src/components/structures/RoomSubList.js index 17daa8553b..33ff17caa4 100644 --- a/src/components/structures/RoomSubList.js +++ b/src/components/structures/RoomSubList.js @@ -106,15 +106,10 @@ var RoomSubList = React.createClass({ applySearchFilter: function(list, filter) { if (filter === "") return list; const lcFilter = filter.toLowerCase(); - return list.filter((room) => { - if (room.name && room.name.toLowerCase().includes(lcFilter)) return true; - // only apply search filter to aliases if it looks like an alias (starts with `#`) - // to prevent loads of false positives with server names, e.g `matrix` - if (filter[0] === '#' && room.getAliases().some((alias) => { - return alias.toLowerCase().startsWith(lcFilter); - })) return true; - return false; - }); + // case insensitive if room name includes filter, + // or if starts with `#` and one of room's aliases starts with filter + return list.filter((room) => (room.name && room.name.toLowerCase().includes(lcFilter)) || + (filter[0] === '#' && room.getAliases().some((alias) => alias.toLowerCase().startsWith(lcFilter)))); }, // The header is collapsable if it is hidden or not stuck