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 | |
10 | namespace Quotient { |
11 | class RedactionEvent; |
12 | class EncryptedEvent; |
13 | |
14 | // That check could look into Event and find most stuff already deleted... |
15 | // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) |
16 | class QUOTIENT_API RoomEvent : public Event { |
17 | public: |
18 | QUO_BASE_EVENT(RoomEvent, Event) |
19 | |
20 | ~RoomEvent() override; // Don't inline this - see the private section |
21 | |
22 | QString id() const; |
23 | QDateTime originTimestamp() const; |
24 | QString roomId() const; |
25 | QString senderId() const; |
26 | bool isRedacted() const { return bool(_redactedBecause); } |
27 | const event_ptr_tt<RedactionEvent>& redactedBecause() const |
28 | { |
29 | return _redactedBecause; |
30 | } |
31 | QString redactionReason() const; |
32 | QString transactionId() const; |
33 | QString stateKey() const; |
34 | |
35 | //! \brief Fill the pending event object with the room id |
36 | void setRoomId(const QString& roomId); |
37 | //! \brief Fill the pending event object with the sender id |
38 | void setSender(const QString& senderId); |
39 | //! \brief Fill the pending event object with the transaction id |
40 | //! \param txnId - transaction id, normally obtained from |
41 | //! Connection::generateTxnId() |
42 | void setTransactionId(const QString& txnId); |
43 | |
44 | //! \brief Add an event id to locally created events after they are sent |
45 | //! |
46 | //! When a new event is created locally, it has no id; the homeserver |
47 | //! assigns it once the event is sent. This function allows to add the id |
48 | //! once the confirmation from the server is received. There should be no id |
49 | //! set previously in the event. It's the responsibility of the code calling |
50 | //! addId() to notify clients about the change; there's no signal or |
51 | //! callback for that in RoomEvent. |
52 | void addId(const QString& newId); |
53 | |
54 | #ifdef Quotient_E2EE_ENABLED |
55 | void setOriginalEvent(event_ptr_tt<EncryptedEvent>&& originalEvent); |
56 | const EncryptedEvent* originalEvent() const { return _originalEvent.get(); } |
57 | const QJsonObject encryptedJson() const; |
58 | #endif |
59 | |
60 | protected: |
61 | explicit RoomEvent(const QJsonObject& json); |
62 | void dumpTo(QDebug dbg) const override; |
63 | |
64 | private: |
65 | // RedactionEvent is an incomplete type here so we cannot inline |
66 | // constructors using it and also destructors (with 'using', in particular). |
67 | event_ptr_tt<RedactionEvent> _redactedBecause; |
68 | |
69 | #ifdef Quotient_E2EE_ENABLED |
70 | event_ptr_tt<EncryptedEvent> _originalEvent; |
71 | #endif |
72 | }; |
73 | using RoomEventPtr = event_ptr_tt<RoomEvent>; |
74 | using RoomEvents = EventsArray<RoomEvent>; |
75 | using RoomEventsRange = Range<RoomEvents>; |
76 | |
77 | } // namespace Quotient |
78 | Q_DECLARE_METATYPE(Quotient::RoomEvent*) |
79 | Q_DECLARE_METATYPE(const Quotient::RoomEvent*) |
80 | |