blob: 3fafecfd4cff5dee002150f6a9cfa0f6d89e1039 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/******************************************************************************
* SPDX-FileCopyrightText: 2018 Kitsune Ral <kitsune-ral@users.sf.net>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include "event.h"
#include <QtCore/QDateTime>
namespace Quotient {
class RedactionEvent;
/** This class corresponds to m.room.* events */
class RoomEvent : public Event {
Q_GADGET
Q_PROPERTY(QString id READ id)
Q_PROPERTY(QDateTime timestamp READ timestamp CONSTANT)
Q_PROPERTY(QString roomId READ roomId CONSTANT)
Q_PROPERTY(QString senderId READ senderId CONSTANT)
Q_PROPERTY(QString redactionReason READ redactionReason)
Q_PROPERTY(bool isRedacted READ isRedacted)
Q_PROPERTY(QString transactionId READ transactionId WRITE setTransactionId)
public:
using factory_t = EventFactory<RoomEvent>;
// RedactionEvent is an incomplete type here so we cannot inline
// constructors and destructors and we cannot use 'using'.
RoomEvent(Type type, event_mtype_t matrixType,
const QJsonObject& contentJson = {});
RoomEvent(Type type, const QJsonObject& json);
~RoomEvent() override;
QString id() const;
QDateTime originTimestamp() const;
[[deprecated("Use originTimestamp()")]] QDateTime timestamp() const {
return originTimestamp();
}
QString roomId() const;
QString senderId() const;
bool isReplaced() const;
QString replacedBy() const;
bool isRedacted() const { return bool(_redactedBecause); }
const event_ptr_tt<RedactionEvent>& redactedBecause() const
{
return _redactedBecause;
}
QString redactionReason() const;
QString transactionId() const;
QString stateKey() const;
void setRoomId(const QString& roomId);
void setSender(const QString& senderId);
/**
* Sets the transaction id for locally created events. This should be
* done before the event is exposed to any code using the respective
* Q_PROPERTY.
*
* \param txnId - transaction id, normally obtained from
* Connection::generateTxnId()
*/
void setTransactionId(const QString& txnId);
/**
* Sets event id for locally created events
*
* When a new event is created locally, it has no server id yet.
* This function allows to add the id once the confirmation from
* the server is received. There should be no id set previously
* in the event. It's the responsibility of the code calling addId()
* to notify clients that use Q_PROPERTY(id) about its change
*/
void addId(const QString& newId);
protected:
void dumpTo(QDebug dbg) const override;
private:
event_ptr_tt<RedactionEvent> _redactedBecause;
};
using RoomEventPtr = event_ptr_tt<RoomEvent>;
using RoomEvents = EventsArray<RoomEvent>;
using RoomEventsRange = Range<RoomEvents>;
class CallEventBase : public RoomEvent {
public:
CallEventBase(Type type, event_mtype_t matrixType, const QString& callId,
int version, const QJsonObject& contentJson = {});
CallEventBase(Type type, const QJsonObject& json);
~CallEventBase() override = default;
bool isCallEvent() const override { return true; }
QString callId() const { return content<QString>("call_id"_ls); }
int version() const { return content<int>("version"_ls); }
};
} // namespace Quotient
Q_DECLARE_METATYPE(Quotient::RoomEvent*)
Q_DECLARE_METATYPE(const Quotient::RoomEvent*)
|