From 34d4ca50834e256e62a5971c6dc7c39e9e78e9fc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 11 Jul 2020 08:56:04 +0200 Subject: If a video is being watched and it has been watched before, then move it to the top of history --- src/QuickMedia.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 18dd114..0586193 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -780,10 +780,12 @@ namespace QuickMedia { } - static bool watch_history_contains_id(const Json::Value &video_history_json, const char *id) { + static int watch_history_get_item_by_id(const Json::Value &video_history_json, const char *id) { assert(video_history_json.isArray()); + int index = -1; for(const Json::Value &item : video_history_json) { + ++index; if(!item.isObject()) continue; @@ -792,10 +794,10 @@ namespace QuickMedia { continue; if(strcmp(id, id_json.asCString()) == 0) - return true; + return index; } - return false; + return -1; } void Program::video_content_page() { @@ -837,8 +839,11 @@ namespace QuickMedia { Json::Value video_history_json = load_video_history_json(current_plugin); - if(watch_history_contains_id(video_history_json, video_id.c_str())) - return; + int existing_index = watch_history_get_item_by_id(video_history_json, video_id.c_str()); + if(existing_index != -1) { + Json::Value removed; + video_history_json.removeIndex(existing_index, &removed); + } Json::Value new_content_object(Json::objectValue); new_content_object["id"] = video_id; -- cgit v1.2.3