Add knock command
This commit is contained in:
committed by
Tobias Fella
parent
a1abf22174
commit
e1b9bc7d0e
@@ -209,6 +209,40 @@ QVector<ActionsModel::Action> actions{
|
|||||||
kli18n("<room alias or id>"),
|
kli18n("<room alias or id>"),
|
||||||
kli18n("Joins the given room"),
|
kli18n("Joins the given room"),
|
||||||
},
|
},
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
Action{
|
||||||
|
QStringLiteral("knock"),
|
||||||
|
[](const QString &text, NeoChatRoom *room) {
|
||||||
|
auto parts = text.split(QLatin1String(" "));
|
||||||
|
QString roomName = parts[0];
|
||||||
|
QRegularExpression roomRegex(QStringLiteral(R"(^[#!][^:]+:\w(?:\w|\.|-)*\.\w+(?::\d{1,5})?)"));
|
||||||
|
auto regexMatch = roomRegex.match(roomName);
|
||||||
|
if (!regexMatch.hasMatch()) {
|
||||||
|
Q_EMIT room->showMessage(NeoChatRoom::Error,
|
||||||
|
i18nc("'<text>' does not look like a room id or alias.", "'%1' does not look like a room id or alias.", text));
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
auto targetRoom = text.startsWith(QLatin1Char('!')) ? room->connection()->room(text) : room->connection()->roomByAlias(text);
|
||||||
|
if (targetRoom) {
|
||||||
|
RoomManager::instance().enterRoom(dynamic_cast<NeoChatRoom *>(targetRoom));
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc("Knocking room <roomname>.", "Knocking room %1.", text));
|
||||||
|
auto connection = Controller::instance().activeConnection();
|
||||||
|
const auto knownServer = roomName.mid(roomName.indexOf(":") + 1);
|
||||||
|
if (parts.length() >= 2) {
|
||||||
|
RoomManager::instance().knockRoom(connection, roomName, parts[1], QStringList{knownServer});
|
||||||
|
} else {
|
||||||
|
RoomManager::instance().knockRoom(connection, roomName, QString(), QStringList{knownServer});
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
std::nullopt,
|
||||||
|
kli18n("<room alias or id> [<reason>]"),
|
||||||
|
kli18n("Requests to join the given room"),
|
||||||
|
},
|
||||||
|
#endif
|
||||||
Action{
|
Action{
|
||||||
QStringLiteral("j"),
|
QStringLiteral("j"),
|
||||||
[](const QString &text, NeoChatRoom *room) {
|
[](const QString &text, NeoChatRoom *room) {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
#include <QQuickTextDocument>
|
#include <QQuickTextDocument>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <csapi/joining.h>
|
#include <csapi/joining.h>
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
#include <csapi/knocking.h>
|
||||||
|
#endif
|
||||||
#include <qt_connection_util.h>
|
#include <qt_connection_util.h>
|
||||||
#include <user.h>
|
#include <user.h>
|
||||||
|
|
||||||
@@ -209,6 +212,27 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: maybe need use the function upstream later
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers)
|
||||||
|
{
|
||||||
|
auto *const job = account->callApi<KnockRoomJob>(roomAliasOrId, viaServers, reason);
|
||||||
|
// Upon completion, ensure a room object is created in case it hasn't come
|
||||||
|
// with a sync yet. If the room object is not there, provideRoom() will
|
||||||
|
// create it in Join state. finished() is used here instead of success()
|
||||||
|
// to overtake clients that may add their own slots to finished().
|
||||||
|
connectSingleShot(job, &BaseJob::finished, this, [this, job, account] {
|
||||||
|
if (job->status() == Quotient::BaseJob::Success) {
|
||||||
|
connectSingleShot(account, &Quotient::Connection::newRoom, this, [this](Quotient::Room *room) {
|
||||||
|
Q_EMIT currentRoom()->showMessage(NeoChatRoom::Info, i18n("You requested to join '%1'", room->name()));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Q_EMIT warning(i18n("Failed to request joining room"), job->errorString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool RoomManager::visitNonMatrix(const QUrl &url)
|
bool RoomManager::visitNonMatrix(const QUrl &url)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ public:
|
|||||||
// Overrided methods from UriResolverBase
|
// Overrided methods from UriResolverBase
|
||||||
UriResolveResult visitUser(User *user, const QString &action) override;
|
UriResolveResult visitUser(User *user, const QString &action) override;
|
||||||
void joinRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QStringList &viaServers) override;
|
void joinRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QStringList &viaServers) override;
|
||||||
|
// TODO: it need also override in the feature?
|
||||||
|
#ifdef QUOTIENT_07
|
||||||
|
void knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers);
|
||||||
|
#endif
|
||||||
Q_INVOKABLE void visitRoom(Quotient::Room *room, const QString &eventId) override;
|
Q_INVOKABLE void visitRoom(Quotient::Room *room, const QString &eventId) override;
|
||||||
Q_INVOKABLE bool visitNonMatrix(const QUrl &url) override;
|
Q_INVOKABLE bool visitNonMatrix(const QUrl &url) override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user