From f6740316dfcdb287b019b4258df2213c31965d42 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 26 Dec 2018 19:36:00 +0900 Subject: PendingEventItem: add FileUploaded status and setFileUploaded helper function --- lib/eventitem.cpp | 26 ++++++++++++++++++++++++++ lib/eventitem.h | 15 ++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/eventitem.cpp b/lib/eventitem.cpp index 79ef769c..8ec3fe48 100644 --- a/lib/eventitem.cpp +++ b/lib/eventitem.cpp @@ -17,3 +17,29 @@ */ #include "eventitem.h" + +#include "events/roommessageevent.h" +#include "events/roomavatarevent.h" + +using namespace QMatrixClient; + +void PendingEventItem::setFileUploaded(const QUrl& remoteUrl) +{ + // TODO: eventually we might introduce hasFileContent to RoomEvent, + // and unify the code below. + if (auto* rme = getAs()) + { + Q_ASSERT(rme->hasFileContent()); + rme->editContent([remoteUrl] (EventContent::TypedBase& ec) { + ec.fileInfo()->url = remoteUrl; + }); + } + if (auto* rae = getAs()) + { + Q_ASSERT(rae->content().fileInfo()); + rae->editContent([remoteUrl] (EventContent::FileInfo& fi) { + fi.url = remoteUrl; + }); + } + setStatus(EventStatus::FileUploaded); +} diff --git a/lib/eventitem.h b/lib/eventitem.h index 5f1d10c9..36ed2132 100644 --- a/lib/eventitem.h +++ b/lib/eventitem.h @@ -33,16 +33,17 @@ namespace QMatrixClient /** Special marks an event can assume * * This is used to hint at a special status of some events in UI. - * Most status values are mutually exclusive. + * All values except Redacted and Hidden are mutually exclusive. */ enum Code { Normal = 0x0, //< No special designation Submitted = 0x01, //< The event has just been submitted for sending - Departed = 0x02, //< The event has left the client - ReachedServer = 0x03, //< The server has received the event - SendingFailed = 0x04, //< The server could not receive the event + FileUploaded = 0x02, //< The file attached to the event has been uploaded to the server + Departed = 0x03, //< The event has left the client + ReachedServer = 0x04, //< The server has received the event + SendingFailed = 0x05, //< The server could not receive the event Redacted = 0x08, //< The event has been redacted - Hidden = 0x10, //< The event should be hidden + Hidden = 0x10, //< The event should not be shown in the timeline }; Q_DECLARE_FLAGS(Status, Code) Q_FLAG(Status) @@ -70,6 +71,9 @@ namespace QMatrixClient return std::exchange(evt, move(other)); } + protected: + template + EventT* getAs() { return eventCast(evt); } private: RoomEventPtr evt; }; @@ -116,6 +120,7 @@ namespace QMatrixClient QString annotation() const { return _annotation; } void setDeparted() { setStatus(EventStatus::Departed); } + void setFileUploaded(const QUrl& remoteUrl); void setReachedServer(const QString& eventId) { setStatus(EventStatus::ReachedServer); -- cgit v1.2.3