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

Fix all rooms search generating permalinks to wrong room id #10625

Merged
merged 12 commits into from
Apr 26, 2023
24 changes: 22 additions & 2 deletions src/components/structures/RoomSearchView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ interface Props {
// XXX: why doesn't searching on name work?
export const RoomSearchView = forwardRef<ScrollPanel, Props>(
(
{ term, scope, promise, abortController, resizeNotifier, permalinkCreator, className, onUpdate }: Props,
{
term,
scope,
promise,
abortController,
resizeNotifier,
permalinkCreator: _permalinkCreator,
className,
onUpdate,
}: Props,
ref: RefObject<ScrollPanel>,
) => {
const client = useContext(MatrixClientContext);
Expand All @@ -68,6 +77,7 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
const [highlights, setHighlights] = useState<string[] | null>(null);
const [results, setResults] = useState<ISearchResults | null>(null);
const aborted = useRef(false);
const permalinkCreators = useRef(new Map<string, RoomPermalinkCreator>()).current;
t3chguy marked this conversation as resolved.
Show resolved Hide resolved

const handleSearchResult = useCallback(
(searchPromise: Promise<ISearchResults>): Promise<boolean> => {
Expand Down Expand Up @@ -217,7 +227,7 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
const result = results.results[i];

const mxEv = result.context.getEvent();
const roomId = mxEv.getRoomId();
const roomId = mxEv.getRoomId()!;
const room = client.getRoom(roomId);
if (!room) {
// if we do not have the room in js-sdk stores then hide it as we cannot easily show it
Expand Down Expand Up @@ -283,6 +293,16 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
ourEventsIndexes.push(result.context.getOurEventIndex());
}

let permalinkCreator = _permalinkCreator;
if (roomId !== permalinkCreator.roomId) {
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
if (permalinkCreators.has(roomId)) {
permalinkCreator = permalinkCreators.get(roomId)!;
} else {
permalinkCreator = new RoomPermalinkCreator(client.getRoom(roomId), roomId);
permalinkCreators.set(roomId, permalinkCreator);
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
}
}

ret.push(
<SearchResultTile
key={mxEv.getId()}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/permalinks/Permalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const ANY_REGEX = /.*/;
// the list and magically have the link work.

export class RoomPermalinkCreator {
private roomId: string;
public readonly roomId: string;
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
private highestPlUserId: string | null = null;
private populationMap: { [serverName: string]: number } = {};
private bannedHostsRegexps: RegExp[] = [];
Expand Down