diff --git a/src/Utils.cpp b/src/Utils.cpp index 1746883e711505b1c2d50375aec7394653553e6c..5e8e1a169cc303447dbb7a549ca4a9f59099e6d2 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 119d660ab19649a4860796caaf7f3cad2c040ed0..505d8e6afba5e45774307e786c9bc4120d090c84 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 2fd4b6d41622e5bc1bf51c305a3f9bff640fda64..54e054ec4a802f32434de56c7f0c8397fbb3e48e 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); }