diff --git a/services/rocketchatchannelservice.cpp b/services/rocketchatchannelservice.cpp index 147b46629ab5209be2c69fe74dbd949b43558570..1a03a9f9d8bea9035d216d02e37aacd4a62a47ea 100755 --- a/services/rocketchatchannelservice.cpp +++ b/services/rocketchatchannelservice.cpp @@ -50,7 +50,7 @@ QSharedPointer<RocketChatChannel> RocketChatChannelService::createChannelObject( } -QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChannelData( QJsonArray pChannelArray, bool pJoined ) +QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processChannelData( QJsonArray pChannelArray, bool pJoined, bool pUpdateOnly ) { QVector<QSharedPointer<RocketChatChannel> > vec; @@ -72,7 +72,15 @@ QVector<QSharedPointer<RocketChatChannel> > RocketChatChannelService::processCha if ( id == "" ) { id = currentChannelObject["_id"].toString(); } - + //TODO: refactor me please! + if(pUpdateOnly && !mChannels->contains(id)){ + continue; + } + if(currentChannelObject.contains("open")&&!currentChannelObject["open"].toBool()){ + mChannels->remove(id); + mStorage->deleteChannel(id); + continue; + } QSharedPointer<RocketChatChannel> channel = nullptr; if ( mChannels->contains( id ) ) { @@ -159,7 +167,16 @@ void RocketChatChannelService::loadJoinedChannelsFromServer( void ) if ( Q_LIKELY( pResponse.contains( "result" ) ) ) { QJsonArray channels = pResponse["result"].toArray(); - auto channelsParsed = processChannelData( channels, true ); + auto channelsParsed = processChannelData( channels, true, false ); + emit channelsLoaded( channelsParsed, true ); + } + }; + std::function<void ( QJsonObject, MeteorDDP * )> roomsSuccess = [ = ]( QJsonObject pResponse, MeteorDDP * pDdpApi ) { + Q_UNUSED( pDdpApi ); + + if ( Q_LIKELY( pResponse.contains( "result" ) ) ) { + QJsonArray channels = pResponse["result"].toArray(); + auto channelsParsed = processChannelData( channels, true, true ); auto channelsLocal = mChannels->getElements(); @@ -182,7 +199,7 @@ void RocketChatChannelService::loadJoinedChannelsFromServer( void ) }; QSharedPointer<DDPRequest> subscriptions( new DDPMethodRequest( "subscriptions/get", {}, [ = ]( QJsonObject pResponse, MeteorDDP * pDdpApi ) { subscriptionSuccess( pResponse, pDdpApi ); - QSharedPointer<DDPRequest> rooms( new DDPMethodRequest( "rooms/get", {}, subscriptionSuccess ) ); + QSharedPointer<DDPRequest> rooms( new DDPMethodRequest( "rooms/get", {}, roomsSuccess ) ); mServer->sendDdprequest( rooms ); } ) ); mServer->sendDdprequest( subscriptions ); @@ -338,6 +355,8 @@ void RocketChatChannelService::leaveChannel( const QString &pId ) QSharedPointer<RocketChatLeaveRoomRequest> request( new RocketChatLeaveRoomRequest( pId ) ); auto ddp = getDdp(); ddp->sendRequest( request ); + QSharedPointer<RocketChatHideRoomRequest> request2( new RocketChatHideRoomRequest( pId ) ); + getDdp()->sendRequest(request2); deleteChannel( pId ); } } @@ -346,6 +365,7 @@ void RocketChatChannelService::deleteChannel( const QString &pId ) { if ( mChannels->contains( pId ) ) { mChannels->get( pId )->setDeleted( true ); + mChannels->remove(pId); mStorage->transaction(); mStorage->deleteChannel( pId ); mStorage->commit(); diff --git a/services/rocketchatchannelservice.h b/services/rocketchatchannelservice.h index d8ccf0d8d0e628f488bf98a79d6c37292a22c9a5..a47aff3700a4b58d091b3a48d809ca0b76ee8c77 100755 --- a/services/rocketchatchannelservice.h +++ b/services/rocketchatchannelservice.h @@ -93,7 +93,7 @@ class RocketChatChannelService : public QObject ChannelRepository *mChannels = nullptr; MeteorDDP *mDdp; - QVector<QSharedPointer<RocketChatChannel>> processChannelData( QJsonArray pChannelArray, bool pJoined ); + QVector<QSharedPointer<RocketChatChannel>> processChannelData( QJsonArray pChannelArray, bool pJoined , bool pUpdateOnly ); MessageService *mMessageService; signals: