diff --git a/ddpRequests/rocketchatcreatechannelrequest.cpp b/ddpRequests/rocketchatcreatepublicgrouprequest.cpp similarity index 81% rename from ddpRequests/rocketchatcreatechannelrequest.cpp rename to ddpRequests/rocketchatcreatepublicgrouprequest.cpp index 36059d6f92893f33071899171a3c84290387e755..94e53d17e5442dc32bdf4daa6430703e53f551b4 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 58c00467a24b9b24f2543d1e10a073cf5ef6a443..e806911a97a2ca9d2519e0ffe3a60c2f7cc222ac 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 c2192bd2ae1d0e2db74291b0bd44f20787590046..6341f9762606032e21a6599ee4a60c5305093b8a 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 73175528760b3d8ccd653cd8fedf9e9fa2d22319..6142ea6fac5c8221146c5fbdee5cd9178052ddac 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 54c3136e3fc755b08e9ca6c1137e173ff9afcf6d..166c7705f40dd1799f02af95c0d26e2c79f1d6ac 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 e02cace088f6696acd948ed316b05e5595f2fb07..aed351770c5defcbdf351a2560b205874905af90 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 a7bd8fd03ab0cd12bf9be7709c7678964e7301db..18744ec78ff8ee81a5fc8f1623edfa58f063c398 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; };