Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix matrix search link
Browse files Browse the repository at this point in the history
  • Loading branch information
bolu-tife committed Apr 10, 2022
1 parent 61076c3 commit 97bcf1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/components/structures/RoomDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Action } from "../../dispatcher/actions";
import PosthogTrackers from "../../PosthogTrackers";
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
import { PublicRoomTile } from "../views/rooms/PublicRoomTile";
import { filter } from "jszip";

const LAST_SERVER_KEY = "mx_last_room_directory_server";
const LAST_INSTANCE_KEY = "mx_last_room_directory_instance";
Expand Down Expand Up @@ -164,6 +165,10 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
this.getMoreRooms();
};

private transformSearchTerm(term: string): string {
return term.substring(term.lastIndexOf("#"));
};

private getMoreRooms(): Promise<boolean> {
if (!MatrixClientPeg.get()) return Promise.resolve(false);

Expand All @@ -186,7 +191,7 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
opts.third_party_instance_id = this.state.instanceId as string;
}
if (this.nextBatch) opts.since = this.nextBatch;
if (filterString) opts.filter = { generic_search_term: filterString };
if (filterString) opts.filter = { generic_search_term: this.transformSearchTerm(filterString) };
return MatrixClientPeg.get().publicRooms(opts).then((data) => {
if (
filterString != this.state.filterString ||
Expand All @@ -203,8 +208,10 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
return false;
}


this.nextBatch = data.next_batch;
this.setState((s) => ({

...s,
publicRooms: [...s.publicRooms, ...(data.chunk || [])],
loading: false,
Expand Down Expand Up @@ -322,7 +329,7 @@ export default class RoomDirectory extends React.Component<IProps, IState> {

private onFilterChange = (alias: string) => {
this.setState({
filterString: alias?.trim() || "",
filterString: this.transformSearchTerm(alias?.trim()) || "",
});

// don't send the request for a little bit,
Expand Down
6 changes: 5 additions & 1 deletion src/components/structures/RoomSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
}
};

private transformSearchTerm(term: string): string {
return term.substring(term.lastIndexOf("#"));
};

private onChange = () => {
if (this.elementRef.current?.tagName !== "INPUT") return;
this.setState({ query: (this.elementRef.current as HTMLInputElement).value });
this.setState({ query: this.transformSearchTerm((this.elementRef.current as HTMLInputElement).value) });
};

private onFocus = (ev: React.FocusEvent<HTMLInputElement>) => {
Expand Down

0 comments on commit 97bcf1d

Please sign in to comment.