added support for updating comics rating from clients

This commit is contained in:
Luis Ángel San Martín 2015-12-01 22:50:02 +01:00
parent d151ccf9e4
commit 2bc9f88400
2 changed files with 28 additions and 9 deletions

View File

@ -397,13 +397,15 @@ void DBHelper::updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatab
updateComicInfo.prepare("UPDATE comic_info SET " updateComicInfo.prepare("UPDATE comic_info SET "
"read = :read, " "read = :read, "
"currentPage = :currentPage, " "currentPage = :currentPage, "
"hasBeenOpened = :hasBeenOpened" "hasBeenOpened = :hasBeenOpened, "
"rating = :rating"
" WHERE id = :id "); " WHERE id = :id ");
updateComicInfo.bindValue(":read", comicInfo.read?1:0); updateComicInfo.bindValue(":read", comicInfo.read?1:0);
updateComicInfo.bindValue(":currentPage", comicInfo.currentPage); updateComicInfo.bindValue(":currentPage", comicInfo.currentPage);
updateComicInfo.bindValue(":hasBeenOpened", comicInfo.hasBeenOpened?1:0); updateComicInfo.bindValue(":hasBeenOpened", comicInfo.hasBeenOpened?1:0);
updateComicInfo.bindValue(":id", comicInfo.id); updateComicInfo.bindValue(":id", comicInfo.id);
updateComicInfo.bindValue(":rating", comicInfo.rating);
updateComicInfo.exec(); updateComicInfo.exec();
} }
@ -416,11 +418,19 @@ void DBHelper::updateFromRemoteClient(qulonglong libraryId,const ComicInfo & com
ComicDB comic = DBHelper::loadComic(comicInfo.id,db); ComicDB comic = DBHelper::loadComic(comicInfo.id,db);
if(comic.info.hash == comicInfo.hash) if(comic.info.hash == comicInfo.hash)
{
if(comicInfo.currentPage > 0)
{ {
if(comic.info.currentPage == comic.info.numPages) if(comic.info.currentPage == comic.info.numPages)
comic.info.read = true; comic.info.read = true;
comic.info.currentPage = comicInfo.currentPage; comic.info.currentPage = comicInfo.currentPage;
comic.info.hasBeenOpened = true; comic.info.hasBeenOpened = true;
}
if(comicInfo.rating > 0)
comic.info.rating = comicInfo.rating;
DBHelper::updateReadingRemoteProgress(comic.info,db); DBHelper::updateReadingRemoteProgress(comic.info,db);
} }

View File

@ -23,12 +23,13 @@ void SyncController::service(HttpRequest &request, HttpResponse &response)
qulonglong libraryId; qulonglong libraryId;
qulonglong comicId; qulonglong comicId;
int currentPage; int currentPage;
int currentRating;
QString hash; QString hash;
foreach(QString comicInfo, data) foreach(QString comicInfo, data)
{ {
QList<QString> comicInfoProgress = comicInfo.split("\t"); QList<QString> comicInfoProgress = comicInfo.split("\t");
if(comicInfoProgress.length() == 4) if(comicInfoProgress.length() == 4 || comicInfoProgress.length() == 5)
{ {
libraryId = comicInfoProgress.at(0).toULongLong(); libraryId = comicInfoProgress.at(0).toULongLong();
comicId = comicInfoProgress.at(1).toULongLong(); comicId = comicInfoProgress.at(1).toULongLong();
@ -39,6 +40,14 @@ void SyncController::service(HttpRequest &request, HttpResponse &response)
info.currentPage = currentPage; info.currentPage = currentPage;
info.hash = hash; //TODO remove the hash check and add UUIDs for libraries info.hash = hash; //TODO remove the hash check and add UUIDs for libraries
info.id = comicId; info.id = comicId;
//Client 2.1+ version
if(comicInfoProgress.length() > 4)
{
currentRating = comicInfoProgress.at(4).toInt();
info.rating = currentRating;
}
DBHelper::updateFromRemoteClient(libraryId,info); DBHelper::updateFromRemoteClient(libraryId,info);
} }
} }