diff --git a/config.h b/config.h index 946ff687f070f9f5bfd09578c754bb14b0385bd9..2cbfcc90d6efb4d8c0829931b10287232d93ba90 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 f423b2f503513c841830a5fa166a4b77e06bf3f6..da6a374a59d9124c47d34868cfde1c692b01f58f 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 dc78573139b2b7ce38bb92f713d3d0f4c0eb11bd..d77ceb550240b66c9cc859275ef742db4e72a740 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 0000000000000000000000000000000000000000..ac6475b028bfdb9a6fb9f4910e36328a72fa248d --- /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 0000000000000000000000000000000000000000..dbabce0b2578ab94a9950b668e3396554435e7ce --- /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 08ea3c8a58c57190e81a5ba0d9fe9146812bfd52..f4d707a097ad9f6092610a45f88c62fef7ba9aff 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 3a6eece3f72715f88b24940685a739de99cafd14..b82d7f37a58f34af84e3e1df0eeb3e13a565ec7b 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 be7345a73a84775d9d3eb03ce4470105201d433f..fb3bb72d828eae95cae57c5f1bf5f2c396686512 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 89c7d92e7e5d5aa0019fc0bdea5af9953372aed8..2e80b7cc325ed71ab7bdac4bbe6b7d098d61bc9b 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 8c2f14a3e171dba84bd49a3b3351bd6a20a69886..2790381c9219752fa0d97978a59da7f7a559406e 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 4d932d314ccc2a022040600c78a003a87db6c2ca..2dd65a75e5ae8fcf1388f56fe4c00fd18ba9f4df 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