diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6c72e62e..70cd87f27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -150,6 +150,9 @@ add_library(neochat STATIC proxycontroller.h models/linemodel.cpp models/linemodel.h + events/locationbeaconevent.h + events/serveraclevent.h + events/widgetevent.h ) qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN diff --git a/src/eventhandler.cpp b/src/eventhandler.cpp index 4423a38a0..307aa4d06 100644 --- a/src/eventhandler.cpp +++ b/src/eventhandler.cpp @@ -21,7 +21,10 @@ #include "delegatetype.h" #include "eventhandler_logging.h" +#include "events/locationbeaconevent.h" #include "events/pollevent.h" +#include "events/serveraclevent.h" +#include "events/widgetevent.h" #include "linkpreviewer.h" #include "models/reactionmodel.h" #include "neochatconfig.h" @@ -432,22 +435,22 @@ QString EventHandler::getBody(const Quotient::RoomEvent *event, Qt::TextFormat f [](const RoomPowerLevelsEvent &) { return i18nc("'power level' means permission level", "changed the power levels for this room"); }, + [](const LocationBeaconEvent &e) { + return e.contentJson()["description"_ls].toString(); + }, + [](const ServerAclEvent &) { + return i18n("changed the server access control lists for this room"); + }, + [](const WidgetEvent &e) { + if (e.fullJson()["unsigned"_ls]["prev_content"_ls].toObject().isEmpty()) { + return i18nc("[User] added widget", "added %1 widget", e.contentJson()["name"_ls].toString()); + } + if (e.contentJson().isEmpty()) { + return i18nc("[User] removed widget", "removed %1 widget", e.fullJson()["unsigned"_ls]["prev_content"_ls]["name"_ls].toString()); + } + return i18nc("[User] configured widget", "configured %1 widget", e.contentJson()["name"_ls].toString()); + }, [prettyPrint](const StateEvent &e) { - if (e.matrixType() == QLatin1String("m.room.server_acl")) { - return i18n("changed the server access control lists for this room"); - } - if (e.matrixType() == QLatin1String("im.vector.modular.widgets")) { - if (e.fullJson()["unsigned"_ls]["prev_content"_ls].toObject().isEmpty()) { - return i18nc("[User] added widget", "added %1 widget", e.contentJson()["name"_ls].toString()); - } - if (e.contentJson().isEmpty()) { - return i18nc("[User] removed widget", "removed %1 widget", e.fullJson()["unsigned"_ls]["prev_content"_ls]["name"_ls].toString()); - } - return i18nc("[User] configured widget", "configured %1 widget", e.contentJson()["name"_ls].toString()); - } - if (e.matrixType() == "org.matrix.msc3672.beacon_info"_ls) { - return e.contentJson()["description"_ls].toString(); - } return e.stateKey().isEmpty() ? i18n("updated %1 state", e.matrixType()) : i18n("updated %1 state for %2", e.matrixType(), prettyPrint ? e.stateKey().toHtmlEscaped() : e.stateKey()); }, @@ -601,19 +604,22 @@ QString EventHandler::getGenericBody() const [](const RoomPowerLevelsEvent &) { return i18nc("'power level' means permission level", "changed the power levels for this room"); }, - [](const StateEvent &e) { - if (e.matrixType() == QLatin1String("m.room.server_acl")) { - return i18n("changed the server access control lists for this room"); + [](const LocationBeaconEvent &) { + return i18n("sent a live location beacon"); + }, + [](const ServerAclEvent &) { + return i18n("changed the server access control lists for this room"); + }, + [](const WidgetEvent &e) { + if (e.fullJson()["unsigned"_ls]["prev_content"_ls].toObject().isEmpty()) { + return i18n("added a widget"); } - if (e.matrixType() == QLatin1String("im.vector.modular.widgets")) { - if (e.fullJson()["unsigned"_ls]["prev_content"_ls].toObject().isEmpty()) { - return i18n("added a widget"); - } - if (e.contentJson().isEmpty()) { - return i18n("removed a widget"); - } - return i18n("configured a widget"); + if (e.contentJson().isEmpty()) { + return i18n("removed a widget"); } + return i18n("configured a widget"); + }, + [](const StateEvent &) { return i18n("updated the state"); }, [](const PollStartEvent &e) { diff --git a/src/events/locationbeaconevent.h b/src/events/locationbeaconevent.h new file mode 100644 index 000000000..8cb1231cb --- /dev/null +++ b/src/events/locationbeaconevent.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 James Graham +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + +#pragma once + +#include + +namespace Quotient +{ + +// Defined so we can directly switch on type. +DEFINE_SIMPLE_STATE_EVENT(LocationBeaconEvent, "org.matrix.msc3672.beacon_info", QString, body, "body") + +} // namespace Quotient diff --git a/src/events/serveraclevent.h b/src/events/serveraclevent.h new file mode 100644 index 000000000..f67f0cd19 --- /dev/null +++ b/src/events/serveraclevent.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 James Graham +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + +#pragma once + +#include + +namespace Quotient +{ + +// Defined so we can directly switch on type. +DEFINE_SIMPLE_STATE_EVENT(ServerAclEvent, "m.room.server_acl", bool, allow_ip_literals, "allow_ip_literals") + +} // namespace Quotient diff --git a/src/events/widgetevent.h b/src/events/widgetevent.h new file mode 100644 index 000000000..6cb04d3ec --- /dev/null +++ b/src/events/widgetevent.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 James Graham +// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + +#pragma once + +#include + +namespace Quotient +{ + +// Defined so we can directly switch on type. +DEFINE_SIMPLE_STATE_EVENT(WidgetEvent, "im.vector.modular.widgets", QString, name, "name") + +} // namespace Quotient