Skip to content

Commit

Permalink
Further comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nvrWhere committed Dec 2, 2024
1 parent d4bb172 commit 80d145c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
34 changes: 0 additions & 34 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,25 +293,6 @@ 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 @@ -2140,21 +2121,6 @@ void Room::discardMessage(const QString& txnId)
emit pendingEventDiscarded();
}

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

QString Room::postEmote(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
return d->postAllText<MessageEventType::Emote>(plainText, html, relatesTo);
}

QString Room::postNotice(const QString& plainText, std::optional<const QString> html, std::optional<EventRelation> relatesTo)
{
return d->postAllText<MessageEventType::Notice>(plainText, html, relatesTo);
}

QString Room::postReaction(const QString& eventId, const QString& key)
{
return post<ReactionEvent>(eventId, key)->transactionId();
Expand Down
28 changes: 20 additions & 8 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,14 +721,26 @@ class QUOTIENT_API Room : public QObject {
return post(makeEvent<EvT>(std::forward<ArgTs>(args)...));
}

//! Send a text message
QString postText(const QString& plainText, std::optional<const QString> html = std::nullopt, 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);
//! \brief Send a text type message
//!
//! This means MessageEventType Text, Emote or Notice.
template<MessageEventType type = MessageEventType::Text>
QString postText(const QString& plainText,
const std::optional<QString>& html = std::nullopt,
const std::optional<EventRelation>& relatesTo = std::nullopt)
{
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 post<RoomMessageEvent>(plainText, type, std::move(content), relatesTo)->transactionId();
}

//! Send a file with the given content
QString postFile(const QString& plainText,
Expand Down
3 changes: 2 additions & 1 deletion quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Quotient/csapi/leaving.h>
#include <Quotient/csapi/room_send.h>

#include "events/roommessageevent.h"
#include <Quotient/events/reactionevent.h>
#include <Quotient/events/redactionevent.h>
#include <Quotient/events/simplestateevents.h>
Expand Down Expand Up @@ -169,7 +170,7 @@ void TestSuite::finishTest(const TestToken& token, bool condition,
if (condition) {
clog << item << " successful" << endl;
if (targetRoom)
targetRoom->postNotice(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1);
targetRoom->postText<MessageEventType::Notice>(origin % ": "_L1 % QString::fromUtf8(item) % " successful"_L1);
} else {
clog << item << " FAILED at " << file << ":" << line << endl;
if (targetRoom)
Expand Down

0 comments on commit 80d145c

Please sign in to comment.