aboutsummaryrefslogtreecommitdiff
path: root/lib/eventitem.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
commit63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408 (patch)
tree2552f5049a6ef7ba0034483b25ca4ab33d1fcb13 /lib/eventitem.h
parente083d327e6f6581210f8d077d8bbe1151e81e82c (diff)
parent93f0c8fe89f448d1d58caa757573f17102369471 (diff)
downloadlibquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.tar.gz
libquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.zip
Merge branch 'master' into clang-format
# Conflicts: # CMakeLists.txt # lib/avatar.cpp # lib/connection.cpp # lib/connection.h # lib/connectiondata.cpp # lib/csapi/account-data.cpp # lib/csapi/account-data.h # lib/csapi/capabilities.cpp # lib/csapi/capabilities.h # lib/csapi/content-repo.cpp # lib/csapi/create_room.cpp # lib/csapi/filter.cpp # lib/csapi/joining.cpp # lib/csapi/keys.cpp # lib/csapi/list_joined_rooms.cpp # lib/csapi/notifications.cpp # lib/csapi/openid.cpp # lib/csapi/presence.cpp # lib/csapi/pushrules.cpp # lib/csapi/registration.cpp # lib/csapi/room_upgrades.cpp # lib/csapi/room_upgrades.h # lib/csapi/search.cpp # lib/csapi/users.cpp # lib/csapi/versions.cpp # lib/csapi/whoami.cpp # lib/csapi/{{base}}.cpp.mustache # lib/events/accountdataevents.h # lib/events/eventcontent.h # lib/events/roommemberevent.cpp # lib/events/stateevent.cpp # lib/jobs/basejob.cpp # lib/jobs/basejob.h # lib/networkaccessmanager.cpp # lib/networksettings.cpp # lib/room.cpp # lib/room.h # lib/settings.cpp # lib/settings.h # lib/syncdata.cpp # lib/user.cpp # lib/user.h # lib/util.cpp
Diffstat (limited to 'lib/eventitem.h')
-rw-r--r--lib/eventitem.h238
1 files changed, 121 insertions, 117 deletions
diff --git a/lib/eventitem.h b/lib/eventitem.h
index 8b863d67..58f5479c 100644
--- a/lib/eventitem.h
+++ b/lib/eventitem.h
@@ -22,140 +22,144 @@
#include <utility>
-namespace QMatrixClient {
- class StateEventBase;
-
- class EventStatus
+namespace QMatrixClient
+{
+class StateEventBase;
+
+class EventStatus
+{
+ Q_GADGET
+public:
+ /** Special marks an event can assume
+ *
+ * This is used to hint at a special status of some events in UI.
+ * All values except Redacted and Hidden are mutually exclusive.
+ */
+ enum Code
{
- Q_GADGET
- public:
- /** Special marks an event can assume
- *
- * This is used to hint at a special status of some events in UI.
- * 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
- 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 not be shown in the timeline
- };
- Q_DECLARE_FLAGS(Status, Code)
- Q_FLAG(Status)
+ Normal = 0x0, //< No special designation
+ Submitted = 0x01, //< The event has just been submitted for sending
+ 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 not be shown in the timeline
};
+ Q_DECLARE_FLAGS(Status, Code)
+ Q_FLAG(Status)
+};
+
+class EventItemBase
+{
+public:
+ explicit EventItemBase(RoomEventPtr&& e)
+ : evt(std::move(e))
+ {
+ Q_ASSERT(evt);
+ }
- class EventItemBase
+ const RoomEvent* event() const { return rawPtr(evt); }
+ const RoomEvent* get() const { return event(); }
+ template <typename EventT>
+ const EventT* viewAs() const
{
- public:
- explicit EventItemBase(RoomEventPtr&& e) : evt(std::move(e))
- {
- Q_ASSERT(evt);
- }
-
- const RoomEvent* event() const { return rawPtr(evt); }
- const RoomEvent* get() const { return event(); }
- template <typename EventT> const EventT* viewAs() const
- {
- return eventCast<const EventT>(evt);
- }
- const RoomEventPtr& operator->() const { return evt; }
- const RoomEvent& operator*() const { return *evt; }
-
- // Used for event redaction
- RoomEventPtr replaceEvent(RoomEventPtr&& other)
- {
- return std::exchange(evt, move(other));
- }
-
- protected:
- template <typename EventT> EventT* getAs()
- {
- return eventCast<EventT>(evt);
- }
-
- private:
- RoomEventPtr evt;
- };
+ return eventCast<const EventT>(evt);
+ }
+ const RoomEventPtr& operator->() const { return evt; }
+ const RoomEvent& operator*() const { return *evt; }
- class TimelineItem : public EventItemBase
+ // Used for event redaction
+ RoomEventPtr replaceEvent(RoomEventPtr&& other)
{
- public:
- // For compatibility with Qt containers, even though we use
- // a std:: container now for the room timeline
- using index_t = int;
+ return std::exchange(evt, move(other));
+ }
- TimelineItem(RoomEventPtr&& e, index_t number)
- : EventItemBase(std::move(e)), idx(number)
- {
- }
+protected:
+ template <typename EventT>
+ EventT* getAs()
+ {
+ return eventCast<EventT>(evt);
+ }
- index_t index() const { return idx; }
+private:
+ RoomEventPtr evt;
+};
+
+class TimelineItem : public EventItemBase
+{
+public:
+ // For compatibility with Qt containers, even though we use
+ // a std:: container now for the room timeline
+ using index_t = int;
+
+ TimelineItem(RoomEventPtr&& e, index_t number)
+ : EventItemBase(std::move(e))
+ , idx(number)
+ {}
+
+ index_t index() const { return idx; }
+
+private:
+ index_t idx;
+};
+
+template <>
+inline const StateEventBase* EventItemBase::viewAs<StateEventBase>() const
+{
+ return evt->isStateEvent() ? weakPtrCast<const StateEventBase>(evt)
+ : nullptr;
+}
- private:
- index_t idx;
- };
+template <>
+inline const CallEventBase* EventItemBase::viewAs<CallEventBase>() const
+{
+ return evt->isCallEvent() ? weakPtrCast<const CallEventBase>(evt) : nullptr;
+}
+
+class PendingEventItem : public EventItemBase
+{
+ Q_GADGET
+public:
+ using EventItemBase::EventItemBase;
+
+ EventStatus::Code deliveryStatus() const { return _status; }
+ QDateTime lastUpdated() const { return _lastUpdated; }
+ QString annotation() const { return _annotation; }
- template <>
- inline const StateEventBase* EventItemBase::viewAs<StateEventBase>() const
+ void setDeparted() { setStatus(EventStatus::Departed); }
+ void setFileUploaded(const QUrl& remoteUrl);
+ void setReachedServer(const QString& eventId)
{
- return evt->isStateEvent() ? weakPtrCast<const StateEventBase>(evt)
- : nullptr;
+ setStatus(EventStatus::ReachedServer);
+ (*this)->addId(eventId);
}
-
- template <>
- inline const CallEventBase* EventItemBase::viewAs<CallEventBase>() const
+ void setSendingFailed(QString errorText)
{
- return evt->isCallEvent() ? weakPtrCast<const CallEventBase>(evt)
- : nullptr;
+ setStatus(EventStatus::SendingFailed);
+ _annotation = std::move(errorText);
}
+ void resetStatus() { setStatus(EventStatus::Submitted); }
- class PendingEventItem : public EventItemBase
- {
- Q_GADGET
- public:
- using EventItemBase::EventItemBase;
-
- EventStatus::Code deliveryStatus() const { return _status; }
- QDateTime lastUpdated() const { return _lastUpdated; }
- QString annotation() const { return _annotation; }
-
- void setDeparted() { setStatus(EventStatus::Departed); }
- void setFileUploaded(const QUrl& remoteUrl);
- void setReachedServer(const QString& eventId)
- {
- setStatus(EventStatus::ReachedServer);
- (*this)->addId(eventId);
- }
- void setSendingFailed(QString errorText)
- {
- setStatus(EventStatus::SendingFailed);
- _annotation = std::move(errorText);
- }
- void resetStatus() { setStatus(EventStatus::Submitted); }
-
- private:
- EventStatus::Code _status = EventStatus::Submitted;
- QDateTime _lastUpdated = QDateTime::currentDateTimeUtc();
- QString _annotation;
-
- void setStatus(EventStatus::Code status)
- {
- _status = status;
- _lastUpdated = QDateTime::currentDateTimeUtc();
- _annotation.clear();
- }
- };
+private:
+ EventStatus::Code _status = EventStatus::Submitted;
+ QDateTime _lastUpdated = QDateTime::currentDateTimeUtc();
+ QString _annotation;
- inline QDebug& operator<<(QDebug& d, const TimelineItem& ti)
+ void setStatus(EventStatus::Code status)
{
- QDebugStateSaver dss(d);
- d.nospace() << "(" << ti.index() << "|" << ti->id() << ")";
- return d;
+ _status = status;
+ _lastUpdated = QDateTime::currentDateTimeUtc();
+ _annotation.clear();
}
+};
+
+inline QDebug& operator<<(QDebug& d, const TimelineItem& ti)
+{
+ QDebugStateSaver dss(d);
+ d.nospace() << "(" << ti.index() << "|" << ti->id() << ")";
+ return d;
}
+} // namespace QMatrixClient
Q_DECLARE_METATYPE(QMatrixClient::EventStatus)