6 #include "events/roomevent.h"
7 #include "events/filesourceinfo.h"
9 #include <QtCore/QPromise>
10 #include <QtCore/QFuture>
17 namespace EventStatus {
25 enum Code : uint16_t {
42 using value_type = RoomEvent;
44 explicit EventItemBase(RoomEventPtr&& e) : evt(std::move(e))
49 const RoomEvent* event()
const {
return std::to_address(evt); }
50 const RoomEvent* get()
const {
return event(); }
51 template <EventClass<RoomEvent> EventT>
52 const EventT* viewAs()
const
54 return eventCast<
const EventT>(evt);
56 const RoomEventPtr& operator->()
const {
return evt; }
57 const RoomEvent& operator*()
const {
return *evt; }
60 RoomEventPtr replaceEvent(RoomEventPtr&& other)
62 return std::exchange(evt, std::move(other));
66 void setUserData(std::any userData) { data = std::move(userData); }
68 const std::any& userdata()
const {
return data; }
69 std::any& userData() {
return data; }
72 template <EventClass<RoomEvent> EventT>
75 return eventCast<EventT>(evt);
89 TimelineItem(RoomEventPtr&& e, index_t number)
90 : EventItemBase(std::move(e)), idx(number)
93 index_t index()
const {
return idx; }
101 using future_type = QFuture<std::reference_wrapper<
const RoomEvent>>;
103 explicit PendingEventItem(RoomEventPtr&& e) : EventItemBase(std::move(e))
105 _promise.setProgressRange(0, 5);
108 EventStatus::Code deliveryStatus()
const {
return _status; }
109 QDateTime lastUpdated()
const {
return _lastUpdated; }
110 QString annotation()
const {
return _annotation; }
112 void setDeparted() { setStatus(EventStatus::Departed); }
113 void setFileUploaded(
const FileSourceInfo &uploadedFileData);
114 void setReachedServer(
const QString& eventId)
116 setStatus(EventStatus::ReachedServer);
117 (*
this)->addId(eventId);
119 void setMerged(
const RoomEvent& intoEvent)
121 _promise.addResult(intoEvent);
124 void setSendingFailed(QString errorText)
126 setStatus(EventStatus::SendingFailed);
127 _annotation = std::move(errorText);
129 void resetStatus() { setStatus(EventStatus::Submitted); }
136 future_type whenMerged()
const {
return _promise.future(); }
141 EventStatus::Code _status = EventStatus::Submitted;
142 QDateTime _lastUpdated = QDateTime::currentDateTimeUtc();
144 QPromise<std::reference_wrapper<
const RoomEvent>> _promise;
146 void setStatus(EventStatus::Code status)
149 _lastUpdated = QDateTime::currentDateTimeUtc();
152 _promise.setProgressValue(_status);
156 inline QDebug& operator<<(QDebug& d,
const TimelineItem& ti)
158 QDebugStateSaver dss(d);
159 d.nospace() <<
"(" << ti.index() <<
"|" << ti->id() <<
")";