libQuotient
A Qt library for building matrix clients
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 
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  void setOriginalEvent(event_ptr_tt<EncryptedEvent>&& originalEvent);
55  const EncryptedEvent* originalEvent() const { return _originalEvent.get(); }
56  const QJsonObject encryptedJson() const;
57 
58 protected:
59  explicit RoomEvent(const QJsonObject& json);
60  void dumpTo(QDebug dbg) const override;
61 
62 private:
63  // RedactionEvent is an incomplete type here so we cannot inline
64  // constructors using it and also destructors (with 'using', in particular).
65  event_ptr_tt<RedactionEvent> _redactedBecause;
66 
67  event_ptr_tt<EncryptedEvent> _originalEvent;
68 };
69 using RoomEventPtr = event_ptr_tt<RoomEvent>;
70 using RoomEvents = EventsArray<RoomEvent>;
71 using RoomEventsRange = std::ranges::subrange<RoomEvents::iterator>;
72 
73 } // namespace Quotient
74 Q_DECLARE_METATYPE(Quotient::RoomEvent*)
75 Q_DECLARE_METATYPE(const Quotient::RoomEvent*)