From 9f12d8a7f6e4cdf0cb95130b69da2b368cc9cbb5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 Feb 2022 21:09:26 +0100 Subject: Add thumbnail to manga history page. Start on new manga history format (one json file) --- src/plugins/Page.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/plugins/Page.cpp') diff --git a/src/plugins/Page.cpp b/src/plugins/Page.cpp index 34ca889..2e3caf4 100644 --- a/src/plugins/Page.cpp +++ b/src/plugins/Page.cpp @@ -85,16 +85,34 @@ namespace QuickMedia { if(!read_file_as_json(bookmark_path, json_root) || !json_root.isArray()) return PluginResult::OK; + std::vector bookmark_json_items; + for(const Json::Value &item : json_root) { + if(!item.isObject()) + continue; + + const Json::Value ×tamp = item["timestamp"]; + if(!timestamp.isInt64()) + continue; + + bookmark_json_items.push_back(&item); + } + + std::sort(bookmark_json_items.begin(), bookmark_json_items.end(), [](const Json::Value *val1, const Json::Value *val2) { + const Json::Value ×tamp1 = (*val1)["timestamp"]; + const Json::Value ×tamp2 = (*val2)["timestamp"]; + return timestamp1.asInt64() > timestamp2.asInt64(); + }); + const time_t time_now = time(nullptr); - for(const Json::Value &item_json : json_root) { - if(!item_json.isObject()) + for(const Json::Value *item_json : bookmark_json_items) { + if(!item_json->isObject()) continue; - const Json::Value &title_json = item_json["title"]; - const Json::Value &author_json = item_json["author"]; - const Json::Value &url_json = item_json["url"]; - const Json::Value &thumbnail_url_json = item_json["thumbnail_url"]; - const Json::Value ×tamp_json = item_json["timestamp"]; + const Json::Value &title_json = (*item_json)["title"]; + const Json::Value &author_json = (*item_json)["author"]; + const Json::Value &url_json = (*item_json)["url"]; + const Json::Value &thumbnail_url_json = (*item_json)["thumbnail_url"]; + const Json::Value ×tamp_json = (*item_json)["timestamp"]; auto body_item = BodyItem::create(title_json.isString() ? title_json.asString() : ""); if(author_json.isString()) @@ -116,7 +134,6 @@ namespace QuickMedia { result_items.push_back(std::move(body_item)); } - std::reverse(result_items.begin(), result_items.end()); return PluginResult::OK; } } \ No newline at end of file -- cgit v1.2.3