Use the new mtxclient special effects refactoring

pull/1407/head
Loren Burkholder 2 years ago committed by Nicolas Werner
parent e026242a62
commit 138b0a6b86
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 2
      CMakeLists.txt
  2. 2
      io.github.NhekoReborn.Nheko.yaml
  3. 2
      resources/qml/delegates/MessageDelegate.qml
  4. 6
      src/Utils.cpp
  5. 9
      src/Utils.h
  6. 3
      src/timeline/InputBar.cpp
  7. 42
      src/timeline/TimelineModel.cpp
  8. 2
      src/timeline/TimelineModel.h

@ -602,7 +602,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare(
MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG c8849cd033bb59bee39f3fb2eaca953853731eb2
GIT_TAG f8a9cbbb25ea145a23506c2f9386f6c61401bed0
)
set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "")
set(BUILD_LIB_TESTS OFF CACHE INTERNAL "")

@ -213,7 +213,7 @@ modules:
buildsystem: cmake-ninja
name: mtxclient
sources:
- commit: c8849cd033bb59bee39f3fb2eaca953853731eb2
- commit: f8a9cbbb25ea145a23506c2f9386f6c61401bed0
#tag: v0.9.2
type: git
url: https://github.com/Nheko-Reborn/mtxclient.git

@ -116,7 +116,7 @@ Item {
}
DelegateChoice {
roleValue: MtxEvent.ConfettiMessage
roleValue: MtxEvent.ElementEffectMessage
TextMessage {
formatted: d.formattedBody

@ -223,7 +223,7 @@ utils::getMessageDescription(const TimelineEvent &event,
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 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>;
@ -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)) {

@ -104,7 +104,7 @@ messageDescription(const QString &username = QString(),
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 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>;
@ -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)

@ -609,7 +609,8 @@ InputBar::confetti(const QString &body, bool rainbowify)
{
auto html = utils::markdownToHtml(body, rainbowify);
mtx::events::msg::Confetti confetti;
mtx::events::msg::ElementEffect confetti;
confetti.msgtype = "nic.custom.confetti";
confetti.body = body.trimmed().toStdString();
if (html != body.trimmed().toHtmlEscaped() &&

@ -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") {
needsSpecialEffects_ = true;
specialEffects_.setFlag(Rainfall);
}
} else if (std::holds_alternative<RoomEvent<mtx::events::msg::Confetti>>(e)) {
} 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);
}
}
}
@ -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 {

@ -99,7 +99,7 @@ enum EventType
Widget,
/// m.room.message
AudioMessage,
ConfettiMessage,
ElementEffectMessage,
EmoteMessage,
FileMessage,
ImageMessage,

Loading…
Cancel
Save