diff options
author | Loren Burkholder <computersemiexpert@outlook.com> | 2023-04-01 15:41:49 -0400 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-04-11 01:01:21 +0200 |
commit | 138b0a6b8683a8e69a4d2fb92926e5a0645d4d5a (patch) | |
tree | 73e5cd6ed41ff9d150f747c1e89455e155bda807 /src | |
parent | Don't bother with rainbow rain (diff) | |
download | nheko-138b0a6b8683a8e69a4d2fb92926e5a0645d4d5a.tar.xz |
Use the new mtxclient special effects refactoring
Diffstat (limited to '')
-rw-r--r-- | src/Utils.cpp | 32 | ||||
-rw-r--r-- | src/Utils.h | 37 | ||||
-rw-r--r-- | src/timeline/InputBar.cpp | 5 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 42 | ||||
-rw-r--r-- | src/timeline/TimelineModel.h | 2 |
5 files changed, 66 insertions, 52 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index eca5cb29..2bf8eb3b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -215,20 +215,20 @@ utils::getMessageDescription(const TimelineEvent &event, const QString &localUser, const QString &displayName) { - using Audio = mtx::events::RoomEvent<mtx::events::msg::Audio>; - using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>; - using File = mtx::events::RoomEvent<mtx::events::msg::File>; - using Image = mtx::events::RoomEvent<mtx::events::msg::Image>; - using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>; - using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; - using Unknown = mtx::events::RoomEvent<mtx::events::msg::Unknown>; - 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>; - using CallReject = mtx::events::RoomEvent<mtx::events::voip::CallReject>; - using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; + using Audio = mtx::events::RoomEvent<mtx::events::msg::Audio>; + using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>; + using File = mtx::events::RoomEvent<mtx::events::msg::File>; + using Image = mtx::events::RoomEvent<mtx::events::msg::Image>; + using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>; + using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; + using Unknown = mtx::events::RoomEvent<mtx::events::msg::Unknown>; + using Video = mtx::events::RoomEvent<mtx::events::msg::Video>; + using ElementEffect = mtx::events::RoomEvent<mtx::events::msg::ElementEffect>; + 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>; + using CallReject = mtx::events::RoomEvent<mtx::events::voip::CallReject>; + using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; if (std::holds_alternative<Audio>(event)) { return createDescriptionInfo<Audio>(event, localUser, displayName); @@ -246,8 +246,8 @@ utils::getMessageDescription(const TimelineEvent &event, return createDescriptionInfo<Unknown>(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<ElementEffect>(event)) { + return createDescriptionInfo<ElementEffect>(event, localUser, displayName); } else if (std::holds_alternative<CallInvite>(event)) { return createDescriptionInfo<CallInvite>(event, localUser, displayName); } else if (std::holds_alternative<CallAnswer>(event)) { diff --git a/src/Utils.h b/src/Utils.h index c16d5a13..2c8988e5 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -95,21 +95,21 @@ messageDescription(const QString &username = QString(), const QString &body = QString(), const bool isLocal = false) { - using Audio = mtx::events::RoomEvent<mtx::events::msg::Audio>; - using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>; - using File = mtx::events::RoomEvent<mtx::events::msg::File>; - using Image = mtx::events::RoomEvent<mtx::events::msg::Image>; - using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>; - using Sticker = mtx::events::Sticker; - using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; - using Unknown = mtx::events::RoomEvent<mtx::events::msg::Unknown>; - 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>; - using CallReject = mtx::events::RoomEvent<mtx::events::voip::CallReject>; - using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; + using Audio = mtx::events::RoomEvent<mtx::events::msg::Audio>; + using Emote = mtx::events::RoomEvent<mtx::events::msg::Emote>; + using File = mtx::events::RoomEvent<mtx::events::msg::File>; + using Image = mtx::events::RoomEvent<mtx::events::msg::Image>; + using Notice = mtx::events::RoomEvent<mtx::events::msg::Notice>; + using Sticker = mtx::events::Sticker; + using Text = mtx::events::RoomEvent<mtx::events::msg::Text>; + using Unknown = mtx::events::RoomEvent<mtx::events::msg::Unknown>; + using Video = mtx::events::RoomEvent<mtx::events::msg::Video>; + using ElementEffect = mtx::events::RoomEvent<mtx::events::msg::ElementEffect>; + 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>; + using CallReject = mtx::events::RoomEvent<mtx::events::voip::CallReject>; + using Encrypted = mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>; if (std::is_same<T, Audio>::value) { if (isLocal) @@ -156,14 +156,15 @@ messageDescription(const QString &username = QString(), else return QCoreApplication::translate("message-description sent:", "%1: %2") .arg(username, body); - } else if (std::is_same<T, Confetti>::value) { + } else if (std::is_same<T, ElementEffect>::value) { if (body.isEmpty()) { + // TODO: what is the best way to handle this? if (isLocal) return QCoreApplication::translate("message-description sent:", - "You sent some confetti"); + "You sent a chat effect"); else return QCoreApplication::translate("message-description sent:", - "%1 sent some confetti") + "%1 sent a chat effect") .arg(username); } else { if (isLocal) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index d3810cf8..fe8b8e48 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -609,8 +609,9 @@ InputBar::confetti(const QString &body, bool rainbowify) { auto html = utils::markdownToHtml(body, rainbowify); - mtx::events::msg::Confetti confetti; - confetti.body = body.trimmed().toStdString(); + mtx::events::msg::ElementEffect confetti; + confetti.msgtype = "nic.custom.confetti"; + confetti.body = body.trimmed().toStdString(); if (html != body.trimmed().toHtmlEscaped() && ChatPage::instance()->userSettings()->markdown()) { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index ba10c3c6..9e667bce 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -54,9 +54,9 @@ struct RoomEventType return qml_mtx_events::EventType::AudioMessage; } constexpr qml_mtx_events::EventType - operator()(const mtx::events::Event<mtx::events::msg::Confetti> &) + operator()(const mtx::events::Event<mtx::events::msg::ElementEffect> &) { - return qml_mtx_events::EventType::ConfettiMessage; + return qml_mtx_events::EventType::ElementEffectMessage; } constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Emote> &) @@ -367,7 +367,7 @@ qml_mtx_events::fromRoomEventType(qml_mtx_events::EventType t) return mtx::events::EventType::SpaceChild; /// m.room.message case qml_mtx_events::AudioMessage: - case qml_mtx_events::ConfettiMessage: + case qml_mtx_events::ElementEffectMessage: case qml_mtx_events::EmoteMessage: case qml_mtx_events::FileMessage: case qml_mtx_events::ImageMessage: @@ -1091,14 +1091,17 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) msg.contains("🎉") || msg.contains("🎊")) { needsSpecialEffects_ = true; specialEffects_.setFlag(Confetti); - } else if (std::get<RoomEvent<mtx::events::msg::Unknown>>(e).content.msgtype == - "io.element.effect.rainfall") { + } + } else if (std::holds_alternative<RoomEvent<mtx::events::msg::ElementEffect>>(e)) { + if (auto msgtype = + std::get<RoomEvent<mtx::events::msg::ElementEffect>>(e).content.msgtype; + msgtype == "nic.custom.confetti") { + needsSpecialEffects_ = true; + specialEffects_.setFlag(Confetti); + } else if (msgtype == "io.element.effect.rainfall") { needsSpecialEffects_ = true; specialEffects_.setFlag(Rainfall); } - } else if (std::holds_alternative<RoomEvent<mtx::events::msg::Confetti>>(e)) { - needsSpecialEffects_ = true; - specialEffects_.setFlag(Confetti); } } @@ -2949,7 +2952,7 @@ TimelineModel::setEdit(const QString &newEdit) if (msgType == mtx::events::MessageType::Text || msgType == mtx::events::MessageType::Notice || msgType == mtx::events::MessageType::Emote || - msgType == mtx::events::MessageType::Confetti || + msgType == mtx::events::MessageType::ElementEffect || msgType == mtx::events::MessageType::Unknown) { auto relInfo = relatedInfo(newEdit); auto editText = relInfo.quoted_body; @@ -2971,14 +2974,23 @@ TimelineModel::setEdit(const QString &newEdit) if (msgType == mtx::events::MessageType::Emote) input()->setText("/me " + editText); - else if (msgType == mtx::events::MessageType::Confetti) - input()->setText("/confetti " + editText); - else if (msgType == mtx::events::MessageType::Unknown) { - if (auto u = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Unknown>>(&e); - u && u->content.msgtype == "io.element.effect.rainfall") + else if (msgType == mtx::events::MessageType::ElementEffect) + { + auto u = + std::get_if<mtx::events::RoomEvent<mtx::events::msg::ElementEffect>>(&e); + auto msgtypeString = u ? u->content.msgtype : ""; + if (msgtypeString == "io.element.effect.rainfall") input()->setText("/rainfall " + editText); + else if (msgtypeString == "nic.custom.confetti") + input()->setText("/confetti " + editText); else - input()->setText(editText); + input()->setText("/msgtype " + QString::fromStdString(msgtypeString) + " " + + editText); + } else if (msgType == mtx::events::MessageType::Unknown) { + auto u = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Unknown>>(&e); + input()->setText("/msgtype " + + (u ? QString::fromStdString(u->content.msgtype) : "") + " " + + editText); } else input()->setText(editText); } else { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index ce3dc9e4..ef845bb5 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -99,7 +99,7 @@ enum EventType Widget, /// m.room.message AudioMessage, - ConfettiMessage, + ElementEffectMessage, EmoteMessage, FileMessage, ImageMessage, |