Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows search to recognize full room links #8275

Merged
merged 33 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
97bcf1d
fix matrix search link
bolu-tife Apr 10, 2022
604a6ed
fix matrix search link
bolu-tife Apr 10, 2022
9ba6051
fix: allow full link search
bolu-tife Apr 10, 2022
9d10d95
fix: allow full link search on new search feature
bolu-tife Apr 10, 2022
85c9d66
improve transformSearchTerm function
bolu-tife Apr 10, 2022
225bcab
improve transformSearchTerm function
bolu-tife Apr 10, 2022
b0f2b91
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Apr 14, 2022
4c6e4c0
add review changes
bolu-tife Apr 15, 2022
bef2ac5
Signed-off-by: Boluwatife Omosowon <boluomosowon@gmail.com>
bolu-tife Apr 16, 2022
a33c486
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Apr 16, 2022
1dba919
add angle brackets to copyright email title
bolu-tife Apr 16, 2022
c26fbf2
removed extra space
bolu-tife Apr 17, 2022
bd46c1e
merged develop into branch
Mar 3, 2023
3adaca0
Update src/utils/SearchInput.ts
bolu-tife Mar 6, 2023
201679f
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
Mar 6, 2023
2dfea11
fixed spolight dialog search for room and user links
Mar 7, 2023
23b9f10
added tests for transformSearchTerm
Mar 7, 2023
897a099
removed transformSearchTerm from room search bar
Mar 7, 2023
db0a434
Merge branch 'develop' into fix/matrix-link-search
bolu-tife Mar 7, 2023
2380985
Merge branch 'matrix-org:develop' into fix/matrix-link-search
bolu-tife Apr 21, 2023
9877e29
replaces two test cases to one that should return the primaryEntityId…
May 1, 2023
818fe72
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 1, 2023
67da64d
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 2, 2023
a8364e6
corrected ts issues
May 3, 2023
49fcb95
Merge branch 'fix/matrix-link-search' of https://github.com/bolu-tife…
May 3, 2023
d63b7e8
Merge branch 'develop' into fix/matrix-link-search
bolu-tife May 3, 2023
f42aea9
changed type of transformSearchTerm to string
May 3, 2023
a973adf
changed return value from empty string to the original search term if…
May 5, 2023
89d7636
changed return value from empty string to the original search term if…
May 5, 2023
377fd93
refactored transformSearchTerm and added a new test case
May 5, 2023
bd055d5
rewrote transformSearchTerm doc
May 5, 2023
682d3f8
changed mocked return values of test case - should return the origina…
May 5, 2023
825e1ce
lint corrections
May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 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 { transformSearchTerm } from "../../utils/SearchInput";

const LAST_SERVER_KEY = "mx_last_room_directory_server";
const LAST_INSTANCE_KEY = "mx_last_room_directory_instance";
Expand Down Expand Up @@ -186,7 +187,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: transformSearchTerm(filterString) };
return MatrixClientPeg.get().publicRooms(opts).then((data) => {
if (
filterString != this.state.filterString ||
Expand Down Expand Up @@ -322,9 +323,8 @@ export default class RoomDirectory extends React.Component<IProps, IState> {

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

bolu-tife marked this conversation as resolved.
Show resolved Hide resolved
// don't send the request for a little bit,
// no point hammering the server with a
// request for every keystroke, let the
Expand Down
3 changes: 2 additions & 1 deletion src/components/views/dialogs/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
import { PosthogAnalytics } from "../../../PosthogAnalytics";
import { getCachedRoomIDForAlias } from "../../../RoomAliasCache";
import { roomContextDetailsText, spaceContextDetailsText } from "../../../utils/i18n-helpers";
import { transformSearchTerm } from "../../../utils/SearchInput";

const MAX_RECENT_SEARCHES = 10;
const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons
Expand Down Expand Up @@ -305,7 +306,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);

const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
const newQuery = e.currentTarget.value;
const newQuery = transformSearchTerm(e.currentTarget.value);
_setQuery(newQuery);

setImmediate(() => {
Expand Down
29 changes: 29 additions & 0 deletions src/utils/SearchInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2022 Boluwatife Omosowon <boluomosowon@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { parsePermalink } from "../utils/permalinks/Permalinks";

/**
* Return the roomId or alias of an element or matrix room link
* E.g https://matrix.to/#/#element-dev:matrix.org returns #element-dev:matrix.org
* @param {string} searchTerm The searchterm.
* @returns {string} Tranforms the string to its roomid or alias if it is a matrix or element link.
bolu-tife marked this conversation as resolved.
Show resolved Hide resolved
*/
export function transformSearchTerm(searchTerm: string): string {
const parseLink = parsePermalink(searchTerm);
if (parseLink) return parseLink.roomIdOrAlias;
return searchTerm;
}