Rework so that ActionsModel no longer depends on NeoChatConfig or RoomManager

This commit is contained in:
James Graham
2025-04-06 12:59:07 +01:00
parent 0403ecbd70
commit 8327b4369e
4 changed files with 43 additions and 9 deletions

View File

@@ -18,6 +18,7 @@
#include <Quotient/qt_connection_util.h>
#include <Quotient/settings.h>
#include "models/actionsmodel.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
@@ -62,6 +63,11 @@ Controller::Controller(QObject *parent)
Q_EMIT globalUrlPreviewDefaultChanged();
});
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
connect(NeoChatConfig::self(), &NeoChatConfig::AllowQuickEditChanged, this, []() {
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
});
ProxyController::instance().setApplicationProxy();
#ifndef Q_OS_ANDROID

View File

@@ -5,10 +5,8 @@
#include "chatbarcache.h"
#include "enums/messagetype.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
#include "roommanager.h"
#include <Quotient/events/eventcontent.h>
#include <Quotient/events/roommemberevent.h>
#include <Quotient/events/roompowerlevelsevent.h>
@@ -20,6 +18,8 @@ using Action = ActionsModel::Action;
using namespace Quotient;
using namespace Qt::StringLiterals;
bool ActionsModel::m_allowQuickEdit = false;
QStringList rainbowColors{"#ff2b00"_L1, "#ff5500"_L1, "#ff8000"_L1, "#ffaa00"_L1, "#ffd500"_L1, "#ffff00"_L1, "#d4ff00"_L1, "#aaff00"_L1, "#80ff00"_L1,
"#55ff00"_L1, "#2bff00"_L1, "#00ff00"_L1, "#00ff2b"_L1, "#00ff55"_L1, "#00ff80"_L1, "#00ffaa"_L1, "#00ffd5"_L1, "#00ffff"_L1,
"#00d4ff"_L1, "#00aaff"_L1, "#007fff"_L1, "#0055ff"_L1, "#002bff"_L1, "#0000ff"_L1, "#2a00ff"_L1, "#5500ff"_L1, "#7f00ff"_L1,
@@ -226,11 +226,11 @@ QList<ActionsModel::Action> actions{
}
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
if (targetRoom) {
RoomManager::instance().resolveResource(targetRoom->id());
ActionsModel::instance().resolveResource(targetRoom->id());
return QString();
}
Q_EMIT room->showMessage(MessageType::Information, i18nc("Joining room <roomname>.", "Joining room %1.", text));
RoomManager::instance().resolveResource(text, "join"_L1);
ActionsModel::instance().resolveResource(text, "join"_L1);
return QString();
},
std::nullopt,
@@ -251,16 +251,16 @@ QList<ActionsModel::Action> actions{
}
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
if (targetRoom) {
RoomManager::instance().resolveResource(targetRoom->id());
ActionsModel::instance().resolveResource(targetRoom->id());
return QString();
}
Q_EMIT room->showMessage(MessageType::Information, i18nc("Knocking room <roomname>.", "Knocking room %1.", text));
auto connection = dynamic_cast<NeoChatConnection *>(room->connection());
const auto knownServer = roomName.mid(roomName.indexOf(":"_L1) + 1);
if (parts.length() >= 2) {
RoomManager::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});
ActionsModel::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});
} else {
RoomManager::instance().knockRoom(connection, roomName, QString(), QStringList{knownServer});
ActionsModel::instance().knockRoom(connection, roomName, QString(), QStringList{knownServer});
}
return QString();
},
@@ -283,7 +283,7 @@ QList<ActionsModel::Action> actions{
return QString();
}
Q_EMIT room->showMessage(MessageType::Information, i18nc("Joining room <roomname>.", "Joining room %1.", text));
RoomManager::instance().resolveResource(text, "join"_L1);
ActionsModel::instance().resolveResource(text, "join"_L1);
return QString();
},
std::nullopt,
@@ -553,7 +553,7 @@ bool ActionsModel::handleQuickEditAction(NeoChatRoom *room, const QString &messa
return false;
}
if (NeoChatConfig::allowQuickEdit()) {
if (m_allowQuickEdit) {
QRegularExpression sed(u"^s/([^/]*)/([^/]*)(/g)?$"_s);
auto match = sed.match(messageText);
if (match.hasMatch()) {
@@ -618,3 +618,8 @@ std::pair<std::optional<QString>, std::optional<Quotient::RoomMessageEvent::MsgT
return std::make_pair(messageType.has_value() ? std::make_optional(sendText) : std::nullopt, messageType);
}
void ActionsModel::setAllowQuickEdit(bool allow)
{
m_allowQuickEdit = allow;
}

View File

@@ -8,6 +8,7 @@
#include <Quotient/events/roommessageevent.h>
class ChatBarCache;
class NeoChatConnection;
class NeoChatRoom;
/**
@@ -20,6 +21,8 @@ class NeoChatRoom;
*/
class ActionsModel : public QAbstractListModel
{
Q_OBJECT
public:
/**
* @brief Definition of an action.
@@ -97,6 +100,21 @@ public:
*/
static std::pair<std::optional<QString>, std::optional<Quotient::RoomMessageEvent::MsgType>> handleAction(NeoChatRoom *room, ChatBarCache *chatBarCache);
static void setAllowQuickEdit(bool allow);
Q_SIGNALS:
/**
* @brief Request a resource is resolved.
*/
void resolveResource(const QString &idOrUri, const QString &action = {});
/**
* @brief Request a room Knock.
*/
void knockRoom(NeoChatConnection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers);
private:
ActionsModel() = default;
static bool m_allowQuickEdit;
};

View File

@@ -7,6 +7,7 @@
#include "chatbarcache.h"
#include "controller.h"
#include "eventhandler.h"
#include "models/actionsmodel.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
@@ -67,6 +68,10 @@ RoomManager::RoomManager(QObject *parent)
m_roomTreeModel->setConnection(m_connection);
});
connect(m_sortFilterSpaceListModel, &SortFilterSpaceListModel::layoutChanged, m_sortFilterRoomTreeModel, &SortFilterRoomTreeModel::invalidate);
connect(&ActionsModel::instance(), &ActionsModel::resolveResource, this, [this](const QString &idOrUri, const QString &action) {
resolveResource(idOrUri, action);
});
connect(&ActionsModel::instance(), &ActionsModel::knockRoom, this, &RoomManager::knockRoom);
}
RoomManager::~RoomManager()