Fix thumbnails for encrypted files and factor upload box out

This commit is contained in:
Nicolas Werner 2022-03-21 05:49:12 +01:00
parent dbd2bebe6c
commit a9486ec896
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
8 changed files with 182 additions and 83 deletions

View file

@ -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)
{