diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index f06de06a..c94efcd7 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -38,10 +38,10 @@ set(BOOST_SHA256 set( MTXCLIENT_URL - https://github.com/mujx/mtxclient/archive/81d497adbb1c70e543482a7f7d5d83baa959cb81.tar.gz + https://github.com/mujx/mtxclient/archive/cd8f571f8d97b315435a3acf861d5cc8351363f9.tar.gz ) set(MTXCLIENT_HASH - 755697c07e4adc0ff380bde8ecd719f5da443b2baca757d4e9c59d30571f5773) + 4aad9205cdc84283955bbac430908340fe6e2addc4a9b44c6403d5aa581d6541) set( TWEENY_URL diff --git a/src/Utils.h b/src/Utils.h index 90c8d9f6..347ece80 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace utils { @@ -195,4 +196,19 @@ humanReadableFingerprint(const std::string &ed25519); QString humanReadableFingerprint(const QString &ed25519); + +//! Retrieve the message body taking into account the `formatted_body` field. +//! If the `format` of the message is not supported we fallback to `body`. +template +QString +get_message_body(const RoomMessageT &event) +{ + if (event.content.format.empty()) + return QString::fromStdString(event.content.body); + + if (event.content.format != common::FORMAT_MSG_TYPE) + return QString::fromStdString(event.content.body); + + return QString::fromStdString(event.content.formatted_body); +} } diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index 8726ec59..7548a5a5 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -436,7 +436,9 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent"); - body = "" + body + ""; + formatted_body = "" + formatted_body + ""; if (with_sender) { auto displayName = Cache::displayName(room_id_, sender); - generateBody(sender, displayName, body); + generateBody(sender, displayName, formatted_body); setupAvatarLayout(displayName); AvatarProvider::resolve( room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); }); } else { - generateBody(body); + generateBody(formatted_body); setupSimpleLayout(); } @@ -484,26 +484,25 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); - auto body = QString::fromStdString(event.content.body).trimmed(); + auto formatted_body = utils::get_message_body(event).trimmed(); + auto body = QString::fromStdString(event.content.body).trimmed(); + auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); auto displayName = Cache::displayName(room_id_, sender); - auto emoteMsg = QString("* %1 %2").arg(displayName).arg(body); + auto emoteMsg = QString("* %1 %2").arg(displayName).arg(formatted_body); descriptionMsg_ = {"", sender, emoteMsg, utils::descriptiveTime(timestamp), timestamp}; generateTimestamp(timestamp); - emoteMsg = emoteMsg.toHtmlEscaped(); - emoteMsg.replace(conf::strings::url_regex, conf::strings::url_html); - emoteMsg.replace("\n", "
"); if (with_sender) { - generateBody(sender, displayName, emoteMsg); + generateBody(sender, displayName, formatted_body); setupAvatarLayout(displayName); AvatarProvider::resolve( room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); }); } else { - generateBody(emoteMsg); + generateBody(formatted_body); setupSimpleLayout(); } @@ -528,7 +527,9 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent event_id_ = QString::fromStdString(event.event_id); const auto sender = QString::fromStdString(event.sender); - auto body = QString::fromStdString(event.content.body).trimmed(); + auto formatted_body = utils::get_message_body(event).trimmed(); + auto body = QString::fromStdString(event.content.body).trimmed(); + auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); auto displayName = Cache::displayName(room_id_, sender); @@ -541,18 +542,14 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent generateTimestamp(timestamp); - body = body.toHtmlEscaped(); - body.replace(conf::strings::url_regex, conf::strings::url_html); - body.replace("\n", "
"); - if (with_sender) { - generateBody(sender, displayName, body); + generateBody(sender, displayName, formatted_body); setupAvatarLayout(displayName); AvatarProvider::resolve( room_id_, sender, this, [this](const QImage &img) { setUserAvatar(img); }); } else { - generateBody(body); + generateBody(formatted_body); setupSimpleLayout(); }