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

Authenticated media and animated thumbnails support #776

Merged
merged 7 commits into from
Jul 18, 2024

Conversation

KitsuneRal
Copy link
Member

This commit implements a proxy layer (almost entirely in terms of existing facilities - Connection::downloadFile()/DownloadFileJob and Connection::getThumbnail()/MediaThumbnailJob respectively) to spare clients from having to figure out which API, old or new, they should use to retrieve media on any given homeserver. In all honesty, the code for the new API hasn't been tested yet but it's almost entirely based on the generated API classes, so nothing should go wrong because our CS API descriptions are perfect, right? :-D

Implements MSC3916 and, while at it, [MSC2705](https://github.com/matrix-org/matrix-spec-proposals/pull/2705] (animated thumbnails).

- Connection::loadCapabilities() is a better name for
  reloadCapabilities(); it also returns a JobHandle so that callers
  could act upon the job completion, successful or not
- Connection::loadVersions() spawns GetVersionsJob to obtain supported
  spec versions
- ...which are then exposed by Connection::supportedMatrixSpecVersions()
- Connection::loadingCapabilities() is deprecated in favour of
  Connection::capabilitiesReady(): it was never meant to check
  whether capabilities are being loaded, rather that they _have been_
  loaded and are available locally; the new name and semantics reflect
  that
- HomeserverData encapsulates minimal information about the homeserver
  that is necessary to form network requests to it, encapsulating
  baseUrl but also including spec versions supported by the homeserver
  so that the right endpoint could be picked depending on those.
  Normally, clients should not use this structure directly; actually,
  it may end up blending into ConnectionData if/when it becomes
  thread-safe and therefore usable inside NetworkAccessManager.
- NetworkAccessManager, respectively, now stores account's
  HomeserverData in its thread-safe storage, so that it could be used
  to convert mxc requests into DownloadFileJob requests in a following
  commit.
DownloadFileJob and MediaThumbnailJob now act as proxies to either
GetContentJob/GetThumbnailJob or
GetContentAuthedJob/GetThumbnailAuthedJob, respectively - selecting
the right endpoint based on spec versions supported by the homeserver.
To support that, BaseJob::doPrepare() virtual function now accepts
ConnectionData so that derived jobs could check homeserverData() in it,
and BaseJob::makeRequestUrl() gets HomeserverData instead of QUrl for
the first parameter (effectively imposing the same requirement to
makeRequestUrl() signatures in all other jobs).

FTBFS; next commits for generated job classes will fix the build.
It doesn't seem to be in use anyway (downloadFile() is instead).
Looks like std::vector::emplace_back() from libc++ is/was seriously
broken?
@KitsuneRal KitsuneRal added the enhancement A feature or change request for the library label Jul 17, 2024
@KitsuneRal KitsuneRal changed the title Authenticated media support Authenticated media and animated thumbnails support Jul 17, 2024
Copy link

sonarcloud bot commented Jul 17, 2024

TobiasFella
TobiasFella previously approved these changes Jul 17, 2024
Copy link
Member

@TobiasFella TobiasFella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable

Quotient/avatar.cpp Outdated Show resolved Hide resolved
@KitsuneRal KitsuneRal merged commit 0894fc1 into dev Jul 18, 2024
6 checks passed
@KitsuneRal KitsuneRal deleted the kitsune/authed-media-support branch July 18, 2024 05:58
KitsuneRal added a commit that referenced this pull request Jul 18, 2024
This was introduced as a workaround for cases when homeservers
require authentication on media endpoints, deviating from the spec text
of that time in order to protect themselves. This workaround is not
necessary since #776; DownloadFileJob and MediaThumbnailJob now always
supply the access token even when the homeserver doesn't require it.
@KitsuneRal KitsuneRal linked an issue Aug 24, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or change request for the library
Projects
Status: 0.9 - Done
Development

Successfully merging this pull request may close these issues.

NetworkAccessManager doesn't work with authenticating media servers
2 participants