mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Make updateFromRemoteClient
return more updated comics
So they can be sent back to the client.
This commit is contained in:
parent
fe15bc2ba8
commit
2b780e23a4
@ -827,10 +827,15 @@ void DBHelper::updateFromRemoteClientWithHash(const ComicInfo &comicInfo)
|
||||
}
|
||||
}
|
||||
|
||||
void DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics)
|
||||
QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics)
|
||||
{
|
||||
QMap<qulonglong, QList<ComicDB>> moreRecentComics;
|
||||
|
||||
foreach (qulonglong libraryId, comics.keys()) {
|
||||
QList<ComicDB> libraryMoreRecentComics;
|
||||
|
||||
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
|
||||
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath + "/.yacreaderlibrary");
|
||||
@ -850,37 +855,58 @@ void DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &
|
||||
ComicDB comic = DBHelper::loadComic(comicInfo.id, db);
|
||||
|
||||
if (comic.info.hash == comicInfo.hash) {
|
||||
if (comicInfo.currentPage > 0) {
|
||||
comic.info.currentPage = comicInfo.currentPage;
|
||||
bool isMoreRecent = false;
|
||||
|
||||
if (comic.info.currentPage == comic.info.numPages)
|
||||
comic.info.read = true;
|
||||
|
||||
comic.info.hasBeenOpened = true;
|
||||
|
||||
if (comic.info.lastTimeOpened.toULongLong() < comicInfo.lastTimeOpened.toULongLong())
|
||||
comic.info.lastTimeOpened = comicInfo.lastTimeOpened;
|
||||
//completion takes precedence over lastTimeOpened, if we just want to synchronize the lastest status we should use only lastTimeOpened
|
||||
if ((comic.info.currentPage > 1 && comic.info.currentPage > comicInfo.currentPage) || comic.info.hasBeenOpened || (comic.info.read && !comicInfo.read)) {
|
||||
isMoreRecent = true;
|
||||
}
|
||||
|
||||
if (comic.info.lastTimeOpened.toULongLong() > 0 && comicInfo.lastTimeOpened.toULongLong() == 0) {
|
||||
isMoreRecent = true;
|
||||
}
|
||||
|
||||
comic.info.currentPage = qMax(comic.info.currentPage, comicInfo.currentPage);
|
||||
|
||||
if (comic.info.currentPage == comic.info.numPages)
|
||||
comic.info.read = true;
|
||||
|
||||
comic.info.read = comic.info.read || comicInfo.read;
|
||||
|
||||
comic.info.hasBeenOpened = comic.info.hasBeenOpened || comicInfo.currentPage > 0;
|
||||
|
||||
if (comic.info.lastTimeOpened.toULongLong() < comicInfo.lastTimeOpened.toULongLong() && comicInfo.lastTimeOpened.toULongLong() > 0)
|
||||
comic.info.lastTimeOpened = comicInfo.lastTimeOpened;
|
||||
|
||||
if (comicInfo.rating > 0)
|
||||
comic.info.rating = comicInfo.rating;
|
||||
|
||||
updateComicInfo.bindValue(":read", comic.info.read ? 1 : 0);
|
||||
updateComicInfo.bindValue(":currentPage", comic.info.currentPage);
|
||||
updateComicInfo.bindValue(":hasBeenOpened", comic.info.hasBeenOpened ? 1 : 0);
|
||||
updateComicInfo.bindValue(":lastTimeOpened", QDateTime::currentMSecsSinceEpoch() / 1000);
|
||||
updateComicInfo.bindValue(":lastTimeOpened", comic.info.lastTimeOpened);
|
||||
updateComicInfo.bindValue(":id", comic.info.id);
|
||||
updateComicInfo.bindValue(":rating", comic.info.rating);
|
||||
updateComicInfo.exec();
|
||||
|
||||
if (isMoreRecent) {
|
||||
libraryMoreRecentComics.append(comic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!libraryMoreRecentComics.isEmpty()) {
|
||||
moreRecentComics[libraryId] = libraryMoreRecentComics;
|
||||
}
|
||||
|
||||
db.commit();
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
}
|
||||
|
||||
return moreRecentComics;
|
||||
}
|
||||
|
||||
void DBHelper::updateFromRemoteClientWithHash(const QList<ComicInfo> &comics)
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
static void updateFromRemoteClient(qulonglong libraryId, const ComicInfo &comicInfo);
|
||||
static void updateFromRemoteClientWithHash(const ComicInfo &comicInfo);
|
||||
static void updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db);
|
||||
static void updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics);
|
||||
static QMap<qulonglong, QList<ComicDB>> updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics);
|
||||
static void updateFromRemoteClientWithHash(const QList<ComicInfo> &comics);
|
||||
static void renameLabel(qulonglong id, const QString &name, QSqlDatabase &db);
|
||||
static void renameList(qulonglong id, const QString &name, QSqlDatabase &db);
|
||||
|
Loading…
x
Reference in New Issue
Block a user