Skip to content

Commit

Permalink
Merge #809(kitsune): Fixes before 0.9 RC2
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Oct 15, 2024
2 parents 0b9f34d + 1e3dc8d commit b07afdc
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 170 deletions.
6 changes: 3 additions & 3 deletions Quotient/csapi/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QUrl GetDisplayNameJob::makeRequestUrl(const HomeserverData& hsData, const QStri

GetDisplayNameJob::GetDisplayNameJob(const QString& userId)
: BaseJob(HttpVerb::Get, u"GetDisplayNameJob"_s,
makePath("/_matrix/client/v3", "/profile/", userId, "/displayname"), false)
makePath("/_matrix/client/v3", "/profile/", userId, "/displayname"))
{}

SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QUrl& avatarUrl)
Expand All @@ -41,7 +41,7 @@ QUrl GetAvatarUrlJob::makeRequestUrl(const HomeserverData& hsData, const QString

GetAvatarUrlJob::GetAvatarUrlJob(const QString& userId)
: BaseJob(HttpVerb::Get, u"GetAvatarUrlJob"_s,
makePath("/_matrix/client/v3", "/profile/", userId, "/avatar_url"), false)
makePath("/_matrix/client/v3", "/profile/", userId, "/avatar_url"))
{}

QUrl GetUserProfileJob::makeRequestUrl(const HomeserverData& hsData, const QString& userId)
Expand All @@ -51,5 +51,5 @@ QUrl GetUserProfileJob::makeRequestUrl(const HomeserverData& hsData, const QStri

GetUserProfileJob::GetUserProfileJob(const QString& userId)
: BaseJob(HttpVerb::Get, u"GetUserProfileJob"_s,
makePath("/_matrix/client/v3", "/profile/", userId), false)
makePath("/_matrix/client/v3", "/profile/", userId))
{}
3 changes: 0 additions & 3 deletions Quotient/eventitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ using namespace Quotient;

