Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support event relations on all post message functions #806

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "events/roomcanonicalaliasevent.h"
#include "events/roomcreateevent.h"
#include "events/roommemberevent.h"
#include "events/roommessageevent.h"
nvrWhere marked this conversation as resolved.
Show resolved Hide resolved
#include "events/roompowerlevelsevent.h"
#include "events/roomtombstoneevent.h"
#include "events/simplestateevents.h"
Expand Down Expand Up @@ -2121,27 +2122,37 @@ void Room::discardMessage(const QString& txnId)
emit pendingEventDiscarded();
}

QString Room::postMessage(const QString& plainText, MessageEventType type)
QString Room::postEmote(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
return post<RoomMessageEvent>(plainText, type)->transactionId();
std::unique_ptr<EventContent::TextContent> content = nullptr;
if (html) {
content = std::make_unique<EventContent::TextContent>(*html, u"text/html"_s);
}

return post<RoomMessageEvent>(plainText, MessageEventType::Emote, std::move(content), relatesTo)->transactionId();
}

QString Room::postPlainText(const QString& plainText)
QString Room::postNotice(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
return postMessage(plainText, MessageEventType::Text);
std::unique_ptr<EventContent::TextContent> content = nullptr;
if (html) {
content = std::make_unique<EventContent::TextContent>(*html, u"text/html"_s);
}

return post<RoomMessageEvent>(plainText, MessageEventType::Notice, std::move(content), relatesTo)->transactionId();
}

QString Room::postHtmlMessage(const QString& plainText, const QString& html,
MessageEventType type)
QString Room::postPlainText(const QString& plainText, std::optional<EventRelation> relatesTo)
{
return post<RoomMessageEvent>(plainText, type,
std::make_unique<EventContent::TextContent>(html, u"text/html"_s))
->transactionId();
return post<RoomMessageEvent>(plainText, MessageEventType::Text, nullptr, relatesTo)->transactionId();
}

QString Room::postHtmlText(const QString& plainText, const QString& html)
QString Room::postHtmlText(const QString& plainText, const QString& html, std::optional<EventRelation> relatesTo)
{
return postHtmlMessage(plainText, html);
return post<RoomMessageEvent>(plainText, MessageEventType::Text,
std::make_unique<EventContent::TextContent>(html, u"text/html"_s),
relatesTo)
->transactionId();
}

QString Room::postReaction(const QString& eventId, const QString& key)
Expand Down Expand Up @@ -2198,7 +2209,8 @@ QString Room::Private::doPostFile(event_ptr_tt<RoomMessageEvent> fileEvent, cons
}

QString Room::postFile(const QString& plainText,
std::unique_ptr<EventContent::FileContentBase> fileContent)
std::unique_ptr<EventContent::FileContentBase> fileContent,
std::optional<EventRelation> relatesTo)
{
Q_ASSERT(fileContent != nullptr);
const auto url = fileContent->url();
Expand All @@ -2208,15 +2220,11 @@ QString Room::postFile(const QString& plainText,

return d->doPostFile(makeEvent<RoomMessageEvent>(plainText,
RoomMessageEvent::rawMsgTypeForFile(localFile),
std::move(fileContent)),
std::move(fileContent),
relatesTo),
url);
}

QString Room::postEvent(RoomEvent* event)
{
return d->sendEvent(RoomEventPtr(event))->transactionId();
}

const PendingEventItem& Room::post(RoomEventPtr event)
{
return d->sendEvent(std::move(event));
Expand Down
39 changes: 21 additions & 18 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,28 @@ class QUOTIENT_API Room : public QObject {
return post(makeEvent<EvT>(std::forward<ArgTs>(args)...));
}

/// Send a plain text message
QString postPlainText(const QString& plainText, std::optional<EventRelation> relatesTo = std::nullopt);

/// Send a rich text message
QString postHtmlText(const QString& plainText, const QString& html, std::optional<EventRelation> relatesTo = std::nullopt);

/// Send a m.emote message
QString postEmote(const QString& plainText, std::optional<const QString> html = std::nullopt, std::optional<EventRelation> relatesTo = std::nullopt);

/// Send an m.notice message
QString postNotice(const QString& plainText, std::optional<const QString> html = std::nullopt, std::optional<EventRelation> relatesTo = std::nullopt);
nvrWhere marked this conversation as resolved.
Show resolved Hide resolved

/// Send a file with the given content
nvrWhere marked this conversation as resolved.
Show resolved Hide resolved
QString postFile(const QString& plainText,
std::unique_ptr<EventContent::FileContentBase> fileContent);
std::unique_ptr<EventContent::FileContentBase> fileContent,
std::optional<EventRelation> relatesTo = std::nullopt);

/// Send the given Json as a message
QString postJson(const QString& matrixType, const QJsonObject& eventContent);

/// Send a reaction on a given event with a given key
QString postReaction(const QString& eventId, const QString& key);
nvrWhere marked this conversation as resolved.
Show resolved Hide resolved

PendingEventItem::future_type whenMessageMerged(QString txnId) const;

Expand All @@ -749,23 +769,6 @@ public Q_SLOTS:
/** Check whether the room should be upgraded */
void checkVersion();

QString postMessage(const QString& plainText, MessageEventType type);
QString postPlainText(const QString& plainText);
QString postHtmlMessage(const QString& plainText, const QString& html,
MessageEventType type = MessageEventType::Text);
QString postHtmlText(const QString& plainText, const QString& html);
/// Send a reaction on a given event with a given key
QString postReaction(const QString& eventId, const QString& key);

/** Post a pre-created room message event
*
* Takes ownership of the event, deleting it once the matching one
* arrives with the sync
* \return transaction id associated with the event.
*/
[[deprecated("Use post() instead")]]
QString postEvent(RoomEvent* event);
QString postJson(const QString& matrixType, const QJsonObject& eventContent);
QString retryMessage(const QString& txnId);
void discardMessage(const QString& txnId);

Expand Down
3 changes: 1 addition & 2 deletions quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ void TestSuite::finishTest(const TestToken& token, bool condition,
if (condition) {
clog << item << " successful" << endl;
if (targetRoom)
targetRoom->postMessage(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1,
MessageEventType::Notice);
targetRoom->postNotice(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1);
} else {
clog << item << " FAILED at " << file << ":" << line << endl;
if (targetRoom)
Expand Down