summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-01-21 03:36:26 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-01-21 03:36:26 +0100
commitdc44ac50a3768f26ad242af263c043e0e94febef (patch)
treedf2161d39d3da51cb539975c5de6836b1f1c88bc /src
parentRemove use of deprecated enum (diff)
downloadnheko-dc44ac50a3768f26ad242af263c043e0e94febef.tar.xz
Linkify links before sending
Diffstat (limited to 'src')
-rw-r--r--src/Utils.cpp27
-rw-r--r--src/Utils.h2
-rw-r--r--src/timeline/TimelineModel.cpp17
3 files changed, 33 insertions, 13 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp

index 1746883e..5e8e1a16 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp
@@ -308,7 +308,7 @@ QString utils::linkifyMessage(const QString &body) { // Convert to valid XML. - auto doc = QString("<html>%1</html>").arg(body); + auto doc = body; doc.replace(conf::strings::url_regex, conf::strings::url_html); return doc; @@ -382,7 +382,7 @@ utils::markdownToHtml(const QString &text) // The buffer is no longer needed. free((char *)tmp_buf); - auto result = escapeBlacklistedHtml(QString::fromStdString(html)).trimmed(); + auto result = linkifyMessage(escapeBlacklistedHtml(QString::fromStdString(html))).trimmed(); return result; } @@ -390,6 +390,27 @@ utils::markdownToHtml(const QString &text) QString utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) { + auto getFormattedBody = [related]() { + using MsgType = mtx::events::MessageType; + + switch (related.type) { + case MsgType::File: { + return QString(QCoreApplication::translate("utils", "sent a file.")); + } + case MsgType::Image: { + return QString(QCoreApplication::translate("utils", "sent an image.")); + } + case MsgType::Audio: { + return QString(QCoreApplication::translate("utils", "sent an audio file.")); + } + case MsgType::Video: { + return QString(QCoreApplication::translate("utils", "sent a video")); + } + default: { + return related.quoted_formatted_body; + } + } + }; return QString("<mx-reply><blockquote><a " "href=\"https://matrix.to/#/%1/%2\">In reply " "to</a> <a href=\"https://matrix.to/#/%3\">%4</a><br" @@ -398,7 +419,7 @@ utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) QString::fromStdString(related.related_event), related.quoted_user, related.quoted_user, - getQuoteBody(related)) + + getFormattedBody()) + html; } diff --git a/src/Utils.h b/src/Utils.h
index 119d660a..505d8e6a 100644 --- a/src/Utils.h +++ b/src/Utils.h
@@ -27,7 +27,7 @@ struct RelatedInfo using MsgType = mtx::events::MessageType; MsgType type; QString room; - QString quoted_body; + QString quoted_body, quoted_formatted_body; std::string related_event; QString quoted_user; }; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 2fd4b6d4..54e054ec 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -775,19 +775,18 @@ TimelineModel::replyAction(QString id) event = decryptEvent(*e).event; } - RelatedInfo related = {}; - related.quoted_user = QString::fromStdString(mtx::accessors::sender(event)); - related.related_event = mtx::accessors::event_id(event); - related.type = mtx::accessors::msg_type(event); - related.quoted_body = mtx::accessors::formattedBodyWithFallback(event); - related.quoted_body.remove(QRegularExpression( + RelatedInfo related = {}; + related.quoted_user = QString::fromStdString(mtx::accessors::sender(event)); + related.related_event = mtx::accessors::event_id(event); + related.type = mtx::accessors::msg_type(event); + related.quoted_body = QString::fromStdString(mtx::accessors::body(event)); + related.quoted_body = utils::getQuoteBody(related); + related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event); + related.quoted_formatted_body.remove(QRegularExpression( "<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption)); nhlog::ui()->debug("after replacement: {}", related.quoted_body.toStdString()); related.room = room_id_; - // if (related.quoted_body.isEmpty()) - // return; - ChatPage::instance()->messageReply(related); }