Skip to content

Commit

Permalink
Support event relations on all post message functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nvrWhere committed Oct 4, 2024
1 parent 28ce82e commit 8b7df73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
22 changes: 12 additions & 10 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,27 +2121,28 @@ void Room::discardMessage(const QString& txnId)
emit pendingEventDiscarded();
}

QString Room::postMessage(const QString& plainText, MessageEventType type)
QString Room::postMessage(const QString& plainText, MessageEventType type, std::optional<EventRelation> relatesTo)
{
return post<RoomMessageEvent>(plainText, type)->transactionId();
return post<RoomMessageEvent>(plainText, type, nullptr, relatesTo)->transactionId();
}

QString Room::postPlainText(const QString& plainText)
QString Room::postPlainText(const QString& plainText, std::optional<EventRelation> relatesTo)
{
return postMessage(plainText, MessageEventType::Text);
return postMessage(plainText, MessageEventType::Text, relatesTo);
}

QString Room::postHtmlMessage(const QString& plainText, const QString& html,
MessageEventType type)
MessageEventType type, std::optional<EventRelation> relatesTo)
{
return post<RoomMessageEvent>(plainText, type,
new EventContent::TextContent(html, u"text/html"_s))
new EventContent::TextContent(html, u"text/html"_s),
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 postHtmlMessage(plainText, html, MessageEventType::Text, relatesTo);
}

QString Room::postReaction(const QString& eventId, const QString& key)
Expand Down Expand Up @@ -2198,7 +2199,8 @@ QString Room::Private::doPostFile(RoomEventPtr&& msgEvent, const QUrl& localUrl)
}

QString Room::postFile(const QString& plainText,
EventContent::TypedBase* content)
EventContent::TypedBase* content,
std::optional<EventRelation> relatesTo)
{
Q_ASSERT(content != nullptr && content->fileInfo() != nullptr);
const auto* const fileInfo = content->fileInfo();
Expand All @@ -2210,7 +2212,7 @@ QString Room::postFile(const QString& plainText,

return d->doPostFile(
makeEvent<RoomMessageEvent>(
plainText, RoomMessageEvent::rawMsgTypeForFile(localFile), content),
plainText, RoomMessageEvent::rawMsgTypeForFile(localFile), content, relatesTo),
fileInfo->url());
}

Expand Down
11 changes: 6 additions & 5 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,16 @@ 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 postMessage(const QString& plainText, MessageEventType type, std::optional<EventRelation> relatesTo = std::nullopt);
QString postPlainText(const QString& plainText, std::optional<EventRelation> relatesTo = std::nullopt);
QString postHtmlMessage(const QString& plainText, const QString& html,
MessageEventType type = MessageEventType::Text);
QString postHtmlText(const QString& plainText, const QString& html);
MessageEventType type = MessageEventType::Text,
std::optional<EventRelation> relatesTo = std::nullopt);
QString postHtmlText(const QString& plainText, const QString& html, std::optional<EventRelation> relatesTo = std::nullopt);
/// Send a reaction on a given event with a given key
QString postReaction(const QString& eventId, const QString& key);

QString postFile(const QString& plainText, EventContent::TypedBase* content);
QString postFile(const QString& plainText, EventContent::TypedBase* content, std::optional<EventRelation> relatesTo = std::nullopt);

/** Post a pre-created room message event
*
Expand Down
2 changes: 1 addition & 1 deletion quotest/quotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ TEST_IMPL(sendFile)
const auto tfName = tfi.fileName();
clog << "Sending file " << tfName.toStdString() << endl;
const auto txnId = targetRoom->postFile(
"Test file"_L1, new EventContent::FileContent(tfi));
"Test file"_L1, new EventContent::FileContent(tfi), std::nullopt);
if (!validatePendingEvent<RoomMessageEvent>(txnId)) {
clog << "Invalid pending event right after submitting" << endl;
tf->deleteLater();
Expand Down

0 comments on commit 8b7df73

Please sign in to comment.