libQuotient
A Qt library for building matrix clients
Quotient::RoomMessageEvent Class Reference

#include <roommessageevent.h>

Inheritance diagram for Quotient::RoomMessageEvent:
Collaboration diagram for Quotient::RoomMessageEvent:

Public Types

enum class  MsgType {
  Text , Emote , Notice , Image ,
  File , Location , Video , Audio ,
  Unknown
}
 

Public Member Functions

 RoomMessageEvent (const QString &plainBody, const QString &jsonMsgType, std::unique_ptr< EventContent::Base > content=nullptr, const std::optional< EventRelation > &relatesTo=std::nullopt)
 
 RoomMessageEvent (const QString &plainBody, MsgType msgType=MsgType::Text, std::unique_ptr< EventContent::Base > content=nullptr, const std::optional< EventRelation > &relatesTo=std::nullopt)
 
 RoomMessageEvent (const QJsonObject &obj)
 
MsgType msgtype () const
 
QString rawMsgtype () const
 
QString plainBody () const
 
std::unique_ptr< EventContent::Basecontent () const
 Load event content from the event JSON. More...
 
void setContent (std::unique_ptr< EventContent::Base > content)
 Update the message JSON with the given content. More...
 
template<std::derived_from< EventContent::Base > ContentT>
bool has () const
 Determine whether the message has content/attachment of a specified type. More...
 
template<std::derived_from< EventContent::Base > ContentT>
std::unique_ptr< ContentT > get () const
 Get the message content and try to cast it to the specified type. More...
 
QMimeType mimeType () const
 
bool hasThumbnail () const
 Determine whether the message has a thumbnail. More...
 
EventContent::Thumbnail getThumbnail () const
 Retrieve a thumbnail from the message event. More...
 
std::optional< EventRelationrelatesTo () const
 The EventRelation for this event. More...
 
QString upstreamEventId () const
 The upstream event ID for the relation. More...
 
QString replacedEvent () const
 Obtain id of an event replaced by the current one. More...
 
bool isReplaced () const
 Determine whether the event has been replaced. More...
 
QString replacedBy () const
 
bool isReply (bool includeFallbacks=false) const
 Determine whether the event is a reply to another message. More...
 
QString replyEventId (bool includeFallbacks=false) const
 The ID for the event being replied to. More...
 
bool isThreaded () const
 Determine whether the event is part of a thread. More...
 
QString threadRootEventId () const
 The event ID for the thread root event. More...
 
QString fileNameToDownload () const
 
void updateFileSourceInfo (const FileSourceInfo &fsi)
 
- Public Member Functions inherited from Quotient::RoomEvent
 ~RoomEvent () override
 
QString displayId () const
 A convenience function to get a display string for an event ID. More...
 
QString id () const
 The event_id JSON value for the event. More...
 
QDateTime originTimestamp () const
 
QString roomId () const
 
QString senderId () const
 
bool isRedacted () const
 
const event_ptr_tt< RedactionEvent > & redactedBecause () const
 
QString redactionReason () const
 
QString transactionId () const
 The transaction_id JSON value for the event. More...
 
bool isStateEvent () const
 
QString stateKey () const
 
void setRoomId (const QString &roomId)
 Fill the pending event object with the room id. More...
 
void setSender (const QString &senderId)
 Fill the pending event object with the sender id. More...
 
void setTransactionId (const QString &txnId)
 Fill the pending event object with the transaction id. More...
 
void addId (const QString &newId)
 Add an event id to locally created events after they are sent. More...
 
void setOriginalEvent (event_ptr_tt< EncryptedEvent > &&originalEvent)
 
const EncryptedEventoriginalEvent () const
 
const QJsonObject encryptedJson () const
 
- Public Member Functions inherited from Quotient::Event
virtual const AbstractEventMetaTypemetaType () const
 
 Event (Event &&) noexcept=default
 
Eventoperator= (Event &&)=delete
 
virtual ~Event ()
 
QString matrixType () const
 Exact Matrix type stored in JSON. More...
 
template<EventClass EventT>
bool is () const
 
