Commit 4a59d1e9 authored by armin's avatar armin
Browse files

Merge branch 'messageSearch0.70Compat' into 'master'

fixes api change in 0.70 regarding messagesearch

See merge request !130
parents 2485fc00 77eeca37
...@@ -270,27 +270,46 @@ void MessageService::addChannelToBlockList( const QString &pId ) ...@@ -270,27 +270,46 @@ void MessageService::addChannelToBlockList( const QString &pId )
void MessageService::searchMessage( const QString &pTerm, const QString &pRoom ) void MessageService::searchMessage( const QString &pTerm, const QString &pRoom )
{ {
if ( mServer ) { if ( mServer ) {
DdpCallback ddpSuccess = [ = ]( const QJsonObject & pResponse, auto ddpSuccess = [ = ]( const QJsonObject & pResponse,
MeteorDDP * pDdp ) { MeteorDDP * pDdp ) {
Q_UNUSED( pDdp ) Q_UNUSED( pDdp )
if ( pResponse.contains( "result" ) ) { if ( pResponse.contains( "result" ) ) {
QJsonObject result = pResponse["result"].toObject(); QJsonObject result = pResponse["result"].toObject();
if ( result.contains( "messages" ) ) { auto major = std::get<0>( RocketChatServerConfig::serverVersion );
QJsonArray messagesArray = result["messages"].toArray(); auto minor = std::get<1>( RocketChatServerConfig::serverVersion );
auto patch = std::get<2>( RocketChatServerConfig::serverVersion );
MessageList messageList; MessageList messageList;
if ( major >= 0 && minor >= 70 ) {
if ( result.contains( "message" ) ) {
auto message = result["message"].toObject();
if ( message.contains( "docs" ) ) {
auto docs = message["docs"].toArray();
for ( const auto doc : docs ) {
messageList.append( parseMessage( doc.toObject() ) );
}
}
}
} else {
if ( result.contains( "messages" ) ) {
auto messagesArray = result["messages"].toArray();
for ( const auto message : messagesArray ) { for ( const auto message : messagesArray ) {
messageList.append( parseMessage( message.toObject() ) ); messageList.append( parseMessage( message.toObject() ) );
} }
}
}
if ( !messageList.isEmpty() ) { if ( !messageList.isEmpty() ) {
auto result = QMetaObject::invokeMethod( mSearchResults, "setSearchResults", Q_ARG( MessageList, messageList ) ); auto result = QMetaObject::invokeMethod( mSearchResults, "setSearchResults", Q_ARG( MessageList, messageList ) );
Q_ASSERT( result ); Q_ASSERT( result );
} }
} }
}
}; };
auto request = QSharedPointer<RocketChatMessageSearchRequest>::create( pTerm, pRoom ); auto request = QSharedPointer<RocketChatMessageSearchRequest>::create( pTerm, pRoom );
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
********************************************************************************************/ ********************************************************************************************/
#pragma once
#ifndef MESSAGESERVICE_H #ifndef MESSAGESERVICE_H
#define MESSAGESERVICE_H #define MESSAGESERVICE_H
...@@ -65,8 +65,8 @@ class MessageService : public QObject ...@@ -65,8 +65,8 @@ class MessageService : public QObject
void addUserToBlockList( const QString &pId ); void addUserToBlockList( const QString &pId );
void addChannelToBlockList( const QString &pId ); void addChannelToBlockList( const QString &pId );
void searchMessage( const QString &pTerm, const QString &pRoom ); void searchMessage( const QString &pTerm, const QString &pRoom );
void deleteMessagesNotInList(MessageMap *pMessages, QString pChannelId, bool pCheckForYounger); void deleteMessagesNotInList( MessageMap *pMessages, QString pChannelId, bool pCheckForYounger );
protected: protected:
QRegularExpression mReplyRegeEx; QRegularExpression mReplyRegeEx;
EmojiRepo *mEmojiRepo; EmojiRepo *mEmojiRepo;
MessagesModel *mMessagesModel; MessagesModel *mMessagesModel;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment