libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
roomevent.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "event.h"
7
8#include <QtCore/QDateTime>
9
10namespace Quotient {
11
12constexpr inline auto EventIdKey = "event_id"_L1;
13constexpr inline auto RoomIdKey = "room_id"_L1;
14constexpr inline auto StateKeyKey = "state_key"_L1;
15constexpr inline auto RedactedCauseKey = "redacted_because"_L1;
16
17class RedactionEvent;
18class EncryptedEvent;
19
20// That check could look into Event and find most stuff already deleted...
21// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
22class QUOTIENT_API RoomEvent : public Event {
23public:
24 QUO_BASE_EVENT(RoomEvent, Event)
25
26 ~RoomEvent() override; // Don't inline this - see the private section
27
28 //! \brief A convenience function to get a display string for an event ID.
29 //! \return id() if the event id is not empty, otherwise transactionId();
30 //! this is useful to deal with pending and normal events uniformly.
31 //! \sa id(), transactionId()
32 QString displayId() const;
33
34 //! The event_id JSON value for the event.
35 QString id() const;
36
37 QDateTime originTimestamp() const;
38 QString roomId() const;
39 QString senderId() const;
40 bool isRedacted() const { return bool(_redactedBecause); }
41 const event_ptr_tt<RedactionEvent>& redactedBecause() const
42 {
43 return _redactedBecause;
44 }
45 QString redactionReason() const;
46
47 //! The transaction_id JSON value for the event.
48 QString transactionId() const;
49
50 // State events are special in Matrix; so isStateEvent() and stateKey() are here,
51 // as an exception. For other event types (including base types), Event::is<>() and
52 // Quotient::is<>() should be used
53
54 bool isStateEvent() const;
55
56 QString stateKey() const;
57
58 //! \brief Fill the pending event object with the room id
59 void setRoomId(const QString& roomId);
60 //! \brief Fill the pending event object with the sender id
61 void setSender(const QString& senderId);
62 //! \brief Fill the pending event object with the transaction id
63 //! \param txnId - transaction id, normally obtained from
64 //! Connection::generateTxnId()
65 void setTransactionId(const QString& txnId);
66
67 //! \brief Add an event id to locally created events after they are sent
68 //!
69 //! When a new event is created locally, it has no id; the homeserver
70 //! assigns it once the event is sent. This function allows to add the id
71 //! once the confirmation from the server is received. There should be no id
72 //! set previously in the event. It's the responsibility of the code calling
73 //! addId() to notify clients about the change; there's no signal or
74 //! callback for that in RoomEvent.
75 void addId(const QString& newId);
76
77 void setOriginalEvent(event_ptr_tt<EncryptedEvent>&& originalEvent);
78 const EncryptedEvent* originalEvent() const { return _originalEvent.get(); }
79 const QJsonObject encryptedJson() const;
80
81protected:
82 explicit RoomEvent(const QJsonObject& json);
83 void dumpTo(QDebug dbg) const override;
84
85private:
86 // RedactionEvent is an incomplete type here so we cannot inline
87 // constructors using it and also destructors (with 'using', in particular).
88 event_ptr_tt<RedactionEvent> _redactedBecause;
89
90 event_ptr_tt<EncryptedEvent> _originalEvent;
91};
92using RoomEventPtr = event_ptr_tt<RoomEvent>;
93using RoomEvents = EventsArray<RoomEvent>;
94using RoomEventsRange = std::ranges::subrange<RoomEvents::iterator>;
95
96//! \brief Determine whether a given event type is that of a state event
97QUOTIENT_API bool isStateEvent(const QString& eventTypeId);
98
99} // namespace Quotient
100Q_DECLARE_METATYPE(Quotient::RoomEvent*)
101Q_DECLARE_METATYPE(const Quotient::RoomEvent*)
#define QUO_BASE_EVENT(CppType_, BaseCppType_,...)
Supply event metatype information in base event types.
Definition event.h:408
#define QUOTIENT_API