aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-07-20 19:33:19 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-07-20 19:33:19 +0200
commit1529f46e6dd457d059fb7e6e9cd10fa0b0399553 (patch)
treedc871ac1d088d0aade4b508807e34841a7c3f889 /lib
parentaf329351289606f3cb1ef865cb0cbe61c1d1711b (diff)
downloadlibquotient-1529f46e6dd457d059fb7e6e9cd10fa0b0399553.tar.gz
libquotient-1529f46e6dd457d059fb7e6e9cd10fa0b0399553.zip
UriResolverBase::visitUser(): add return value
To enable reporting when the action is incorrect.
Diffstat (limited to 'lib')
-rw-r--r--lib/uriresolver.cpp18
-rw-r--r--lib/uriresolver.h18
2 files changed, 22 insertions, 14 deletions
diff --git a/lib/uriresolver.cpp b/lib/uriresolver.cpp
index 5052890b..ec30512c 100644
--- a/lib/uriresolver.cpp
+++ b/lib/uriresolver.cpp
@@ -6,7 +6,7 @@
using namespace Quotient;
UriResolveResult UriResolverBase::visitResource(Connection* account,
- const Uri& uri)
+ const Uri& uri)
{
switch (uri.type()) {
case Uri::NonMatrix:
@@ -26,8 +26,7 @@ UriResolveResult UriResolverBase::visitResource(Connection* account,
return IncorrectAction;
auto* user = account->user(uri.primaryId());
Q_ASSERT(user != nullptr);
- visitUser(user, uri.action());
- return UriResolved;
+ return visitUser(user, uri.action());
}
case Uri::RoomId:
case Uri::RoomAlias: {
@@ -49,15 +48,16 @@ UriResolveResult UriResolverBase::visitResource(Connection* account,
}
}
+// This template is only instantiated once, for Quotient::visitResource()
template <typename... FnTs>
class StaticUriDispatcher : public UriResolverBase {
public:
StaticUriDispatcher(const FnTs&... fns) : fns_(fns...) {}
private:
- void visitUser(User* user, const QString& action) override
+ UriResolveResult visitUser(User* user, const QString& action) override
{
- std::get<0>(fns_)(user, action);
+ return std::get<0>(fns_)(user, action);
}
void visitRoom(Room* room, const QString& eventId) override
{
@@ -78,7 +78,7 @@ private:
UriResolveResult Quotient::visitResource(
Connection* account, const Uri& uri,
- std::function<void(User*, QString)> userHandler,
+ std::function<UriResolveResult(User*, QString)> userHandler,
std::function<void(Room*, QString)> roomEventHandler,
std::function<void(Connection*, QString, QStringList)> joinHandler,
std::function<bool(const QUrl&)> nonMatrixHandler)
@@ -88,9 +88,10 @@ UriResolveResult Quotient::visitResource(
.visitResource(account, uri);
}
-void UriDispatcher::visitUser(User *user, const QString &action)
+UriResolveResult UriDispatcher::visitUser(User *user, const QString &action)
{
emit userAction(user, action);
+ return UriResolved;
}
void UriDispatcher::visitRoom(Room *room, const QString &eventId)
@@ -98,7 +99,8 @@ void UriDispatcher::visitRoom(Room *room, const QString &eventId)
emit roomAction(room, eventId);
}
-void UriDispatcher::joinRoom(Connection *account, const QString &roomAliasOrId, const QStringList &viaServers)
+void UriDispatcher::joinRoom(Connection* account, const QString& roomAliasOrId,
+ const QStringList& viaServers)
{
emit joinAction(account, roomAliasOrId, viaServers);
}
diff --git a/lib/uriresolver.h b/lib/uriresolver.h
index 914ddf02..9b2ced9d 100644
--- a/lib/uriresolver.h
+++ b/lib/uriresolver.h
@@ -40,7 +40,14 @@ public:
protected:
/// Called by visitResource() when the passed URI identifies a Matrix user
- virtual void visitUser(User* user, const QString& action) {}
+ /*!
+ * \return IncorrectAction if the action is not correct or not supported;
+ * UriResolved if it is accepted; other values are disallowed
+ */
+ virtual UriResolveResult visitUser(User* user, const QString& action)
+ {
+ return IncorrectAction;
+ }
/// Called by visitResource() when the passed URI identifies a room or
/// an event in a room
virtual void visitRoom(Room* room, const QString& eventId) {}
@@ -88,17 +95,16 @@ protected:
*/
UriResolveResult
visitResource(Connection* account, const Uri& uri,
- std::function<void(User*, QString)> userHandler,
+ std::function<UriResolveResult(User*, QString)> userHandler,
std::function<void(Room*, QString)> roomEventHandler,
std::function<void(Connection*, QString, QStringList)> joinHandler,
std::function<bool(const QUrl&)> nonMatrixHandler);
/*! \brief Check that the resource is resolvable with no action on it */
-inline UriResolveResult checkResource(Connection* account,
- const Uri& uri)
+inline UriResolveResult checkResource(Connection* account, const Uri& uri)
{
return visitResource(
- account, uri, [](auto, auto) {}, [](auto, auto) {},
+ account, uri, [](auto, auto) { return UriResolved; }, [](auto, auto) {},
[](auto, auto, auto) {}, [](auto) { return false; });
}
@@ -150,7 +156,7 @@ signals:
void nonMatrixAction(QUrl url);
private:
- void visitUser(User* user, const QString& action) override;
+ UriResolveResult visitUser(User* user, const QString& action) override;
void visitRoom(Room* room, const QString& eventId) override;
void joinRoom(Connection* account, const QString& roomAliasOrId,
const QStringList& viaServers = {}) override;