From a7595eab5a6fdcde80b9989f65de1801afad3d3d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 11 Sep 2019 00:00:04 +0200 Subject: Reimplement sending basic text messages --- src/timeline2/TimelineViewManager.cpp | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/timeline2/TimelineViewManager.cpp') diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp index eb9bea54..6aa2ff43 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp @@ -62,3 +62,41 @@ TimelineViewManager::initWithMessages(const std::mapaddEvents(e.second); } } + +void +TimelineViewManager::queueTextMessage(const QString &msg) +{ + mtx::events::msg::Text text = {}; + text.body = msg.trimmed().toStdString(); + text.format = "org.matrix.custom.html"; + text.formatted_body = utils::markdownToHtml(msg).toStdString(); + + if (timeline_) + timeline_->sendMessage(text); +} + +void +TimelineViewManager::queueReplyMessage(const QString &reply, const RelatedInfo &related) +{ + mtx::events::msg::Text text = {}; + + QString body; + bool firstLine = true; + for (const auto &line : related.quoted_body.splitRef("\n")) { + if (firstLine) { + firstLine = false; + body = QString("> <%1> %2\n").arg(related.quoted_user).arg(line); + } else { + body = QString("%1\n> %2\n").arg(body).arg(line); + } + } + + text.body = QString("%1\n%2").arg(body).arg(reply).toStdString(); + text.format = "org.matrix.custom.html"; + text.formatted_body = + utils::getFormattedQuoteBody(related, utils::markdownToHtml(reply)).toStdString(); + text.relates_to.in_reply_to.event_id = related.related_event; + + if (timeline_) + timeline_->sendMessage(text); +} -- cgit 1.5.1