void PendingEventItem::setFileUploaded(const FileSourceInfo& uploadedFileData)
{
// TODO: eventually we might introduce hasFileContent to RoomEvent,
// and unify the code below.
if (auto* rme = getAs<RoomMessageEvent>()) {
Q_ASSERT(rme->hasFileContent());
auto fc = rme->fileContent();
fc->source = uploadedFileData;
rme->setContent(std::move(fc));
}
if (auto* rae = getAs<RoomAvatarEvent>()) {
Q_ASSERT(rae->content().fileInfo());
rae->editContent([&uploadedFileData](EventContent::FileInfo& fi) {
fi.source = uploadedFileData;
});
Expand Down
24 changes: 11 additions & 13 deletions Quotient/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,17 @@ class EventTemplate : public BaseEventT {
/// To retrieve the value the getter uses a JSON key name that corresponds to
/// its own (getter's) name but written in snake_case. \p GetterName_ must be
/// in camelCase, no quotes (an identifier, not a literal).
#define DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_, \
JsonKey_) \
constexpr inline auto Name_##ContentKey = JsonKey_##_L1; \
class QUOTIENT_API Name_ \
: public EventTemplate< \
Name_, Base_, \
EventContent::SingleKeyValue<ValueType_, Name_##ContentKey>> { \
public: \
QUO_EVENT(Name_, TypeId_) \
using value_type = ValueType_; \
using EventTemplate::EventTemplate; \
QUO_CONTENT_GETTER_X(ValueType_, GetterName_, Name_##ContentKey) \
}; \
#define DEFINE_SIMPLE_EVENT(Name_, Base_, TypeId_, ValueType_, GetterName_, JsonKey_) \
constexpr inline auto Name_##ContentKey = JsonKey_##_L1; \
class QUOTIENT_API Name_ \
: public ::Quotient::EventTemplate< \
Name_, Base_, EventContent::SingleKeyValue<ValueType_, Name_##ContentKey>> { \
public: \
QUO_EVENT(Name_, TypeId_) \
using value_type = ValueType_; \
using EventTemplate::EventTemplate; \
QUO_CONTENT_GETTER_X(ValueType_, GetterName_, Name_##ContentKey) \
}; \
// End of macro

// === is<>(), eventCast<>() and switchOnType<>() ===
Expand Down
67 changes: 28 additions & 39 deletions Quotient/events/eventcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class QUOTIENT_API Base {

QJsonObject toJson() const;

virtual QMimeType type() const = 0;

public:
QJsonObject originalJson;

Expand All @@ -50,8 +52,7 @@ class QUOTIENT_API Base {
// but specific aggregation structure is altered. See doc comments to
// each type for the list of available attributes.

// A quick classes inheritance structure follows (the definitions are
// spread across eventcontent.h and roommessageevent.h):
// A quick class inheritance structure follows:
// UrlBasedContent<InfoT> : InfoT + thumbnail data
// PlayableContent<InfoT> : + duration attribute
// FileInfo
Expand All @@ -63,27 +64,22 @@ class QUOTIENT_API Base {

//! \brief Mix-in class representing `info` subobject in content JSON
//!
//! This is one of base classes for content types that deal with files or
//! URLs. It stores the file metadata attributes, such as size, MIME type
//! etc. found in the `content/info` subobject of event JSON payloads.
//! Actual content classes derive from this class _and_ TypedBase that
//! provides a polymorphic interface to access data in the mix-in. FileInfo
//! (as well as ImageInfo, that adds image size to the metadata) is NOT
//! polymorphic and is used in a non-polymorphic way to store thumbnail
//! metadata (in a separate instance), next to the metadata on the file
//! itself.
//! This is one of base classes for content types that deal with files or URLs. It stores
//! file metadata attributes, such as size, MIME type etc. found in the `content/info` subobject of
//! event JSON payloads. Actual content classes derive from this class _and_ Base that provides
//! a polymorphic interface to access data in the mix-in. FileInfo (as well as ImageInfo, that adds
//! image size to the metadata) is NOT polymorphic and is used in a non-polymorphic way to store
//! thumbnail metadata (in a separate instance), next to the metadata on the file itself.
//!
//! If you need to make a new _content_ (not info) class based on files/URLs
//! take UrlBasedContent as the example, i.e.:
//! 1. Double-inherit from this class (or ImageInfo) and TypedBase.
//! 2. Provide a constructor from QJsonObject that will pass the `info`
//! subobject (not the whole content JSON) down to FileInfo/ImageInfo.
//! 3. Override fillJson() to customise the JSON export logic. Make sure
//! to call toInfoJson() from it to produce the payload for the `info`
//! subobject in the JSON payload.
//! If you need to make a new _content_ (not info) class based on files/URLs take UrlBasedContent
//! as the example, i.e.:
//! 1. Double-inherit from this class (or ImageInfo) and Base.
//! 2. Provide a constructor from QJsonObject that will pass the `info` subobject (not the whole
//! content JSON) down to FileInfo/ImageInfo.
//! 3. Override fillJson() to customise the JSON export logic. Make sure to call toInfoJson()
//! from it to produce the payload for the `info` subobject in the JSON payload.
//!
//! \sa ImageInfo, FileContent, ImageContent, AudioContent, VideoContent,
//! UrlBasedContent
//! \sa ImageInfo, FileContent, ImageContent, AudioContent, VideoContent, UrlBasedContent
struct QUOTIENT_API FileInfo {
FileInfo() = default;
//! \brief Construct from a QFileInfo object
Expand Down Expand Up @@ -149,23 +145,18 @@ struct QUOTIENT_API Thumbnail : public ImageInfo {
void dumpTo(QJsonObject& infoJson) const;
};

class QUOTIENT_API TypedBase : public Base {
//! The base for all file-based content classes
class QUOTIENT_API FileContentBase : public Base {
public:
virtual QMimeType type() const = 0;
virtual const FileInfo* fileInfo() const { return nullptr; }
virtual FileInfo* fileInfo() { return nullptr; }
virtual const Thumbnail* thumbnailInfo() const { return nullptr; }

protected:
explicit TypedBase(QJsonObject o = {}) : Base(std::move(o)) {}
using Base::Base;
virtual QUrl url() const = 0;
};

//! \brief Rich text content for m.text, m.emote, m.notice
//!
//! Available fields: mimeType, body. The body can be either rich text
//! or plain text, depending on what mimeType specifies.
class QUOTIENT_API TextContent : public TypedBase {
class QUOTIENT_API TextContent : public Base {
public:
TextContent(QString text, const QString& contentType);
explicit TextContent(const QJsonObject& json);
Expand All @@ -190,7 +181,7 @@ class QUOTIENT_API TextContent : public TypedBase {
//! - thumbnail.payloadSize
//! - thumbnail.mimeType
//! - thumbnail.imageSize
class QUOTIENT_API LocationContent : public TypedBase {
class QUOTIENT_API LocationContent : public Base {
public:
LocationContent(const QString& geoUri, const Thumbnail& thumbnail = {});
explicit LocationContent(const QJsonObject& json);
Expand All @@ -212,13 +203,13 @@ class QUOTIENT_API LocationContent : public TypedBase {
//! the top-level JSON object and the rest of information from the `info`
//! subobject, as defined by the parameter type.
//! \tparam InfoT base info class - FileInfo or ImageInfo
template <class InfoT>
class UrlBasedContent : public TypedBase, public InfoT {
template <std::derived_from<FileInfo> InfoT>
class UrlBasedContent : public FileContentBase, public InfoT {
public:
using InfoT::InfoT;
explicit UrlBasedContent(const QJsonObject& json)
: TypedBase(json)
, InfoT(QUrl(json["url"_L1].toString()), json["info"_L1].toObject(),
: FileContentBase(json)
, InfoT(fromJson<QUrl>(json["url"_L1]), json["info"_L1].toObject(),
json["filename"_L1].toString())
, thumbnail(FileInfo::originalInfoJson)
{
Expand All @@ -231,9 +222,7 @@ class UrlBasedContent : public TypedBase, public InfoT {
}

QMimeType type() const override { return InfoT::mimeType; }
const FileInfo* fileInfo() const override { return this; }
FileInfo* fileInfo() override { return this; }
const Thumbnail* thumbnailInfo() const override { return &thumbnail; }
QUrl url() const override { return InfoT::url(); }

public:
Thumbnail thumbnail;
Expand Down Expand Up @@ -346,4 +335,4 @@ using VideoContent = PlayableContent<ImageInfo>;
//! - imageSize
using AudioContent = PlayableContent<FileInfo>;
} // namespace Quotient::EventContent
Q_DECLARE_METATYPE(const Quotient::EventContent::TypedBase*)
Q_DECLARE_METATYPE(const Quotient::EventContent::Base*)
Loading

0 comments on commit b07afdc

Please sign in to comment.