Skip to content

Commit

Permalink
Comment updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nvrWhere committed Dec 1, 2024
1 parent 1b217c5 commit d4bb172
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
50 changes: 25 additions & 25 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include "events/roomcanonicalaliasevent.h"
#include "events/roomcreateevent.h"
#include "events/roommemberevent.h"
#include "events/roommessageevent.h"
#include "events/roompowerlevelsevent.h"
#include "events/roomtombstoneevent.h"
#include "events/simplestateevents.h"
Expand Down Expand Up @@ -294,6 +293,25 @@ class Q_DECL_HIDDEN Room::Private {

const PendingEventItem& sendEvent(RoomEventPtr&& event);

// template<MessageEventType msgType>
template<MessageEventType type>
QString postAllText(const QString& plainText,
std::optional<const QString> html,
std::optional<EventRelation> relatesTo)
{
static_assert(type == MessageEventType::Text ||
type == MessageEventType::Emote ||
type == MessageEventType::Notice ,
"MessageEvent type is not a text message"
);

std::unique_ptr<EventContent::TextContent> content = nullptr;
if (html) {
content = std::make_unique<EventContent::TextContent>(*html, u"text/html"_s);
}
return q->post<RoomMessageEvent>(plainText, type, std::move(content), relatesTo)->transactionId();
}

QString doPostFile(event_ptr_tt<RoomMessageEvent> fileEvent, const QUrl& localUrl);

PendingEvents::iterator addAsPending(RoomEventPtr&& event);
Expand Down Expand Up @@ -2122,37 +2140,19 @@ void Room::discardMessage(const QString& txnId)
emit pendingEventDiscarded();
}

QString Room::postEmote(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
QString Room::postText(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
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();
return d->postAllText<MessageEventType::Text>(plainText, html, relatesTo);
}

QString Room::postNotice(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
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::postPlainText(const QString& plainText, std::optional<EventRelation> relatesTo)
QString Room::postEmote(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
return post<RoomMessageEvent>(plainText, MessageEventType::Text, nullptr, relatesTo)->transactionId();
return d->postAllText<MessageEventType::Emote>(plainText, html, relatesTo);
}

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

QString Room::postReaction(const QString& eventId, const QString& key)
Expand Down
17 changes: 7 additions & 10 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,27 +721,24 @@ 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 text message
QString postText(const QString& plainText, std::optional<const QString> html = std::nullopt, 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
//! 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
//! Send an m.notice message
QString postNotice(const QString& plainText, std::optional<const QString> html = std::nullopt, std::optional<EventRelation> relatesTo = std::nullopt);

/// Send a file with the given content
//! Send a file with the given content
QString postFile(const QString& plainText,
std::unique_ptr<EventContent::FileContentBase> fileContent,
std::optional<EventRelation> relatesTo = std::nullopt);

/// Send the given Json as a message
//! 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
//! Send a reaction on a given event with a given key
QString postReaction(const QString& eventId, const QString& key);

PendingEventItem::future_type whenMessageMerged(QString txnId) const;
Expand Down
8 changes: 4 additions & 4 deletions quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void TestSuite::finishTest(const TestToken& token, bool condition,
} else {
clog << item << " FAILED at " << file << ":" << line << endl;
if (targetRoom)
targetRoom->postPlainText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1
targetRoom->postText(origin % ": "_L1 % QString::fromUtf8(item) % " FAILED at "_L1
% QString::fromUtf8(file) % ", line "_L1 % QString::number(line));
}

Expand Down Expand Up @@ -363,7 +363,7 @@ TEST_IMPL(loadMembers)

TEST_IMPL(sendMessage)
{
auto txnId = targetRoom->postPlainText("Hello, "_L1 % origin % " is here"_L1);
auto txnId = targetRoom->postText("Hello, "_L1 % origin % " is here"_L1);
if (!validatePendingEvent<RoomMessageEvent>(txnId)) {
clog << "Invalid pending event right after submitting" << endl;
FAIL_TEST();
Expand Down Expand Up @@ -462,7 +462,7 @@ TEST_IMPL(sendFile)
if (id != txnId)
return false;

targetRoom->postPlainText(origin % ": File upload failed: "_L1 % error);
targetRoom->postText(origin % ": File upload failed: "_L1 % error);
tf->deleteLater();
FAIL_TEST();
});
Expand Down Expand Up @@ -922,7 +922,7 @@ void TestManager::conclude()
htmlReport += "<br><strong>Did not finish:</strong>"_L1 + QString::fromUtf8(dnfList);
}

auto txnId = room->postHtmlText(plainReport, htmlReport);
auto txnId = room->postText(plainReport, htmlReport);
// Now just wait until all the pending events reach the server
connectUntil(room, &Room::messageSent, this,
[this, txnId, room, plainReport] {
Expand Down

0 comments on commit d4bb172

Please sign in to comment.