diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-12-17 01:11:19 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-12-17 01:11:19 +0100 |
commit | e8e475956b3d2a57981ad41536a1ddc1b7361591 (patch) | |
tree | 90941aa94f6542ae8ae1a91d54fd48aab3ef221a /src/Utils.cpp | |
parent | Fix sending confetti (diff) | |
download | nheko-e8e475956b3d2a57981ad41536a1ddc1b7361591.tar.xz |
Fix confetti in the sidebar
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r-- | src/Utils.cpp | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index c19871bc..b0d84339 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -45,16 +45,17 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin const auto username = displayName; const auto ts = QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts); - auto body = utils::event_body(event).trimmed(); + auto body = mtx::accessors::body(event); if (mtx::accessors::relations(event).reply_to()) - body = QString::fromStdString(utils::stripReplyFromBody(body.toStdString())); - - return DescInfo{QString::fromStdString(msg.event_id), - sender, - utils::messageDescription<T>(username, body, sender == localUser), - utils::descriptiveTime(ts), - msg.origin_server_ts, - ts}; + body = utils::stripReplyFromBody(body); + + return DescInfo{ + QString::fromStdString(msg.event_id), + sender, + utils::messageDescription<T>(username, QString::fromStdString(body), sender == localUser), + utils::descriptiveTime(ts), + msg.origin_server_ts, + ts}; } std::string @@ -216,6 +217,7 @@ utils::getMessageDescription(const TimelineEvent &event, using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>; using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; using Video = mtx::events::RoomEvent<mtx::events::msg::Video>; + using Confetti = mtx::events::RoomEvent<mtx::events::msg::Confetti>; using CallInvite = mtx::events::RoomEvent<mtx::events::voip::CallInvite>; using CallAnswer = mtx::events::RoomEvent<mtx::events::voip::CallAnswer>; using CallHangUp = mtx::events::RoomEvent<mtx::events::voip::CallHangUp>; @@ -236,6 +238,8 @@ utils::getMessageDescription(const TimelineEvent &event, return createDescriptionInfo<Text>(event, localUser, displayName); } else if (std::holds_alternative<Video>(event)) { return createDescriptionInfo<Video>(event, localUser, displayName); + } else if (std::holds_alternative<Confetti>(event)) { + return createDescriptionInfo<Confetti>(event, localUser, displayName); } else if (std::holds_alternative<CallInvite>(event)) { return createDescriptionInfo<CallInvite>(event, localUser, displayName); } else if (std::holds_alternative<CallAnswer>(event)) { @@ -324,28 +328,6 @@ utils::levenshtein_distance(const std::string &s1, const std::string &s2) return *std::min_element(row1.begin(), row1.end()); } -QString -utils::event_body(const mtx::events::collections::TimelineEvents &e) -{ - using namespace mtx::events; - if (auto ev = std::get_if<RoomEvent<msg::Audio>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::Emote>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::File>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::Image>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::Notice>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::Text>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - if (auto ev = std::get_if<RoomEvent<msg::Video>>(&e); ev != nullptr) - return QString::fromStdString(ev->content.body); - - return QString(); -} - QPixmap utils::scaleImageToPixmap(const QImage &img, int size) { |