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
11class QFileInfo;
12
13namespace Quotient {
14
15/**
16 * The event class corresponding to m.room.message events
17 */
20public:
21 QUO_EVENT(RoomMessageEvent, "m.room.message")
22
23 enum class MsgType {
24 Text,
25 Emote,
26 Notice,
27 Image,
28 File,
30 Video,
31 Audio,
33 };
34
41
43
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.
60
61 //! Update the message JSON with the given 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
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
77 {
78 return has<ContentT>()
79 ? std::unique_ptr<ContentT>(static_cast<ContentT*>(content().release()))
80 : nullptr;
81 }
82
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
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.
105
106 //! \brief Obtain id of an event replaced by the current one
107 //! \sa RoomEvent::isReplaced, RoomEvent::replacedBy
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
117
118 //! \brief Determine whether the event is part of a thread.
119 //!
120 //! \return true if this event is part of a thread, i.e. it has
121 //! `"rel_type": "m.thread"` or `"m.relations": { "m.thread": {}}`;
122 //! false otherwise.
123 bool isThreaded() const;
124
125 //! \brief The event ID for the thread root event.
126 //!
127 //! \note This will return the ID of the event if it is the thread root.
128 //!
129 //! \note If the event is the thread root event and has not been updated with the server-side
130 //! the function will return an empty string as we can't tell if the message
131 //! is threaded.
132 //!
133 //! \return The event ID of the thread root if threaded, an empty string otherwise.
135
137
139
142
143private:
144 // FIXME: should it really be static?
148
150};
151
159
161} // namespace Quotient
#define QUO_EVENT(CppType_, MatrixType_)
Supply event metatype information in (specific) event types.
Definition event.h:432
#define QUOTIENT_API