Fix all rooms search generating permalinks to wrong room id (#10625)
* Fix all rooms search generating permalinks to wrong room id * Iterate * Add comment * Iterate * Add coverage * Iterate * Add comment * Restore src/utils/permalinks/Permalinks.ts * Update src/components/structures/RoomSearchView.tsx Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
7f32b423c5
commit
2b3e0b47ba
3 changed files with 151 additions and 22 deletions
|
@ -50,7 +50,6 @@ interface Props {
|
|||
promise: Promise<ISearchResults>;
|
||||
abortController?: AbortController;
|
||||
resizeNotifier: ResizeNotifier;
|
||||
permalinkCreator: RoomPermalinkCreator;
|
||||
className: string;
|
||||
onUpdate(inProgress: boolean, results: ISearchResults | null): void;
|
||||
}
|
||||
|
@ -59,7 +58,7 @@ 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, className, onUpdate }: Props,
|
||||
ref: RefObject<ScrollPanel>,
|
||||
) => {
|
||||
const client = useContext(MatrixClientContext);
|
||||
|
@ -68,6 +67,15 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
|
|||
const [highlights, setHighlights] = useState<string[] | null>(null);
|
||||
const [results, setResults] = useState<ISearchResults | null>(null);
|
||||
const aborted = useRef(false);
|
||||
// A map from room ID to permalink creator
|
||||
const permalinkCreators = useRef(new Map<string, RoomPermalinkCreator>()).current;
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
permalinkCreators.forEach((pc) => pc.stop());
|
||||
permalinkCreators.clear();
|
||||
};
|
||||
}, [permalinkCreators]);
|
||||
|
||||
const handleSearchResult = useCallback(
|
||||
(searchPromise: Promise<ISearchResults>): Promise<boolean> => {
|
||||
|
@ -217,7 +225,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
|
||||
|
@ -283,6 +291,13 @@ export const RoomSearchView = forwardRef<ScrollPanel, Props>(
|
|||
ourEventsIndexes.push(result.context.getOurEventIndex());
|
||||
}
|
||||
|
||||
let permalinkCreator = permalinkCreators.get(roomId);
|
||||
if (!permalinkCreator) {
|
||||
permalinkCreator = new RoomPermalinkCreator(room);
|
||||
permalinkCreator.start();
|
||||
permalinkCreators.set(roomId, permalinkCreator);
|
||||
}
|
||||
|
||||
ret.push(
|
||||
<SearchResultTile
|
||||
key={mxEv.getId()}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue