diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-21 05:49:12 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-03-21 05:49:12 +0100 |
commit | a9486ec89616a1e944d325c99d87173742a2de33 (patch) | |
tree | 70a494e3abcfc6f085f64d5497afa86373faacb9 /src/EventAccessors.cpp | |
parent | Show some previews in upload window (diff) | |
download | nheko-a9486ec89616a1e944d325c99d87173742a2de33.tar.xz |
Fix thumbnails for encrypted files and factor upload box out
Diffstat (limited to 'src/EventAccessors.cpp')
-rw-r--r-- | src/EventAccessors.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp index 00cea86e..e4dfe92e 100644 --- a/src/EventAccessors.cpp +++ b/src/EventAccessors.cpp @@ -139,6 +139,19 @@ struct EventFile } }; +struct EventThumbnailFile +{ + template<class Content> + using file_t = decltype(Content::info.thumbnail_file); + template<class T> + std::optional<mtx::crypto::EncryptedFile> operator()(const mtx::events::Event<T> &e) + { + if constexpr (is_detected<file_t, T>::value) + return e.content.info.thumbnail_file; + return std::nullopt; + } +}; + struct EventUrl { template<class Content> @@ -163,6 +176,8 @@ struct EventThumbnailUrl std::string operator()(const mtx::events::Event<T> &e) { if constexpr (is_detected<thumbnail_url_t, T>::value) { + if (auto file = EventThumbnailFile{}(e)) + return file->url; return e.content.info.thumbnail_url; } return ""; @@ -424,6 +439,12 @@ mtx::accessors::file(const mtx::events::collections::TimelineEvents &event) return std::visit(EventFile{}, event); } +std::optional<mtx::crypto::EncryptedFile> +mtx::accessors::thumbnail_file(const mtx::events::collections::TimelineEvents &event) +{ + return std::visit(EventThumbnailFile{}, event); +} + std::string mtx::accessors::url(const mtx::events::collections::TimelineEvents &event) { |