From 1529f46e6dd457d059fb7e6e9cd10fa0b0399553 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 20 Jul 2020 19:33:19 +0200 Subject: UriResolverBase::visitUser(): add return value To enable reporting when the action is incorrect. --- lib/uriresolver.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/uriresolver.cpp') 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 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 userHandler, + std::function userHandler, std::function roomEventHandler, std::function joinHandler, std::function 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); } -- cgit v1.2.3