Support image filters on syncback from ios and android clients

This commit is contained in:
luisangelsm
2025-11-19 18:10:02 +01:00
parent 14ad6f3a2d
commit b94dc7fcf5
3 changed files with 92 additions and 37 deletions

View File

@ -1084,7 +1084,7 @@ void DBHelper::updateFromRemoteClient(qulonglong libraryId, const ComicInfo &com
QSqlDatabase::removeDatabase(connectionName);
}
QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened)
QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters)
{
QMap<qulonglong, QList<ComicDB>> moreRecentComics;
@ -1105,7 +1105,9 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
"currentPage = :currentPage, "
"hasBeenOpened = :hasBeenOpened, "
"lastTimeOpened = :lastTimeOpened, "
"rating = :rating"
"rating = :rating, "
"imageFiltersJson = :imageFiltersJson, "
"lastTimeImageFiltersSet = :lastTimeImageFiltersSet "
" WHERE id = :id ");
foreach (ComicInfo comicInfo, comics[libraryId]) {
@ -1129,6 +1131,12 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
isMoreRecent = true;
}
if (clientSendsImageFilters) {
if (comic.info.lastTimeImageFiltersSet.toULongLong() > comicInfo.lastTimeImageFiltersSet.toULongLong()) {
isMoreRecent = true;
}
}
comic.info.currentPage = qMax(comic.info.currentPage, comicInfo.currentPage);
if (comic.info.currentPage == comic.info.numPages)
@ -1148,12 +1156,21 @@ QMap<qulonglong, QList<ComicDB>> DBHelper::updateFromRemoteClient(const QMap<qul
if (comicInfo.rating > 0)
comic.info.rating = comicInfo.rating;
if (clientSendsImageFilters) {
if (comic.info.lastTimeImageFiltersSet.toULongLong() < comicInfo.lastTimeImageFiltersSet.toULongLong()) {
comic.info.imageFiltersJson = comicInfo.imageFiltersJson;
comic.info.lastTimeImageFiltersSet = comicInfo.lastTimeImageFiltersSet;
}
}
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", comic.info.lastTimeOpened);
updateComicInfo.bindValue(":id", comic.info.id);
updateComicInfo.bindValue(":rating", comic.info.rating);
updateComicInfo.bindValue(":imageFiltersJson", comic.info.imageFiltersJson);
updateComicInfo.bindValue(":lastTimeImageFiltersSet", comic.info.lastTimeImageFiltersSet);
updateComicInfo.exec();
if (isMoreRecent) {

View File

@ -76,7 +76,7 @@ public:
static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo);
[[deprecated("Server v1")]] static void updateFromRemoteClient(qulonglong libraryId, const ComicInfo &comicInfo);
static void updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db);
static QMap<qulonglong, QList<ComicDB>> updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened);
static QMap<qulonglong, QList<ComicDB>> updateFromRemoteClient(const QMap<qulonglong, QList<ComicInfo>> &comics, bool clientSendsHasBeenOpened, bool clientSendsImageFilters);
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);

View File

@ -38,19 +38,32 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
auto libraries = DBHelper::getLibraries();
bool clientSendsHasBeenOpened = false;
bool clientSendsImageFilters = false;
foreach (QString comicInfo, data) {
QList<QString> comicInfoProgress = comicInfo.split("\t");
if (comicInfoProgress.length() >= 9) {
if (comicInfoProgress.at(0) != "u") {
if (comicInfo.isEmpty()) {
continue;
}
QList<QString> comicInfoProgress = comicInfo.split("\t");
if (comicInfoProgress.isEmpty()) {
continue;
}
if (comicInfoProgress.at(0) == "u") { // Android
clientSendsHasBeenOpened = true;
if (comicInfoProgress.length() < 9) {
continue;
}
auto libraryUuid = QUuid(comicInfoProgress.at(1));
if (!libraryUuid.isNull()) {
if (libraryUuid.isNull()) {
continue;
}
auto libraryId = libraries.getIdFromUuid(libraryUuid);
if (libraryId == -1) {
continue;
@ -74,12 +87,21 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
info.read = comicInfoProgress.at(8).toInt();
if (comicInfoProgress.length() >= 11) { // info includes image filters
info.lastTimeImageFiltersSet = comicInfoProgress.at(9);
info.imageFiltersJson = comicInfoProgress.at(10);
clientSendsImageFilters = true;
}
if (!comics.contains(libraryId)) {
comics[libraryId] = QList<ComicInfo>();
}
comics[libraryId].push_back(info);
} else { // iOS
if (comicInfoProgress.length() < 6) {
continue;
}
} else if (comicInfoProgress.length() >= 6) {
if (comicInfoProgress.at(0) != "unknown") {
libraryId = comicInfoProgress.at(0).toULongLong();
comicId = comicInfoProgress.at(1).toULongLong();
@ -104,7 +126,16 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
if (!comics.contains(libraryId)) {
comics[libraryId] = QList<ComicInfo>();
}
if (comicInfoProgress.length() >= 9) { // info includes image filters
info.lastTimeImageFiltersSet = comicInfoProgress.at(7);
info.imageFiltersJson = comicInfoProgress.at(8);
clientSendsImageFilters = true;
}
comics[libraryId].push_back(info);
} else {
hash = comicInfoProgress.at(2);
currentPage = comicInfoProgress.at(3).toInt();
@ -119,6 +150,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
lastTimeOpened = comicInfoProgress.at(5).toULong();
info.lastTimeOpened = lastTimeOpened;
if (comicInfoProgress.length() >= 9) { // info includes image filters
info.lastTimeImageFiltersSet = comicInfoProgress.at(7);
info.imageFiltersJson = comicInfoProgress.at(8);
clientSendsImageFilters = true;
}
comicsWithNoLibrary.push_back(info);
}
}
@ -127,13 +165,13 @@ void SyncControllerV2::service(HttpRequest &request, HttpResponse &response)
QJsonArray items;
if (!comics.isEmpty()) {
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened);
auto moreRecentComicsFound = DBHelper::updateFromRemoteClient(comics, clientSendsHasBeenOpened, clientSendsImageFilters);
foreach (qulonglong libraryId, moreRecentComicsFound.keys()) {
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
foreach (ComicDB comic, moreRecentComicsFound[libraryId]) {
items.append(YACReaderServerDataHelper::comicToJSON(libraryId, libraryUuid, comic));
items.append(YACReaderServerDataHelper::fullComicToJSON(libraryId, libraryUuid, comic));
}
}
}