Rework so that ActionsModel no longer depends on NeoChatConfig or RoomManager
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <Quotient/qt_connection_util.h>
|
#include <Quotient/qt_connection_util.h>
|
||||||
#include <Quotient/settings.h>
|
#include <Quotient/settings.h>
|
||||||
|
|
||||||
|
#include "models/actionsmodel.h"
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
@@ -62,6 +63,11 @@ Controller::Controller(QObject *parent)
|
|||||||
Q_EMIT globalUrlPreviewDefaultChanged();
|
Q_EMIT globalUrlPreviewDefaultChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
|
||||||
|
connect(NeoChatConfig::self(), &NeoChatConfig::AllowQuickEditChanged, this, []() {
|
||||||
|
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
|
||||||
|
});
|
||||||
|
|
||||||
ProxyController::instance().setApplicationProxy();
|
ProxyController::instance().setApplicationProxy();
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
|
|||||||
@@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "enums/messagetype.h"
|
#include "enums/messagetype.h"
|
||||||
#include "neochatconfig.h"
|
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
#include "roommanager.h"
|
|
||||||
#include <Quotient/events/eventcontent.h>
|
#include <Quotient/events/eventcontent.h>
|
||||||
#include <Quotient/events/roommemberevent.h>
|
#include <Quotient/events/roommemberevent.h>
|
||||||
#include <Quotient/events/roompowerlevelsevent.h>
|
#include <Quotient/events/roompowerlevelsevent.h>
|
||||||
@@ -20,6 +18,8 @@ using Action = ActionsModel::Action;
|
|||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
using namespace Qt::StringLiterals;
|
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,
|
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,
|
"#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,
|
"#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);
|
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
|
||||||
if (targetRoom) {
|
if (targetRoom) {
|
||||||
RoomManager::instance().resolveResource(targetRoom->id());
|
ActionsModel::instance().resolveResource(targetRoom->id());
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
Q_EMIT room->showMessage(MessageType::Information, i18nc("Joining room <roomname>.", "Joining room %1.", text));
|
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();
|
return QString();
|
||||||
},
|
},
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
@@ -251,16 +251,16 @@ QList<ActionsModel::Action> actions{
|
|||||||
}
|
}
|
||||||
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
|
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
|
||||||
if (targetRoom) {
|
if (targetRoom) {
|
||||||
RoomManager::instance().resolveResource(targetRoom->id());
|
ActionsModel::instance().resolveResource(targetRoom->id());
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
Q_EMIT room->showMessage(MessageType::Information, i18nc("Knocking room <roomname>.", "Knocking room %1.", text));
|
Q_EMIT room->showMessage(MessageType::Information, i18nc("Knocking room <roomname>.", "Knocking room %1.", text));
|
||||||
auto connection = dynamic_cast<NeoChatConnection *>(room->connection());
|
auto connection = dynamic_cast<NeoChatConnection *>(room->connection());
|
||||||
const auto knownServer = roomName.mid(roomName.indexOf(":"_L1) + 1);
|
const auto knownServer = roomName.mid(roomName.indexOf(":"_L1) + 1);
|
||||||
if (parts.length() >= 2) {
|
if (parts.length() >= 2) {
|
||||||
RoomManager::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});
|
ActionsModel::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});
|
||||||
} else {
|
} else {
|
||||||
RoomManager::instance().knockRoom(connection, roomName, QString(), QStringList{knownServer});
|
ActionsModel::instance().knockRoom(connection, roomName, QString(), QStringList{knownServer});
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
},
|
},
|
||||||
@@ -283,7 +283,7 @@ QList<ActionsModel::Action> actions{
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
Q_EMIT room->showMessage(MessageType::Information, i18nc("Joining room <roomname>.", "Joining room %1.", text));
|
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();
|
return QString();
|
||||||
},
|
},
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
@@ -553,7 +553,7 @@ bool ActionsModel::handleQuickEditAction(NeoChatRoom *room, const QString &messa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NeoChatConfig::allowQuickEdit()) {
|
if (m_allowQuickEdit) {
|
||||||
QRegularExpression sed(u"^s/([^/]*)/([^/]*)(/g)?$"_s);
|
QRegularExpression sed(u"^s/([^/]*)/([^/]*)(/g)?$"_s);
|
||||||
auto match = sed.match(messageText);
|
auto match = sed.match(messageText);
|
||||||
if (match.hasMatch()) {
|
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);
|
return std::make_pair(messageType.has_value() ? std::make_optional(sendText) : std::nullopt, messageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActionsModel::setAllowQuickEdit(bool allow)
|
||||||
|
{
|
||||||
|
m_allowQuickEdit = allow;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <Quotient/events/roommessageevent.h>
|
#include <Quotient/events/roommessageevent.h>
|
||||||
|
|
||||||
class ChatBarCache;
|
class ChatBarCache;
|
||||||
|
class NeoChatConnection;
|
||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,6 +21,8 @@ class NeoChatRoom;
|
|||||||
*/
|
*/
|
||||||
class ActionsModel : public QAbstractListModel
|
class ActionsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Definition of an action.
|
* @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 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:
|
private:
|
||||||
ActionsModel() = default;
|
ActionsModel() = default;
|
||||||
|
|
||||||
|
static bool m_allowQuickEdit;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "eventhandler.h"
|
#include "eventhandler.h"
|
||||||
|
#include "models/actionsmodel.h"
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
@@ -67,6 +68,10 @@ RoomManager::RoomManager(QObject *parent)
|
|||||||
m_roomTreeModel->setConnection(m_connection);
|
m_roomTreeModel->setConnection(m_connection);
|
||||||
});
|
});
|
||||||
connect(m_sortFilterSpaceListModel, &SortFilterSpaceListModel::layoutChanged, m_sortFilterRoomTreeModel, &SortFilterRoomTreeModel::invalidate);
|
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()
|
RoomManager::~RoomManager()
|
||||||
|
|||||||
Reference in New Issue
Block a user