diff --git a/repos/entities/tempfile.cpp b/repos/entities/tempfile.cpp index 7040c2fdd172288ff3eeafd83a813ddd92d289a1..0ce8eca59a98934014f0abac80d1909bae94e8cf 100644 --- a/repos/entities/tempfile.cpp +++ b/repos/entities/tempfile.cpp @@ -40,6 +40,16 @@ const QFileInfo &TempFile::getFileInfo() const return mFileInfo; } +bool TempFile::getFileChecked() const +{ + return mFileChecked; +} + +void TempFile::setFileChecked(bool fileChecked) +{ + mFileChecked = fileChecked; +} + const QString &TempFile::getFilePath() const { return mFilePath; diff --git a/repos/entities/tempfile.h b/repos/entities/tempfile.h index 6fc50f76c4902424521c0d282c551425492b14db..f40602b090c3846e4ffb53bd90b4d38f512467a3 100644 --- a/repos/entities/tempfile.h +++ b/repos/entities/tempfile.h @@ -44,8 +44,12 @@ class TempFile const QFileInfo &getFileInfo() const; + bool getFileChecked() const; + void setFileChecked( bool fileChecked ); + protected: TempFile() = default; + bool mFileChecked = false; QUrl mUrl; QString mFileName; QString mFilePath; diff --git a/rocketchat.cpp b/rocketchat.cpp index 9f2d3eec2b877b314b924f39b62eb11a1ca50d47..3d1c0854e691a933cb11deb2e34268c60c52793d 100755 --- a/rocketchat.cpp +++ b/rocketchat.cpp @@ -296,9 +296,9 @@ void RocketChat::clearWebViewCookies() #endif } -void RocketChat::deleteMessage(QString rid, QString id) +void RocketChat::deleteMessage( QString rid, QString id ) { - QMetaObject::invokeMethod( mServerMap.first(), "deleteMessage", Q_ARG( QString, rid ),Q_ARG( QString, id ) ); + QMetaObject::invokeMethod( mServerMap.first(), "deleteMessage", Q_ARG( QString, rid ), Q_ARG( QString, id ) ); } bool RocketChat::newServerByDomain( const QString &domain, bool pUnsecure = false ) @@ -676,10 +676,10 @@ void RocketChat::onUnreadCountChanged( const QString &pServerId, uint pUnread ) void RocketChat::onLoggedIn( const QString &pServerId ) { + emit loggedIn( pServerId ); #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) checkForpendingNotification(); #endif - emit loggedIn( pServerId ); } void RocketChat::onChannelSwitchRequest( const QSharedPointer<RocketChatChannel> &pChannel ) diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index 1e67a2edd26dd079ed9c9e6e53bb0dd6e5097ad8..59c43454c6b178b551e25278936db714d2787733 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -60,11 +60,14 @@ void RocketChatServerData::initConnections() MessageList messageList = messages->values( it.key() ); auto channel = mChannels->get( it.key() ); QList<QSharedPointer<RocketChatMessage>> newones = channel->addMessages( messageList ); - mMessageService->deleteMessagesNotInList(messages, it.key(),true); - if(newones.count()) + mMessageService->deleteMessagesNotInList( messages, it.key(), true ); + + if ( newones.count() ) { mMessageService->persistMessages( newones ); + } } } + mStorage->askForcommit(); delete messages; } @@ -168,6 +171,8 @@ void RocketChatServerData::initConnections() } emit readyToCheckForPendingNotification(); + qDebug() << " init ts : " << QDateTime::currentSecsSinceEpoch(); + mChannelService->loadJoinedChannelsFromDb(); } @@ -617,23 +622,23 @@ void RocketChatServerData::wipeDbAndReconnect() resume(); } -void RocketChatServerData::deleteMessage(QString rid, QString id) +void RocketChatServerData::deleteMessage( QString rid, QString id ) { - QJsonArray params = { QJsonObject({{"_id", id }})}; - auto request = QSharedPointer<DDPMethodRequest>::create("deleteMessage",params); + QJsonArray params = { QJsonObject( {{"_id", id }} )}; + auto request = QSharedPointer<DDPMethodRequest>::create( "deleteMessage", params ); DdpCallback success = [ = ]( QJsonObject, MeteorDDP * ) { try { - auto room = mChannels->get(rid); - mStorage->deleteMessage(id); - room->deleteMessage(id); + auto room = mChannels->get( rid ); + mStorage->deleteMessage( id ); + room->deleteMessage( id ); - } catch (std::logic_error error) { + } catch ( std::logic_error error ) { qDebug() << error.what(); } }; - request->setSuccess(success); - sendDdprequest(request); + request->setSuccess( success ); + sendDdprequest( request ); } QSharedPointer<RocketChatUser> RocketChatServerData::getOwnUser() const @@ -800,6 +805,7 @@ void RocketChatServerData::loginWithToken( const QString &pUsername, const QStri request->setSuccess( success ); request->setError( error ); + qDebug() << " login ts : " << QDateTime::currentSecsSinceEpoch(); #ifdef Q_OS_IOS mDdpApi->sendRequest( request ); #else @@ -976,6 +982,8 @@ void RocketChatServerData::loginWithMethod( const QString &method, const QString void RocketChatServerData::onDDPConnected() { + qDebug() << " ddp connected ts : " << QDateTime::currentSecsSinceEpoch(); + auto request = QSharedPointer<PingRequest>::create(); mDdpApi->sendRequest( request ); @@ -1575,6 +1583,8 @@ void RocketChatServerData::getServerSettings() void RocketChatServerData::onChannelsLoaded( const QVector<QSharedPointer<RocketChatChannel>> &pChannels ) { + qDebug() << " channels loaded ts : " << QDateTime::currentSecsSinceEpoch(); + Q_UNUSED( pChannels ); qDebug() << "on channels loaded "; loadHistories(); @@ -1769,6 +1779,18 @@ void RocketChatServerData::getCustomEmojis() mCustomEmojisReady = true; } }; + + if ( mCustomEmojisReady ) { + onLoggedIn(); + + qDebug() << "ddp authenticated"; + this->initialised = true; + } else { + + mEmojiService->loadCustomEmojis( std::move( success ) ); + } + + auto notifyRoomsChanged = QSharedPointer<RocketChatSubscribeRoomsChanged>::create( this->mUserId ); auto notifySubSubscription = QSharedPointer<RocketChatSubscribeUserNotify>::create( this->mUserId ); auto notifyNoticeSubSubscription = QSharedPointer<RocketChatNotifyNoticesRequest>::create( this->mUserId ); @@ -1786,14 +1808,7 @@ void RocketChatServerData::getCustomEmojis() getServerSettings(); emit registerForPush(); - if ( mCustomEmojisReady ) { - onLoggedIn(); - - qDebug() << "ddp authenticated"; - this->initialised = true; - } - mEmojiService->loadCustomEmojis( std::move( success ) ); } void RocketChatServerData::openPrivateChannelWith( const QString &pUsername ) diff --git a/services/fileservice.cpp b/services/fileservice.cpp index 768e8e569744ec5fea1f5413c479f71ba274c551..d786884c157a57edae4e4166ecb7acae0c84aef4 100755 --- a/services/fileservice.cpp +++ b/services/fileservice.cpp @@ -69,6 +69,7 @@ FileService::FileService( RocketChatServerData *server ) */ bool FileService::getFileRessource( const QSharedPointer< FileRequest > &pRequest ) { + auto repo = mServer->getFiles(); if ( !pRequest.isNull() && pRequest->url.size() > 0 ) { if ( mCurrentDownloads.contains( pRequest->url ) ) { @@ -106,12 +107,23 @@ bool FileService::getFileRessource( const QSharedPointer< FileRequest > &pReques } } else { - QFile oldFile( tempFile->getFilePath() ); + if ( !tempFile->getFileChecked() ) { + QFile oldFile( tempFile->getFilePath() ); + + if ( oldFile.exists() ) { + tempFile->setFileChecked( true ); + } else { + mStorage->removeFileCacheEntry( pRequest->url, tempFile->getFilePath() ); + repo->remove( pRequest->url ); + getFileFromServer( pRequest ); + return false; + } - if ( oldFile.copy( location ) ) { - tempFile = QSharedPointer<TempFile>::create( location, pRequest->url ); - } else { - qWarning() << oldFile.errorString(); + /*if ( oldFile.copy( location ) ) { + tempFile = QSharedPointer<TempFile>::create( location, pRequest->url ); + } else { + qWarning() << oldFile.errorString(); + }*/ } }