template<typename... VisitorTs>
auto switchOnType (VisitorTs &&... visitors) const
 Apply one of the visitors based on the actual event type. More...
 
const QJsonObject & fullJson () const
 
const QJsonObject contentJson () const
 
template<typename T , typename KeyT >
const T contentPart (KeyT &&key) const
 Get a part of the content object, assuming a given type. More...
 
const QJsonObject unsignedJson () const
 
template<typename T , typename KeyT >
const T unsignedPart (KeyT &&key) const
 Get a part of the unsigned object, assuming a given type. More...
 
bool isStateEvent () const
 

Static Public Member Functions

static QString rawMsgTypeForUrl (const QUrl &url)
 
static QString rawMsgTypeForFile (const QFileInfo &fi)
 
- Static Public Member Functions inherited from Quotient::Event
static QJsonObject basicJson (const QString &matrixType, const QJsonObject &content)
 Make a minimal correct Matrix event JSON. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Quotient::Event
static EventMetaType< EventBaseMetaType { "Event" }
 
- Protected Member Functions inherited from Quotient::RoomEvent
 RoomEvent (const QJsonObject &json)
 
void dumpTo (QDebug dbg) const override
 
- Protected Member Functions inherited from Quotient::Event
 Event (const QJsonObject &json)
 
QJsonObject & editJson ()
 

Detailed Description

The event class corresponding to m.room.message events

Definition at line 19 of file roommessageevent.h.

Member Enumeration Documentation

◆ MsgType

Enumerator
Text 
Emote 
Notice 
Image 
File 
Location 
Video 
Audio 
Unknown 

Definition at line 24 of file roommessageevent.h.

Constructor & Destructor Documentation

◆ RoomMessageEvent() [1/3]

Quotient::RoomMessageEvent::RoomMessageEvent ( const QString &  plainBody,
const QString &  jsonMsgType,
std::unique_ptr< EventContent::Base content = nullptr,
const std::optional< EventRelation > &  relatesTo = std::nullopt 
)

◆ RoomMessageEvent() [2/3]

Quotient::RoomMessageEvent::RoomMessageEvent ( const QString &  plainBody,
MsgType  msgType = MsgType::Text,
std::unique_ptr< EventContent::Base content = nullptr,
const std::optional< EventRelation > &  relatesTo = std::nullopt 
)
explicit

◆ RoomMessageEvent() [3/3]

Quotient::RoomMessageEvent::RoomMessageEvent ( const QJsonObject &  obj)
explicit

Member Function Documentation

◆ content()

std::unique_ptr<EventContent::Base> Quotient::RoomMessageEvent::content ( ) const

Load event content from the event JSON.

Warning
The result must be checked for nullptr as an event with just a plainBody will not have a content object.
Since libQuotient 0.9, the returned value has changed from a C pointer (TypedBase*) to std::unique_ptr<> because the deserialised content object is no more stored inside the event. The calling code must either store the entire returned value in a variable or copy/move away the needed field from the returned value; a reference or a pointer to a field will become dangling at the statement end.
Returns
an event content object if the event has content, nullptr otherwise.

◆ fileNameToDownload()

QString Quotient::RoomMessageEvent::fileNameToDownload ( ) const

◆ get()

template<std::derived_from< EventContent::Base > ContentT>
std::unique_ptr<ContentT> Quotient::RoomMessageEvent::get ( ) const
inline

Get the message content and try to cast it to the specified type.

Returns
A pointer to the object of the requested type if the event has content of this type; nullptr, if the event has no content or the content cannot be cast to this type

Definition at line 77 of file roommessageevent.h.

◆ getThumbnail()

EventContent::Thumbnail Quotient::RoomMessageEvent::getThumbnail ( ) const

Retrieve a thumbnail from the message event.

◆ has()

template<std::derived_from< EventContent::Base > ContentT>
bool Quotient::RoomMessageEvent::has ( ) const
inline

Determine whether the message has content/attachment of a specified type.

Returns
true, if the message has type and content corresponding to ContentT (e.g. m.file or m.audio for FileContent); false otherwise

