aboutsummaryrefslogtreecommitdiff
path: root/plugins/Fourchan.hpp
blob: 8622a690b482ae5b8783d9fb51f3c8a54ca95e72 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once

#include "ImageBoard.hpp"

namespace QuickMedia {
    // |post_id| is optional
    bool fourchan_extract_url(const std::string &url, std::string &board_id, std::string &thread_id, std::string &post_id);

    class FourchanBoardsPage : public Page {
    public:
        FourchanBoardsPage(Program *program, std::string resources_root) : Page(program), resources_root(std::move(resources_root)) {}
        const char* get_title() const override { return "Select board"; }
        PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
        void get_boards(BodyItems &result_items);

        const std::string resources_root;
        std::string pass_id;
    };

    class FourchanLoginPage : public LazyFetchPage {
    public:
        FourchanLoginPage(Program *program, std::string title, FourchanBoardsPage *boards_page, std::vector<Tab> *tabs, size_t tab_index) :
            LazyFetchPage(program), title(std::move(title)), boards_page(boards_page), tabs(tabs), tab_index(tab_index) {}
        const char* get_title() const override { return title.c_str(); }
        PluginResult submit(const SubmitArgs&, std::vector<Tab>&) override;
        PluginResult lazy_fetch(BodyItems &result_items) override;

        bool submit_is_async() const override { return true; }
        bool allow_submit_no_selection() const override { return true; }
        bool lazy_fetch_is_loader() override { return true; }
        void login_finish();

        const LoginInputs *login_inputs;
    private:
        enum class LoggedIn {
            Unknown,
            Yes,
            No
        };

        std::string title;
        FourchanBoardsPage *boards_page;
        std::vector<Tab> *tabs;
        size_t tab_index;
        LoggedIn logged_in = LoggedIn::Unknown;
    };

    class FourchanThreadListPage : public LazyFetchPage {
    public:
        FourchanThreadListPage(Program *program, std::string title, std::string board_id, std::string pass_id) :
            LazyFetchPage(program), title(std::move(title)), board_id(std::move(board_id)), pass_id(std::move(pass_id)) {}
        const char* get_title() const override { return title.c_str(); }
        PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
        PluginResult lazy_fetch(BodyItems &result_items) override;

        const std::string title;
        const std::string board_id;
        std::string pass_id;
    };

    class FourchanThreadPage : public ImageBoardThreadPage {
    public:
        FourchanThreadPage(Program *program, std::string board_id, std::string thread_id, std::string post_id, std::string pass_id) :
            ImageBoardThreadPage(program, std::move(board_id), std::move(thread_id), std::move(post_id)), pass_id(std::move(pass_id)) {}

        PluginResult lazy_fetch(BodyItems &result_items) override;

        PostResult post_comment(const std::string &captcha_id, const std::string &captcha_solution, const std::string &comment, const std::string &filepath = "") override;
        const std::string& get_pass_id() override;
        PluginResult request_captcha_challenge(ImageBoardCaptchaChallenge &challenge_response) override;
    private:
        std::string pass_id;
    };
}