From aead89cca00cba7bef8752163752f6a9c213ae6f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 1 Aug 2021 00:26:57 +0200 Subject: 4chan: fix last posted timestamp being incorrect (when saved to disk) --- src/QuickMedia.cpp | 13 +++++++------ src/Utils.cpp | 9 --------- 2 files changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 1f7372a..4a3003b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -54,7 +54,7 @@ #include #include -static int FPS_IDLE = 2; +static int FPS_IDLE; static const double IDLE_TIMEOUT_SEC = 2.0; static const sf::Vector2i AVATAR_THUMBNAIL_SIZE(std::floor(32), std::floor(32)); @@ -463,7 +463,7 @@ namespace QuickMedia { } if(low_cpu_mode) - FPS_IDLE = 2; + FPS_IDLE = 3; else FPS_IDLE = 20; @@ -3724,7 +3724,8 @@ namespace QuickMedia { const int captcha_solution_text_height = 18 * get_ui_scale(); sf::Text captcha_solution_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), captcha_solution_text_height); int solved_captcha_ttl = 0; - int64_t last_posted_time = get_unix_time_monotonic(); + int64_t last_posted_time = time(nullptr); + fprintf(stderr, "unix time: %ld\n", last_posted_time); int64_t seconds_until_post_again = 60; // TODO: Timeout for other imageboards bool has_post_timeout = thread_page->get_pass_id().empty(); @@ -3760,7 +3761,7 @@ namespace QuickMedia { // TODO: Asynchronously update the thread periodically to show new comments. selected_file_for_upload.clear(); // TODO: Remove from here, this is async has_post_timeout = thread_page->get_pass_id().empty(); - last_posted_time = get_unix_time_monotonic(); + last_posted_time = time(nullptr); Path last_posted_time_filepath; if(get_image_board_last_posted_filepath(plugin_name, last_posted_time_filepath)) @@ -3803,7 +3804,7 @@ namespace QuickMedia { if(text.empty() && selected_file_for_upload.empty()) return false; - if(has_post_timeout && seconds_until_post_again - (get_unix_time_monotonic() - last_posted_time) > 0) + if(has_post_timeout && seconds_until_post_again - (time(nullptr) - last_posted_time) > 0) return false; comment_input.set_editable(false); @@ -4325,7 +4326,7 @@ namespace QuickMedia { } if((navigation_stage == NavigationStage::REPLYING || navigation_stage == NavigationStage::VIEWING_COMMENTS) && has_post_timeout) { - int64_t time_left_until_post_again = seconds_until_post_again - (get_unix_time_monotonic() - last_posted_time); + int64_t time_left_until_post_again = seconds_until_post_again - (time(nullptr) - last_posted_time); if(time_left_until_post_again > 0) { sf::RectangleShape time_left_bg(comment_input_shade.getSize()); time_left_bg.setPosition(comment_input_shade.getPosition()); diff --git a/src/Utils.cpp b/src/Utils.cpp index 3032f22..c73932b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -126,13 +126,4 @@ namespace QuickMedia { strftime(time_str, sizeof(time_str) - 1, "%Y %b %d, %a %H:%M", &time_tm); return time_str; } - - int64_t get_unix_time_monotonic() { - struct timespec t; - if(clock_gettime(CLOCK_MONOTONIC, &t) == -1) { - fprintf(stderr, "This kernel version doesn't support CLOCK_MONOTONIC\n"); - abort(); - } - return t.tv_sec; - } } \ No newline at end of file -- cgit v1.2.3