Definition at line 70 of file roommessageevent.h.

◆ hasThumbnail()

bool Quotient::RoomMessageEvent::hasThumbnail ( ) const

Determine whether the message has a thumbnail.

Returns
true, if the message has a data structure corresponding to a thumbnail (the message type may be one for visual content, such as m.image, or non-visual, i.e. m.file or m.location); false otherwise

◆ isReplaced()

bool Quotient::RoomMessageEvent::isReplaced ( ) const

Determine whether the event has been replaced.

Returns
true if this event has been overridden by another event with "rel_type": "m.replace"; false otherwise

◆ isReply()

bool Quotient::RoomMessageEvent::isReply ( bool  includeFallbacks = false) const

Determine whether the event is a reply to another message.

Parameters
includeFallbacksinclude thread fallback replies for non-threaded clients.
Returns
true if this event is a reply, i.e. it has "m.in_reply_to" event ID and is not a thread fallback (except where includeFallbacks is true); false otherwise.
Note
It's possible to reply to another message in a thread so this function will return true for a "rel_type" of "m.thread" if "is_falling_back" is false.

◆ isThreaded()

bool Quotient::RoomMessageEvent::isThreaded ( ) const

Determine whether the event is part of a thread.

Returns
true if this event is part of a thread, i.e. it has "rel_type": "m.thread" or "m.relations": { "m.thread": {}}; false otherwise.

◆ mimeType()

QMimeType Quotient::RoomMessageEvent::mimeType ( ) const

◆ msgtype()

MsgType Quotient::RoomMessageEvent::msgtype ( ) const

◆ plainBody()

QString Quotient::RoomMessageEvent::plainBody ( ) const

◆ rawMsgtype()

QString Quotient::RoomMessageEvent::rawMsgtype ( ) const

◆ rawMsgTypeForFile()

static QString Quotient::RoomMessageEvent::rawMsgTypeForFile ( const QFileInfo &  fi)
static

◆ rawMsgTypeForUrl()

static QString Quotient::RoomMessageEvent::rawMsgTypeForUrl ( const QUrl &  url)
static

◆ relatesTo()

std::optional<EventRelation> Quotient::RoomMessageEvent::relatesTo ( ) const

The EventRelation for this event.

Returns
an EventRelation object which can be checked for type if it exists, std::nullopt otherwise.

◆ replacedBy()

QString Quotient::RoomMessageEvent::replacedBy ( ) const

◆ replacedEvent()

QString Quotient::RoomMessageEvent::replacedEvent ( ) const

Obtain id of an event replaced by the current one.

See also
RoomEvent::isReplaced, RoomEvent::replacedBy

◆ replyEventId()

QString Quotient::RoomMessageEvent::replyEventId ( bool  includeFallbacks = false) const

The ID for the event being replied to.

Parameters
includeFallbacksinclude thread fallback replies for non-threaded clients.
Returns
The event ID for a reply, this includes threaded replies where "rel_type" is "m.thread" and "is_falling_back" is false (except where includeFallbacks is true).

◆ setContent()

void Quotient::RoomMessageEvent::setContent ( std::unique_ptr< EventContent::Base content)

Update the message JSON with the given content.

◆ threadRootEventId()

QString Quotient::RoomMessageEvent::threadRootEventId ( ) const

The event ID for the thread root event.

Note
This will return the ID of the event if it is the thread root.
Returns
The event ID of the thread root if threaded, an empty string otherwise.

◆ updateFileSourceInfo()

void Quotient::RoomMessageEvent::updateFileSourceInfo ( const FileSourceInfo fsi)

◆ upstreamEventId()

QString Quotient::RoomMessageEvent::upstreamEventId ( ) const

The upstream event ID for the relation.

Warning
If your client is not thread aware use replyEventId() as this will return the fallback reply ID so you can treat a threaded reply like a normal one.
If your client is thread aware use threadRootEventId() to get the thread root ID as this will return an empty string on the root event. threadRootEventId() will return the root messages ID on itself.

The documentation for this class was generated from the following file: