mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Add initial support for displaying formatted messages
This commit is contained in:
parent
36c5a8f410
commit
8ad01f520a
3 changed files with 35 additions and 22 deletions
4
deps/CMakeLists.txt
vendored
4
deps/CMakeLists.txt
vendored
|
@ -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
|
||||
|
|
16
src/Utils.h
16
src/Utils.h
|
@ -12,6 +12,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QPixmap>
|
||||
#include <mtx/events/collections.hpp>
|
||||
#include <mtx/events/common.hpp>
|
||||
|
||||
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<typename RoomMessageT>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -436,7 +436,9 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
|
|||
event_id_ = QString::fromStdString(event.event_id);
|
||||
const auto sender = QString::fromStdString(event.sender);
|
||||
const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
|
||||
auto body = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
|
||||
|
||||
auto formatted_body = utils::get_message_body(event).trimmed();
|
||||
auto body = QString::fromStdString(event.content.body).trimmed();
|
||||
|
||||
descriptionMsg_ = {Cache::displayName(room_id_, sender),
|
||||
sender,
|
||||
|
@ -446,20 +448,18 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
|
|||
|
||||
generateTimestamp(timestamp);
|
||||
|
||||
body.replace(conf::strings::url_regex, conf::strings::url_html);
|
||||
body.replace("\n", "<br/>");
|
||||
body = "<i>" + body + "</i>";
|
||||
formatted_body = "<i>" + formatted_body + "</i>";
|
||||
|
||||
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<mtx::events::msg::Emote>
|
|||
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", "<br/>");
|
||||
|
||||
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<mtx::events::msg::Text>
|
|||
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<mtx::events::msg::Text>
|
|||
|
||||
generateTimestamp(timestamp);
|
||||
|
||||
body = body.toHtmlEscaped();
|
||||
body.replace(conf::strings::url_regex, conf::strings::url_html);
|
||||
body.replace("\n", "<br/>");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue