fix(msc4459): don't set mxc when there is no data to associate with it

This commit is contained in:
Rye committed 2026-05-04 06:57:11 +02:00
1 parent ff41ff1061
commit f49e84d1af
2 files changed
+11 -9

No files matched your search

+4 -5
View File
@@ -1134,11 +1134,10 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
} else {
editor.insertNode(emoticonEl);
}
if (!imagePacksUsedRef.current.has(key))
imagePacksUsedRef.current.set(
key,
getImagePackReferencesForMxc(key, mx, ImageUsage.Emoticon, room)
);
if (!imagePacksUsedRef.current.has(key)) {
const imgPkRef = getImagePackReferencesForMxc(key, mx, ImageUsage.Emoticon, room);
if (imgPkRef?.room_id && imgPkRef?.shortcode) imagePacksUsedRef.current.set(key, imgPkRef);
}
moveCursor(editor);
handleCloseAutocomplete();
};
+7 -4
View File
@@ -30,7 +30,7 @@ export function getImagePackReferencesForMxcWrappedInMap(
if (!mxcUrl.startsWith('mxc')) return retMap;
const result = getImagePackReferencesForMxc(mxcUrl, matrixClient, imageUsage, room);
// if the result is undefined return the empty map, to not produce invalid entries
if (!result?.room_id) return retMap;
if (!result?.room_id || !result?.state_key || !result?.shortcode) return retMap;
retMap.set(mxcUrl, result);
return retMap;
}
@@ -90,7 +90,7 @@ export function getImagePackReferencesForMxc(
roomLookupTable.set(room.roomId, roomLookupTabRes);
}
// prefer room local match as they're probably often more relevant
if (roomLocalMatch) return roomLocalMatch;
if (roomLocalMatch?.room_id && roomLocalMatch?.shortcode) return roomLocalMatch;
// simple caching
if (globalLookupTable.has(mxcUrl)) return globalLookupTable.get(mxcUrl)!;
const globalImgPacks: ImagePack[] = getGlobalImagePacks(matrixClient);
@@ -101,7 +101,10 @@ export function getImagePackReferencesForMxc(
imageUsage,
false
);
if (globalMatch) globalLookupTable.set(mxcUrl, globalMatch);
if (globalMatch?.room_id && globalMatch?.shortcode) {
globalLookupTable.set(mxcUrl, globalMatch);
return globalMatch;
}
return globalMatch ?? {};
return {};
}