From 938ce241ffeceb50c4fb32b09be1c16c2ce3a195 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Sat, 5 Nov 2022 15:55:14 +0100 Subject: [PATCH] feat: refetch errored/pending images on collab room init load (#5833) --- src/excalidraw-app/collab/Collab.tsx | 17 ++++++++++++++--- src/excalidraw-app/index.tsx | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/excalidraw-app/collab/Collab.tsx b/src/excalidraw-app/collab/Collab.tsx index 0aa185ff..58f3a890 100644 --- a/src/excalidraw-app/collab/Collab.tsx +++ b/src/excalidraw-app/collab/Collab.tsx @@ -310,16 +310,27 @@ class Collab extends PureComponent { } }; - private fetchImageFilesFromFirebase = async (scene: { + private fetchImageFilesFromFirebase = async (opts: { elements: readonly ExcalidrawElement[]; + /** + * Indicates whether to fetch files that are errored or pending and older + * than 10 seconds. + * + * Use this as a machanism to fetch files which may be ok but for some + * reason their status was not updated correctly. + */ + forceFetchFiles?: boolean; }) => { - const unfetchedImages = scene.elements + const unfetchedImages = opts.elements .filter((element) => { return ( isInitializedImageElement(element) && !this.fileManager.isFileHandled(element.fileId) && !element.isDeleted && - element.status === "saved" + (opts.forceFetchFiles + ? element.status !== "pending" || + Date.now() - element.updated > 10000 + : element.status === "saved") ); }) .map((element) => (element as InitializedExcalidrawImageElement).fileId); diff --git a/src/excalidraw-app/index.tsx b/src/excalidraw-app/index.tsx index 3f78e26b..8cffe69a 100644 --- a/src/excalidraw-app/index.tsx +++ b/src/excalidraw-app/index.tsx @@ -285,6 +285,7 @@ const ExcalidrawWrapper = () => { collabAPI .fetchImageFilesFromFirebase({ elements: data.scene.elements, + forceFetchFiles: true, }) .then(({ loadedFiles, erroredFiles }) => { excalidrawAPI.addFiles(loadedFiles);