aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-18 23:32:08 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-18 23:32:12 +0100
commitde45f6d8d7d777244006a7998ec971157e51296e (patch)
tree93ab54b196bda4af7d7fe16d74fb25f08c37a931 /plugins
parentc56cb5d25388d938fce485ff02b067a2fd70e096 (diff)
Readd meme gpg encryption in matrix, this time asynchronous decryption
of only visible items
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Matrix.hpp40
1 files changed, 39 insertions, 1 deletions
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<MatrixChatBodyDecryptJob> 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<BodyItem> 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<MatrixChatBodyDecryptJob> 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<std::function<void()>> ui_thread_tasks;
+
std::vector<std::unique_ptr<RoomData>> rooms;
std::unordered_map<std::string, size_t> 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<std::string, CustomEmoji> custom_emoji_by_key;
std::unordered_set<std::string> silenced_invites;
std::unordered_map<std::string, int64_t> qm_read_markers_by_room_cache;
+
+ MessageQueue<std::shared_ptr<MatrixChatBodyDecryptJob>> decrypt_task;
+ std::thread decrypt_thread;
};
} \ No newline at end of file