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

fix fileupload on android

parent 4a59d1e9
......@@ -25,7 +25,11 @@
FileUploader::FileUploader( QObject *parent, RocketChatServerData *pServer, const QUrl &pUri, const QString &pChannelId ): QObject( parent ),
mUri( pUri ), mChannelId( pChannelId ), mServer( pServer )
{
#ifdef Q_OS_ANDROID
auto file = QSharedPointer<QFile>::create( pUri.path() );
#else
auto file = QSharedPointer<QFile>::create( pUri.toLocalFile() );
#endif
if ( file->isOpen() ) {
file->close();
......@@ -195,12 +199,14 @@ void FileUploader::nextRequest()
auto request = mPartialRequests.first();
double diff = request->getProgress() - progress;
uint now = QDateTime::currentDateTime().toTime_t();
if( diff >= 0.05 && now - lastUpdate){
if ( diff >= 0.05 && now - lastUpdate ) {
progress = request->getProgress();
qDebug() << "progress is "<< progress;
qDebug() << "progress is " << progress;
emit progressChanged( progress );
lastUpdate = now;
}
mServer->sendApiRequest( request, true );
}
}
......
......@@ -70,7 +70,7 @@ FileService::FileService( RocketChatServerData *server )
*/
bool FileService::getFileRessource( const QSharedPointer< FileRequest > &pRequest )
{
if(mServer){
if ( mServer ) {
auto repo = mServer->getFiles();
if ( !pRequest.isNull() && pRequest->url.size() > 0 ) {
......@@ -145,7 +145,7 @@ bool FileService::getFileRessource( const QSharedPointer< FileRequest > &pReques
void FileService::getFilesFromDb()
{
if(mServer){
if ( mServer ) {
auto files = mStorage->getFiles();
auto repo = mServer->getFiles();
......@@ -159,7 +159,7 @@ void FileService::getFilesFromDb()
QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< FileRequest > &pRequest )
{
if ( !pRequest.isNull()&&mServer ) {
if ( !pRequest.isNull() && mServer ) {
auto repo = mServer->getFiles();
if ( repo == nullptr ) {
......@@ -170,10 +170,6 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
QString fullUrl = baseUrl + pRequest->url ;
qDebug() << "file from cache requested" << fullUrl;
if(fullUrl.contains("ras")){
qDebug()<<"ras found";
}
if ( repo->contains( fullUrl ) ) {
auto storageEntry = repo->get( fullUrl );
......@@ -184,12 +180,13 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
}
if (storageEntry->getFileChecked() ) {
if ( storageEntry->getFileChecked() ) {
return storageEntry;
}else{
} else {
QFile cacheHit( storageEntry->getFilePath() );
if(cacheHit.exists()){
storageEntry->setFileChecked(true);
if ( cacheHit.exists() ) {
storageEntry->setFileChecked( true );
return storageEntry;
}
}
......@@ -209,7 +206,7 @@ QSharedPointer<TempFile> FileService::getFileFromCache( const QSharedPointer< Fi
void FileService::getFileFromServer( const QSharedPointer< FileRequest > &pRequest )
{
if ( Q_LIKELY( !pRequest.isNull()&&mServer ) ) {
if ( Q_LIKELY( !pRequest.isNull() && mServer ) ) {
auto baseUrl = mServer->getRestApi()->getBaseUrl();
auto fullUrl = baseUrl + pRequest->url ;
......@@ -356,7 +353,7 @@ QString FileService::determineLocation( const QUrl &pUrl, const QString &pType,
filePath = mMusicPath + urlPath;
} else if ( pType == "document" ) {
filePath = mDocumentPath + urlPath;
}else{
} else {
filePath = mTempPath + urlPath;
}
} else {
......
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