From ca89688eb5f1c05752f0494eb1cdc2ecd550bdba Mon Sep 17 00:00:00 2001 From: Armin Felder <armin.felder@osalliance.com> Date: Thu, 27 Sep 2018 21:35:16 +0200 Subject: [PATCH] refactored create public group --- ...=> rocketchatcreatepublicgrouprequest.cpp} | 6 ++-- ...h => rocketchatcreatepublicgrouprequest.h} | 6 ++-- engine.pro | 8 ++--- rocketchat.cpp | 2 -- rocketchat.h | 2 +- rocketchatserver.cpp | 36 ++++++++++++------- rocketchatserver.h | 4 +-- 7 files changed, 37 insertions(+), 27 deletions(-) rename ddpRequests/{rocketchatcreatechannelrequest.cpp => rocketchatcreatepublicgrouprequest.cpp} (81%) rename ddpRequests/{rocketchatcreatechannelrequest.h => rocketchatcreatepublicgrouprequest.h} (84%) diff --git a/ddpRequests/rocketchatcreatechannelrequest.cpp b/ddpRequests/rocketchatcreatepublicgrouprequest.cpp similarity index 81% rename from ddpRequests/rocketchatcreatechannelrequest.cpp rename to ddpRequests/rocketchatcreatepublicgrouprequest.cpp index 36059d6..94e53d1 100755 --- a/ddpRequests/rocketchatcreatechannelrequest.cpp +++ b/ddpRequests/rocketchatcreatepublicgrouprequest.cpp @@ -19,9 +19,9 @@ ********************************************************************************************/ -#include "rocketchatcreatechannelrequest.h" +#include "rocketchatcreatepublicgrouprequest.h" -RocketChatCreateChannelRequest::RocketChatCreateChannelRequest( const QString &pChannelName, const QStringList &pUserName, bool pReadonly, const DdpCallback &pSuccess ) +RocketChatCreatePublicGroupRequest::RocketChatCreatePublicGroupRequest( const QString &pChannelName, const QStringList &pUserName, bool pReadonly, const DdpCallback &pSuccess ) { QJsonArray users = QJsonArray::fromStringList( pUserName ); QJsonArray params = {pChannelName, users, pReadonly}; @@ -29,7 +29,7 @@ RocketChatCreateChannelRequest::RocketChatCreateChannelRequest( const QString &p setSuccess( pSuccess ); } -RocketChatCreateChannelRequest::RocketChatCreateChannelRequest( const QString &pChannelName, const QStringList &pUserNames, const DdpCallback &pSuccess ): RocketChatCreateChannelRequest( pChannelName, pUserNames, false, pSuccess ) +RocketChatCreatePublicGroupRequest::RocketChatCreatePublicGroupRequest( const QString &pChannelName, const QStringList &pUserNames, const DdpCallback &pSuccess ): RocketChatCreatePublicGroupRequest( pChannelName, pUserNames, false, pSuccess ) { } diff --git a/ddpRequests/rocketchatcreatechannelrequest.h b/ddpRequests/rocketchatcreatepublicgrouprequest.h similarity index 84% rename from ddpRequests/rocketchatcreatechannelrequest.h rename to ddpRequests/rocketchatcreatepublicgrouprequest.h index 58c0046..e806911 100755 --- a/ddpRequests/rocketchatcreatechannelrequest.h +++ b/ddpRequests/rocketchatcreatepublicgrouprequest.h @@ -24,11 +24,11 @@ #include "ddpmethodrequest.h" -class RocketChatCreateChannelRequest : public DDPMethodRequest +class RocketChatCreatePublicGroupRequest : public DDPMethodRequest { public: - RocketChatCreateChannelRequest( const QString &pChannelName, const QStringList &pUserNames, bool pReadonly, const DdpCallback &pSuccess = nullptr ); - RocketChatCreateChannelRequest( const QString &pChannelName, const QStringList &pUserNames, const DdpCallback &pSuccess = nullptr ); + RocketChatCreatePublicGroupRequest( const QString &pChannelName, const QStringList &pUserNames, bool pReadonly, const DdpCallback &pSuccess = nullptr ); + RocketChatCreatePublicGroupRequest( const QString &pChannelName, const QStringList &pUserNames, const DdpCallback &pSuccess = nullptr ); }; #endif // ROCKETCHATCREATECHANNELREQUEST_H diff --git a/engine.pro b/engine.pro index c2192bd..6341f97 100644 --- a/engine.pro +++ b/engine.pro @@ -18,7 +18,6 @@ SOURCES += api/meteorddp.cpp \ ddpRequests/rocketchatnotifynoticesrequest.cpp \ ddpRequests/rocketchatsubscriptionchangedrequest.cpp \ ddpRequests/rocketchatmarkchannelasreadrequest.cpp \ - ddpRequests/rocketchatcreatechannelrequest.cpp \ ddpRequests/ddpunsubscriptionrequest.cpp \ ddpRequests/rocketchatcreateprivategrouprequest.cpp \ ddpRequests/rocketchatadduserstochannel.cpp \ @@ -100,7 +99,8 @@ SOURCES += api/meteorddp.cpp \ ddpRequests/rocketchatjoinroomrequest.cpp \ ddpRequests/rocketchatgetroomidbynameorid.cpp \ ddpRequests/rocketchatspotlightrequest.cpp \ - repos/entities/rocketchatreplymessage.cpp + repos/entities/rocketchatreplymessage.cpp \ + ddpRequests/rocketchatcreatepublicgrouprequest.cpp HEADERS += \ @@ -118,7 +118,6 @@ HEADERS += \ ddpRequests/rocketchatnotifynoticesrequest.h \ ddpRequests/rocketchatsubscriptionchangedrequest.h \ ddpRequests/rocketchatmarkchannelasreadrequest.h \ - ddpRequests/rocketchatcreatechannelrequest.h \ ddpRequests/ddpunsubscriptionrequest.h \ ddpRequests/rocketchatcreateprivategrouprequest.h \ ddpRequests/rocketchatadduserstochannel.h \ @@ -204,7 +203,8 @@ HEADERS += \ ddpRequests/rocketchatgetroomidbynameorid.h \ ddpRequests/rocketchatspotlightrequest.h \ api/messagelistener.h \ - repos/entities/rocketchatreplymessage.h + repos/entities/rocketchatreplymessage.h \ + ddpRequests/rocketchatcreatepublicgrouprequest.h linux{ diff --git a/rocketchat.cpp b/rocketchat.cpp index 7317552..6142ea6 100755 --- a/rocketchat.cpp +++ b/rocketchat.cpp @@ -41,8 +41,6 @@ /** * @brief RocketChat::RocketChat - * @param restApi - * @param ddp */ RocketChat::RocketChat( QGuiApplication *app ) { diff --git a/rocketchat.h b/rocketchat.h index 54c3136..166c770 100755 --- a/rocketchat.h +++ b/rocketchat.h @@ -75,7 +75,7 @@ class RocketChat : public QObject Q_INVOKABLE void openFileDialog( const QString &pChannelId ); Q_INVOKABLE void resetCurrentChannel( void ); Q_INVOKABLE void logout( const QString &pServer ); - Q_INVOKABLE void createChannel( const QString &pServerId, const QString &pChannelName, + Q_INVOKABLE void createPublicGroup( const QString &pServerId, const QString &pChannelName, const QStringList &pUsersNames, bool pReadonly = false ); Q_INVOKABLE void createPrivateGroup( const QString &pServerId, const QString &pChannelName, const QStringList &pUsersNames, bool pReadonly = false ); diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index e02cace..aed3517 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -84,7 +84,7 @@ void RocketChatServerData::init() QMetaObject::invokeMethod( mRestApi, "init" ); - mDdpApi->registerMessageHandler(this); + mDdpApi->registerMessageHandler( this ); connect( mDdpApi, &MeteorDDP::ddpConnected, this, &RocketChatServerData::onDDPConnected, Qt::UniqueConnection ); connect( mDdpApi, &MeteorDDP::ddpDisconnected, this, &RocketChatServerData::onDDPDisonnected, Qt::UniqueConnection ); @@ -522,10 +522,10 @@ void RocketChatServerData::onUnreadCountChanged() emit unreadCountChanged( QStringLiteral( "default" ), number ); } -bool RocketChatServerData::handlesMessage(QJsonObject message) +bool RocketChatServerData::handlesMessage( QJsonObject message ) { qDebug() << "RocketChatServerData message handler"; - onDDPMessageReceived(message); + onDDPMessageReceived( message ); return true; } @@ -559,11 +559,13 @@ void RocketChatServerData::offlineLogin() QString RocketChatServerData::getBaseUrl() const { - QString protocol ="https://"; - if(mDdpApi->getUnsecure()){ - protocol ="http://"; + QString protocol = "https://"; + + if ( mDdpApi->getUnsecure() ) { + protocol = "http://"; } - return protocol+mBaseUrl; + + return protocol + mBaseUrl; } QVariantList RocketChatServerData::getEmojisByCategory() const @@ -1952,25 +1954,35 @@ void RocketChatServerData::logout() emit loggedOut( this->mServerId ); } -void RocketChatServerData::createChannel( const QString &pChannelName, const QStringList &pUsers, bool pReadonly ) +void RocketChatServerData::createPublicGroup( const QString &pChannelName, const QStringList &pUsers, bool pReadonly ) { DdpCallback success = [ = ]( QJsonObject pResponse, MeteorDDP * pDdpApi ) { Q_UNUSED( pResponse ); Q_UNUSED( pDdpApi ); qDebug() << "created channel"; + + if ( pResponse.contains( "result" ) ) { + QJsonObject result = pResponse["result"].toObject(); + + if ( result.contains( "rid" ) && result.contains( "name" ) ) { + QString rid = result["rid"].toString(); + QString name = result["name"].toString(); + switchChannel( "default", rid, name, "c" ); + } + } }; - QSharedPointer<RocketChatCreateChannelRequest> request( new RocketChatCreateChannelRequest( pChannelName, pUsers, pReadonly ) ); + QSharedPointer<RocketChatCreatePublicGroupRequest> request( new RocketChatCreatePublicGroupRequest( pChannelName, pUsers, pReadonly ) ); mDdpApi->sendRequest( request ); } void RocketChatServerData::createPrivateGroup( const QString &pChannelName, const QStringList &pUsers, bool pReadonly ) { - DdpCallback success = [ = ]( QJsonObject response, MeteorDDP * ddpApi ) { + DdpCallback success = [ = ]( QJsonObject pResponse, MeteorDDP * ddpApi ) { Q_UNUSED( ddpApi ); qDebug() << "created group"; - if ( response.contains( "result" ) ) { - QJsonObject result = response["result"].toObject(); + if ( pResponse.contains( "result" ) ) { + QJsonObject result = pResponse["result"].toObject(); if ( result.contains( "rid" ) && result.contains( "name" ) ) { QString rid = result["rid"].toString(); diff --git a/rocketchatserver.h b/rocketchatserver.h index a7bd8fd..18744ec 100755 --- a/rocketchatserver.h +++ b/rocketchatserver.h @@ -351,8 +351,8 @@ class RocketChatServerData : public MessageListener void historyReady(); // MessageListener interface -public: - bool handlesMessage(QJsonObject object); + public: + bool handlesMessage( QJsonObject object ); QString getBaseUrl() const; }; -- GitLab