Merge pull request #4859 from matrix-org/t3chguy/dedup-rooms-autocomplete
De-duplicate rooms from the room autocomplete provider
This commit is contained in:
commit
52b52dfec4
1 changed files with 3 additions and 2 deletions
|
@ -25,9 +25,9 @@ import {MatrixClientPeg} from '../MatrixClientPeg';
|
||||||
import QueryMatcher from './QueryMatcher';
|
import QueryMatcher from './QueryMatcher';
|
||||||
import {PillCompletion} from './Components';
|
import {PillCompletion} from './Components';
|
||||||
import * as sdk from '../index';
|
import * as sdk from '../index';
|
||||||
import _sortBy from 'lodash/sortBy';
|
|
||||||
import {makeRoomPermalink} from "../utils/permalinks/Permalinks";
|
import {makeRoomPermalink} from "../utils/permalinks/Permalinks";
|
||||||
import {ICompletion, ISelectionRange} from "./Autocompleter";
|
import {ICompletion, ISelectionRange} from "./Autocompleter";
|
||||||
|
import { uniqBy, sortBy } from 'lodash';
|
||||||
|
|
||||||
const ROOM_REGEX = /\B#\S*/g;
|
const ROOM_REGEX = /\B#\S*/g;
|
||||||
|
|
||||||
|
@ -91,10 +91,11 @@ export default class RoomProvider extends AutocompleteProvider {
|
||||||
this.matcher.setObjects(matcherObjects);
|
this.matcher.setObjects(matcherObjects);
|
||||||
const matchedString = command[0];
|
const matchedString = command[0];
|
||||||
completions = this.matcher.match(matchedString);
|
completions = this.matcher.match(matchedString);
|
||||||
completions = _sortBy(completions, [
|
completions = sortBy(completions, [
|
||||||
(c) => score(matchedString, c.displayedAlias),
|
(c) => score(matchedString, c.displayedAlias),
|
||||||
(c) => c.displayedAlias.length,
|
(c) => c.displayedAlias.length,
|
||||||
]);
|
]);
|
||||||
|
completions = uniqBy(completions, (match) => match.room);
|
||||||
completions = completions.map((room) => {
|
completions = completions.map((room) => {
|
||||||
return {
|
return {
|
||||||
completion: room.displayedAlias,
|
completion: room.displayedAlias,
|
||||||
|
|
Loading…
Reference in a new issue