From de45f6d8d7d777244006a7998ec971157e51296e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 18 Nov 2022 23:32:08 +0100 Subject: Readd meme gpg encryption in matrix, this time asynchronous decryption of only visible items --- plugins/Matrix.hpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index e5c86e8..8b9dcc9 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -30,6 +30,38 @@ namespace QuickMedia { std::string message_to_qm_text(Matrix *matrix, const Message *message, bool allow_formatted_text = true, mgl::vec2i image_max_size = mgl::vec2i(0, 0)); std::string pantalaimon_url_to_homeserver_url(Matrix *matrix, const std::string &url); Message* get_latest_message_in_edit_chain(Message *message); + bool matrix_gpg_encrypt_for_each_user_in_room(Matrix *matrix, RoomData *room, const std::string &my_gpg_user_id, const std::string &str, std::string &encrypted_str); + + struct MatrixChatBodyDecryptJob { + enum class DecryptState { + NOT_DECRYPTED, + DECRYPTING, + DECRYPTED, + FAILED_TO_DECRYPT + }; + + std::string text; + DecryptState decrypt_state = DecryptState::NOT_DECRYPTED; + bool cancel = false; + }; + + class MatrixChatBodyItemData : public BodyItemExtra { + public: + enum class DecryptState { + NOT_DECRYPTED, + DECRYPTING, + DECRYPTED + }; + + MatrixChatBodyItemData(Matrix *matrix, std::string text_to_decrypt) : matrix(matrix), text_to_decrypt(std::move(text_to_decrypt)) {} + ~MatrixChatBodyItemData(); + void draw_overlay(mgl::Window&, const Widgets &widgets) override; + + DecryptState decrypt_state = DecryptState::NOT_DECRYPTED; + std::shared_ptr decrypt_job; + Matrix *matrix = nullptr; + std::string text_to_decrypt; + }; struct TimestampedDisplayData { std::string data; @@ -178,7 +210,7 @@ namespace QuickMedia { bool users_fetched = false; time_t last_read_message_timestamp = 0; std::shared_ptr body_item; - std::string latest_message; + int offset_to_latest_message_text = 0; // These are messages fetched with |Matrix::get_message_by_id|. Needed to show replies, when replying to old message not part of /sync. // The value is nullptr if the message is fetched and cached but the event if referenced an invalid message. @@ -707,6 +739,8 @@ namespace QuickMedia { std::string body_to_formatted_body(RoomData *room, const std::string &body); void on_exit_room(RoomData *room); + void async_decrypt_message(std::shared_ptr decrypt_job); + // Calls the |MatrixDelegate| pending events. // Should be called from the main (ui) thread void update(); @@ -761,6 +795,7 @@ namespace QuickMedia { void load_silenced_invites(); private: MessageQueue> ui_thread_tasks; + std::vector> rooms; std::unordered_map room_data_by_id; // value is an index into |rooms| std::recursive_mutex room_data_mutex; @@ -799,5 +834,8 @@ namespace QuickMedia { std::unordered_map custom_emoji_by_key; std::unordered_set silenced_invites; std::unordered_map qm_read_markers_by_room_cache; + + MessageQueue> decrypt_task; + std::thread decrypt_thread; }; } \ No newline at end of file -- cgit v1.2.3