aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-21 03:49:17 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-21 03:49:17 +0200
commit40e0f8f5d8c3e480f01a2d71b6a493247adcb77f (patch)
treeccc3c0a7c82be8f5dbe86dfc712cce3da7e2ad59 /plugins
parent5c72463c029804c85479d2c4426397d932c88ee1 (diff)
Initial matrix support
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Fourchan.hpp2
-rw-r--r--plugins/Manga.hpp2
-rw-r--r--plugins/Matrix.hpp68
-rw-r--r--plugins/Plugin.hpp1
4 files changed, 70 insertions, 3 deletions
diff --git a/plugins/Fourchan.hpp b/plugins/Fourchan.hpp
index 564271a..bc336bf 100644
--- a/plugins/Fourchan.hpp
+++ b/plugins/Fourchan.hpp
@@ -13,8 +13,6 @@ namespace QuickMedia {
Fourchan(const std::string &resources_root);
~Fourchan() override;
PluginResult get_front_page(BodyItems &result_items) override;
- SearchResult search(const std::string &url, BodyItems &result_items) override;
- SuggestionResult update_search_suggestions(const std::string &text, 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;
diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp
index 0c57d9f..13c494e 100644
--- a/plugins/Manga.hpp
+++ b/plugins/Manga.hpp
@@ -21,7 +21,7 @@ namespace QuickMedia {
virtual ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) = 0;
virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) = 0;
- virtual PluginResult get_creators_manga_list(const std::string &url, BodyItems &result_items) { return {}; }
+ virtual PluginResult get_creators_manga_list(const std::string &url, BodyItems &result_items) { (void)url; (void)result_items; return {}; }
const std::vector<Creator>& get_creators() const;
protected:
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
new file mode 100644
index 0000000..c498ec8
--- /dev/null
+++ b/plugins/Matrix.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include "Plugin.hpp"
+#include <unordered_map>
+#include <json/value.h>
+
+namespace QuickMedia {
+ struct UserInfo {
+ std::string display_name;
+ std::string avatar_url;
+ };
+
+ struct Message {
+ // Index into |RoomData.user_info|
+ size_t user_id;
+ std::string msg;
+ };
+
+ struct RoomData {
+ // Each room has its own list of user data, even if multiple rooms has the same user
+ // because users can have different display names and avatars in different rooms.
+ // The value is an index to |user_info|.
+ std::unordered_map<std::string, size_t> user_info_by_user_id;
+ std::vector<UserInfo> user_info;
+ std::vector<Message> messages;
+ std::string prev_batch;
+ bool initial_fetch_finished = false;
+ };
+
+ enum class MessageDirection {
+ BEFORE,
+ AFTER
+ };
+
+ class Matrix : public Plugin {
+ public:
+ Matrix();
+ bool search_is_filter() override { return true; }
+ bool search_suggestions_has_thumbnails() const override { return true; }
+ bool search_results_has_thumbnails() const override { return false; }
+ int get_search_delay() const override { return 0; }
+ bool search_suggestion_is_search() const override { return true; }
+ Page get_page_after_search() const override { return Page::EXIT; }
+ PluginResult get_cached_sync(BodyItems &result_items);
+ PluginResult sync();
+ PluginResult get_joined_rooms(BodyItems &result_items);
+ // Note: the number of items returned in |result_items| may not be the number of new messages because many messages can be combined
+ // into one if one user sends multiple messages. The number of messages is returned in |num_new_messages|.
+ PluginResult get_room_messages(const std::string &room_id, size_t start_index, BodyItems &result_items, size_t &num_new_messages);
+ SearchResult search(const std::string &text, BodyItems &result_items) override;
+
+ PluginResult post_message(const std::string &room_id, const std::string &text);
+ PluginResult login(const std::string &username, const std::string &password, const std::string &homeserver, std::string &err_msg);
+
+ PluginResult load_and_verify_cached_session();
+ private:
+ PluginResult sync_response_to_body_items(const Json::Value &root);
+ PluginResult load_initial_room_data(const std::string &room_id, RoomData *room_data);
+ void events_add_user_info(const Json::Value &events_json, RoomData *room_data);
+ void events_add_messages(const Json::Value &events_json, RoomData *room_data, MessageDirection message_dir);
+ private:
+ std::unordered_map<std::string, std::unique_ptr<RoomData>> room_data_by_id;
+ std::string user_id;
+ std::string access_token;
+ std::string homeserver;
+ std::string next_batch;
+ };
+} \ No newline at end of file
diff --git a/plugins/Plugin.hpp b/plugins/Plugin.hpp
index 7d052c2..d2caa67 100644
--- a/plugins/Plugin.hpp
+++ b/plugins/Plugin.hpp
@@ -34,6 +34,7 @@ namespace QuickMedia {
NET_ERR
};
+ void html_escape_sequences(std::string &str);
void html_unescape_sequences(std::string &str);
class Plugin {