From 6751d325c5682b8d627083ea6a774e3ba9e6f619 Mon Sep 17 00:00:00 2001 From: Armin <armin.felder@osalliance.com> Date: Wed, 3 Jan 2018 00:26:55 +0100 Subject: [PATCH] added support for RC 0.60 subscriptions --- config.h | 1 + ddpRequests/ddpsubscriptionrequest.cpp | 11 +++++++- engine.pro | 6 +++-- restRequests/getserverinforequest.cpp | 6 +++++ restRequests/getserverinforequest.h | 13 ++++++++++ restRequests/restpaths.cpp | 1 + restRequests/restpaths.h | 1 + rocketchatserver.cpp | 35 +++++++++++++++++++++----- rocketchatserver.h | 7 +++++- rocketchatserverconfig.cpp | 5 ++++ rocketchatserverconfig.h | 9 ++++--- 11 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 restRequests/getserverinforequest.cpp create mode 100644 restRequests/getserverinforequest.h diff --git a/config.h b/config.h index 946ff68..2cbfcc9 100755 --- a/config.h +++ b/config.h @@ -3,4 +3,5 @@ #define DBVERSION 1 + #endif // CONFIG_H diff --git a/ddpRequests/ddpsubscriptionrequest.cpp b/ddpRequests/ddpsubscriptionrequest.cpp index f423b2f..da6a374 100755 --- a/ddpRequests/ddpsubscriptionrequest.cpp +++ b/ddpRequests/ddpsubscriptionrequest.cpp @@ -21,6 +21,7 @@ #include "ddpsubscriptionrequest.h" +#include "../rocketchatserverconfig.h" DDPSubscriptionRequest::DDPSubscriptionRequest( const QString &pCollection, const QJsonArray &pParams ) { @@ -44,7 +45,15 @@ void DDPSubscriptionRequest::buildRequest( const QString &pCollection, const QJs QJsonObject obj; obj["useCollection"] = false; obj["args"] = args; - params.append( args ); + int major = std::get<0>( RocketChatServerConfig::serverVersion ); + int minor = std::get<1>( RocketChatServerConfig::serverVersion ); + int patch = std::get<2>( RocketChatServerConfig::serverVersion ); + + if ( major != -1 && minor != -1 && patch != -1 ) { + if ( major >= 0 && minor > 6 ) { + params.append( obj ); + } + } QJsonObject request; request["name"] = pCollection; diff --git a/engine.pro b/engine.pro index dc78573..d77ceb5 100644 --- a/engine.pro +++ b/engine.pro @@ -84,7 +84,8 @@ SOURCES += api/meteorddp.cpp \ CustomModels/messagemodel.cpp \ CustomModels/loginmethodsmodel.cpp \ repos/loginmethodsrepository.cpp \ - repos/entities/loginmethod.cpp + repos/entities/loginmethod.cpp \ + restRequests/getserverinforequest.cpp HEADERS += \ api/meteorddp.h \ @@ -169,7 +170,8 @@ HEADERS += \ CustomModels/messagemodel.h \ CustomModels/loginmethodsmodel.h \ repos/loginmethodsrepository.h \ - repos/entities/loginmethod.h + repos/entities/loginmethod.h \ + restRequests/getserverinforequest.h linux{ diff --git a/restRequests/getserverinforequest.cpp b/restRequests/getserverinforequest.cpp new file mode 100644 index 0000000..ac6475b --- /dev/null +++ b/restRequests/getserverinforequest.cpp @@ -0,0 +1,6 @@ +#include "getserverinforequest.h" + +GetServerInfoRequest::GetServerInfoRequest( const RestRequestCallback &pSuccess, const RestRequestCallback &pError ): GetRequest( RestPaths::apiServerInfo, pSuccess, pError ) +{ + +} diff --git a/restRequests/getserverinforequest.h b/restRequests/getserverinforequest.h new file mode 100644 index 0000000..dbabce0 --- /dev/null +++ b/restRequests/getserverinforequest.h @@ -0,0 +1,13 @@ +#ifndef GETSERVERINFOREQUEST_H +#define GETSERVERINFOREQUEST_H + +#include "getrequest.h" +#include "restpaths.h" + +class GetServerInfoRequest: public GetRequest +{ + public: + GetServerInfoRequest( const RestRequestCallback &pSuccess, const RestRequestCallback &pError ); +}; + +#endif // GETSERVERINFOREQUEST_H diff --git a/restRequests/restpaths.cpp b/restRequests/restpaths.cpp index 08ea3c8..f4d707a 100755 --- a/restRequests/restpaths.cpp +++ b/restRequests/restpaths.cpp @@ -31,3 +31,4 @@ const QString RestPaths::apiRoomMessages = "/channels.history"; const QString RestPaths::apiSendMessage = "/chat.postMessage"; const QString RestPaths::apiJoinedRooms = "/channels.list.joined"; const QString RestPaths::apiJoinedGroups = "/groups.list"; +const QString RestPaths::apiServerInfo = "/info"; diff --git a/restRequests/restpaths.h b/restRequests/restpaths.h index 3a6eece..b82d7f3 100755 --- a/restRequests/restpaths.h +++ b/restRequests/restpaths.h @@ -36,6 +36,7 @@ class RestPaths const static QString apiSendMessage; const static QString apiJoinedRooms; const static QString apiJoinedGroups; + const static QString apiServerInfo; }; #endif // RESTPATHS_H diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index be7345a..fb3bb72 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -64,7 +64,6 @@ RocketChatServerData::~RocketChatServerData() { qDebug() << "RocketChatServerData destructor start"; - delete mEmojiService; delete mFileService; qDebug() << "RocketChatServerData destructor end"; @@ -820,6 +819,7 @@ void RocketChatServerData::onDDPAuthenticated() getCustomEmojis(); setUserPresenceStatus( 1 ); mStorage->setSetting( "currentServer", mBaseUrl ); + getServerInfo(); if ( !mCurrentChannel.isEmpty() ) { joinChannel( mCurrentChannel ); @@ -1216,13 +1216,13 @@ void RocketChatServerData::joinJitsiCall( const QString &pRoomId ) { if ( Q_LIKELY( mChannels->contains( pRoomId ) ) ) { - QString hash = QCryptographicHash::hash( ( config.uniqueId + pRoomId ).toUtf8(), QCryptographicHash::Md5 ).toHex(); + QString hash = QCryptographicHash::hash( ( RocketChatServerConfig::uniqueId + pRoomId ).toUtf8(), QCryptographicHash::Md5 ).toHex(); #if defined(Q_OS_IOS) || defined(Q_OS_ANDROID) QString scheme = "org.jitsi.meet://"; #else QString scheme = "https://"; #endif - QString url = scheme + config.jitsiMeetUrl + "/" + config.jitsiMeetPrefix + hash; + QString url = scheme + RocketChatServerConfig::jitsiMeetUrl + "/" + RocketChatServerConfig::jitsiMeetPrefix + hash; qDebug() << url; emit openUrl( url ); } @@ -1290,15 +1290,15 @@ void RocketChatServerData::getServerSettings() QString value = currentConfObject["value"].toString(); if ( id == "uniqueID" ) { - config.uniqueId = value; + RocketChatServerConfig::uniqueId = value; } if ( id == "Jitsi_Domain" ) { - config.jitsiMeetUrl = value; + RocketChatServerConfig::jitsiMeetUrl = value; } if ( id == "Jitsi_URL_Room_Prefix" ) { - config.jitsiMeetPrefix = value; + RocketChatServerConfig::jitsiMeetPrefix = value; } } @@ -1612,6 +1612,29 @@ void RocketChatServerData::getLoginMethods() mDdpApi->sendRequest( loginMethodsSubscription ); } +void RocketChatServerData::getServerInfo() +{ + RestRequestCallback success = [ = ]( QNetworkReply * pReply, QJsonObject data, RestApi * pApi ) { + Q_UNUSED( pApi ); + Q_UNUSED( pReply ); + qDebug() << data; + + if ( data.contains( "info" ) ) { + QJsonObject info = data["info"].toObject(); + + if ( info.contains( "version" ) ) { + QString version = info["version"].toString(); + QStringList verParts = version.split( "." ); + std::get<0>( RocketChatServerConfig::serverVersion ) = verParts[0].toInt(); + std::get<1>( RocketChatServerConfig::serverVersion ) = verParts[1].toInt(); + std::get<2>( RocketChatServerConfig::serverVersion ) = verParts[2].toInt(); + } + } + }; + QSharedPointer<GetServerInfoRequest> serverInfoRequest( new GetServerInfoRequest( success, nullptr ) ); + mRestApi->sendRequest( serverInfoRequest ); +} + QList<QSharedPointer<RocketChatUser> > RocketChatServerData::getUserOfChannel( const QString &pChannelId ) { QList<QSharedPointer<RocketChatUser>> users; diff --git a/rocketchatserver.h b/rocketchatserver.h index 89c7d92..2e80b7c 100755 --- a/rocketchatserver.h +++ b/rocketchatserver.h @@ -65,6 +65,7 @@ #include "ddpRequests/ddpsamlloginrequest.h" #include "restRequests/restrequest.h" #include "restRequests/restlogoutrequest.h" +#include "restRequests/getserverinforequest.h" #include "fileuploader.h" #include "notifications/notifications.h" #include "services/rocketchatchannelservice.h" @@ -151,6 +152,8 @@ class RocketChatServerData : public QObject void getRoomInformation( const QString &pRoomName ); void getLoginMethods(); + void getServerInfo(); + void loadChannels(); void logout( void ); @@ -195,6 +198,8 @@ class RocketChatServerData : public QObject public: + + QString getServerId() const; bool isConnected() const; bool isWebsocketValid( void ) const; @@ -244,6 +249,7 @@ class RocketChatServerData : public QObject uint mTokenExpire = 0; QString mResumeToken; + MeteorDDP *mDdpApi = nullptr; RestApi *mRestApi = nullptr; UserRepository mUsers; @@ -251,7 +257,6 @@ class RocketChatServerData : public QObject ChannelRepository *mChannels = nullptr; EmojiRepo *mEmojiRepo = nullptr; QVariantMap mAutocompleteRecords; - RocketChatServerConfig config; bool mConnected = false; bool mLoggedIn = false; bool mResumeOperation = false; diff --git a/rocketchatserverconfig.cpp b/rocketchatserverconfig.cpp index 8c2f14a..2790381 100644 --- a/rocketchatserverconfig.cpp +++ b/rocketchatserverconfig.cpp @@ -21,6 +21,11 @@ #include "rocketchatserverconfig.h" +std::tuple<int, int, int> RocketChatServerConfig::serverVersion = std::make_tuple( -1, -1, -1 ); +QString RocketChatServerConfig::uniqueId; +QString RocketChatServerConfig::jitsiMeetUrl; +QString RocketChatServerConfig::jitsiMeetPrefix; + RocketChatServerConfig::RocketChatServerConfig() { diff --git a/rocketchatserverconfig.h b/rocketchatserverconfig.h index 4d932d3..2dd65a7 100644 --- a/rocketchatserverconfig.h +++ b/rocketchatserverconfig.h @@ -22,14 +22,17 @@ #ifndef ROCKETCHATSERVERCONFIG_H #define ROCKETCHATSERVERCONFIG_H #include <QString> +#include <tuple> class RocketChatServerConfig { public: RocketChatServerConfig(); - QString uniqueId; - QString jitsiMeetUrl; - QString jitsiMeetPrefix; + static QString uniqueId; + static QString jitsiMeetUrl; + static QString jitsiMeetPrefix; + static std::tuple<int, int, int> serverVersion; + }; #endif // ROCKETCHATSERVERCONFIG_H -- GitLab