aboutsummaryrefslogtreecommitdiff
path: root/plugins/Fourchan.hpp
blob: bc336bf0204268f1a51336821299ad6edb79751d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include "ImageBoard.hpp"
#include <thread>
#include <mutex>
#include <condition_variable>

namespace QuickMedia {
    class Program;

    class Fourchan : public ImageBoard {
    public:
        Fourchan(const std::string &resources_root);
        ~Fourchan() override;
        PluginResult get_front_page(BodyItems &result_items) override;
        PluginResult get_threads(const std::string &url, BodyItems &result_items) override;
        PluginResult get_thread_comments(const std::string &list_url, const std::string &url, BodyItems &result_items) override;
        PostResult post_comment(const std::string &board, const std::string &thread, const std::string &captcha_id, const std::string &comment) override;
        bool search_suggestions_has_thumbnails() const override { return false; }
        bool search_results_has_thumbnails() const override { return false; }
        int get_search_delay() const override { return 150; }
        Page get_page_after_search() const override { return Page::IMAGE_BOARD_THREAD_LIST; }
        bool search_is_filter() override { return true; }
        BodyItems get_related_media(const std::string &url) override;

        PluginResult login(const std::string &token, const std::string &pin, std::string &response_msg);
        const std::string& get_pass_id() const override;
    private:
        PluginResult get_threads_internal(const std::string &url, BodyItems &result_items);
        void set_board_url(const std::string &new_url);
        std::string get_board_url();
        void set_board_thread_list(BodyItems body_items);
        BodyItems get_board_thread_list();
    private:
        std::string current_board_url;
        std::thread thread_list_update_thread;
        BodyItems cached_thread_list_items;
        std::mutex board_url_mutex;
        std::mutex board_list_mutex;
        std::condition_variable thread_list_cached_cv;
        std::mutex thread_list_cache_mutex;
        std::condition_variable thread_list_update_cv;
        bool thread_list_cached = false;
        bool running = true;
        std::vector<std::string> cached_media_urls;
        std::string resources_root;
        std::string pass_id;
    };
}