Skip to main content

Overview

Every file link Sublay returns stops working at its File’s linksExpireAt, 24 to 48 hours after it was read (File links). An app left open longer than that would show broken images. useFileLinks keeps them working. Pass it a File (or a bare link, such as a notification’s spaceAvatar) and render what it returns. While the links work it returns what it was given. Once they have expired, or are about to, it asks Refresh File Links for fresh ones and re-renders with them:
  • Batched: every image on screen that needs fresh links is asked for in one request.
  • By id: nothing else is read again, so lists and scroll positions stay as they are.
  • Bounded: each link is asked about at most twice: once when it expires, once if it fails to load. A file the viewer can no longer see gets no fresh link: the old one is returned and stops working. A failed request is retried once.
useReportFileLoadError is for an image’s onError: it asks once for a fresh link, in case the device’s clock is off and the link expired earlier than it thinks. The avatar the components installed with sublay add draw already does both. Any other File your app renders (an entity’s or a message’s images, for example) needs to go through useFileLinks for its links to be refreshed. A File without linksExpireAt (and a link without exp) doesn’t expire, and is returned as is.

Usage Example

Parameters

File | string | null | undefined
required
The File whose links to keep working, or a bare link (a string). null and undefined are returned as they are.

useReportFileLoadError

Takes no parameters.

Returns

The same kind of value it was given: the File (or link) with links that work, once fresh ones have arrived; until then, what it was given.

useReportFileLoadError

(file: File | string | null | undefined) => void
Asks once for a fresh link for this File or link.

Notes

  • Store a file’s id, never a link: a stored link stops working within two days.
  • On React Native, an image library that caches by URL downloads an image again when its link changes, at most about once a day per file.