libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
roommessageevent.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2015 Felix Rohrbach <kde@fxrh.de>
2
// SPDX-FileCopyrightText: 2016 Kitsune Ral <Kitsune-Ral@users.sf.net>
3
// SPDX-FileCopyrightText: 2017 Roman Plášil <me@rplasil.name>
4
// SPDX-License-Identifier: LGPL-2.1-or-later
5
6
#
pragma
once
7
8
#
include
"eventcontent.h"
9
#
include
"roomevent.h"
10
11
class
QFileInfo;
12
13
namespace
Quotient
{
14
15
/**
16
* The event class corresponding to m.room.message events
17
*/
18
class
QUOTIENT_API
RoomMessageEvent
:
public
RoomEvent
{
19
Q_GADGET
20
public
:
21
QUO_EVENT
(
RoomMessageEvent
,
"m.room.message"
)
22
23
enum
class
MsgType
{
24
Text
,
25
Emote
,
26
Notice
,
27
Image
,
28
File
,
29
Location
,
30
Video
,
31
Audio
,
32
Unknown
33
};
34
35
RoomMessageEvent
(
const
QString
&
plainBody
,
const
QString
&
jsonMsgType
,
36
std
::
unique_ptr
<
EventContent
::
Base
>
content
=
nullptr
,
37
const
std
::
optional
<
EventRelation
>&
relatesTo
=
std
::
nullopt
);
38
explicit
RoomMessageEvent
(
const
QString
&
plainBody
,
MsgType
msgType
=
MsgType
::
Text
,
39
std
::
unique_ptr
<
EventContent
::
Base
>
content
=
nullptr
,
40
const
std
::
optional
<
EventRelation
>&
relatesTo
=
std
::
nullopt
);
41
42
explicit
RoomMessageEvent
(
const
QJsonObject
&
obj
);
43
44
MsgType
msgtype
()
const
;
45
QString
rawMsgtype
()
const
;
46
QString
plainBody
()
const
;
47
48
//! \brief Load event content from the event JSON
49
//!
50
//! \warning The result must be checked for nullptr as an event with just a plainBody
51
//! will not have a content object.
52
//! \warning Since libQuotient 0.9, the returned value has changed from a C pointer (TypedBase*)
53
//! to `std::unique_ptr<>` because the deserialised content object is no more stored
54
//! inside the event. The calling code must either store the entire returned value
55
//! in a variable or copy/move away the needed field from the returned value;
56
//! a reference or a pointer to a field will become dangling at the statement end.
57
//!
58
//! \return an event content object if the event has content, nullptr otherwise.
59
std
::
unique_ptr
<
EventContent
::
Base
>
content
()
const
;
60
61
//! Update the message JSON with the given content
62
void
setContent
(
std
::
unique_ptr
<
EventContent
::
Base
>
content
);
63
64
//! \brief Determine whether the message has content/attachment of a specified type
65
//!
66
//! \return true, if the message has type and content corresponding to \p ContentT (e.g.
67
//! `m.file` or `m.audio` for FileContent); false otherwise
68
template
<
std
::
derived_from
<
EventContent
::
Base
>
ContentT
>
69
bool
has
()
const
{
return
false
; }
70
71
//! \brief Get the message content and try to cast it to the specified type
72
//!
73
//! \return A pointer to the object of the requested type if the event has content of this type;
74
//! nullptr, if the event has no content or the content cannot be cast to this type
75
template
<
std
::
derived_from
<
EventContent
::
Base
>
ContentT
>
76
std
::
unique_ptr
<
ContentT
>
get
()
const
77
{
78
return
has
<
ContentT
>()
79
?
std
::
unique_ptr
<
ContentT
>(
static_cast
<
ContentT
*>(
content
().
release
()))
80
:
nullptr
;
81
}
82
83
QMimeType
mimeType
()
const
;
84
85
//! \brief Determine whether the message has a thumbnail
86
//!
87
//! \return true, if the message has a data structure corresponding to
88
//! a thumbnail (the message type may be one for visual content,
89
//! such as m.image, or non-visual, i.e. m.file or m.location);
90
//! false otherwise
91
bool
hasThumbnail
()
const
;
92
93
//! Retrieve a thumbnail from the message event
94
EventContent
::
Thumbnail
getThumbnail
()
const
;
95
96
//! \brief The upstream event ID for the relation.
97
//!
98
//! \warning If your client is not thread aware use replyEventId() as this will
99
//! return the fallback reply ID so you can treat a threaded reply like a normal one.
100
//!
101
//! \warning If your client is thread aware use threadRootEventId() to get the
102
//! thread root ID as this will return an empty string on the root event.
103
//! threadRootEventId() will return the root messages ID on itself.
104
QString
upstreamEventId
()
const
;
105
106
//! \brief Obtain id of an event replaced by the current one
107
//! \sa RoomEvent::isReplaced, RoomEvent::replacedBy
108
QString
replacedEvent
()
const
;
109
110
//! \brief Determine whether the event has been replaced
111
//!
112
//! \return true if this event has been overridden by another event
113
//! with `"rel_type": "m.replace"`; false otherwise
114
bool
isReplaced
()
const
;
115
116
QString
replacedBy
()
const
;
117
118
QString
fileNameToDownload
()
const
;
119
120
void
updateFileSourceInfo
(
const
FileSourceInfo
&
fsi
);
121
122
static
QString
rawMsgTypeForUrl
(
const
QUrl
&
url
);
123
static
QString
rawMsgTypeForFile
(
const
QFileInfo
&
fi
);
124
125
private
:
126
// FIXME: should it really be static?
127
static
QJsonObject
assembleContentJson
(
const
QString
&
plainBody
,
const
QString
&
jsonMsgType
,
128
std
::
unique_ptr
<
EventContent
::
Base
>
content
,
129
const
std
::
optional
<
EventRelation
>&
relatesTo
);
130
131
Q_ENUM
(
MsgType
)
132
};
133
134
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
TextContent
>()
const
;
135
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
LocationContent
>()
const
;
136
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
FileContentBase
>()
const
;
137
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
FileContent
>()
const
;
138
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
ImageContent
>()
const
;
139
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
AudioContent
>()
const
;
140
template
<>
QUOTIENT_API
bool
RoomMessageEvent
::
has
<
EventContent
::
VideoContent
>()
const
;
141
142
using
MessageEventType
=
RoomMessageEvent
::
MsgType
;
143
}
// namespace Quotient
Quotient::RoomMessageEvent
Definition
roommessageevent.h:18
QUO_EVENT
#define QUO_EVENT(CppType_, MatrixType_)
Supply event metatype information in (specific) event types.
Definition
event.h:428
Quotient
Definition
accountregistry.h:13
QUOTIENT_API
#define QUOTIENT_API
Definition
quotient_export.h:22
Quotient
events
roommessageevent.h
Generated by
1.9.8