aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-10-05 23:37:52 +0200
committerdec05eba <dec05eba@protonmail.com>2023-10-05 23:37:52 +0200
commitf0a020814794a14760d5aa90493117ea3667e61f (patch)
tree31f60164115580f692fcf7761e6de8acca3bc6ee
parent3e15996dac725dead8d3d7e017f060e15edbd1a6 (diff)
Only decrypt gpg message in room list if its the latest message
-rw-r--r--plugins/Matrix.hpp5
-rw-r--r--src/plugins/Matrix.cpp9
2 files changed, 10 insertions, 4 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp
index 6cc3668..68081d8 100644
--- a/plugins/Matrix.hpp
+++ b/plugins/Matrix.hpp
@@ -59,7 +59,7 @@ namespace QuickMedia {
DECRYPTED
};
- MatrixChatBodyItemData(Matrix *matrix, std::string text_to_decrypt) : matrix(matrix), text_to_decrypt(std::move(text_to_decrypt)) {}
+ MatrixChatBodyItemData(Matrix *matrix, std::string text_to_decrypt, RoomData *room = nullptr, uint64_t gpg_decrypt_message_id = 0) : matrix(matrix), text_to_decrypt(std::move(text_to_decrypt)), room(room), gpg_decrypt_message_id(gpg_decrypt_message_id) {}
~MatrixChatBodyItemData();
void draw_overlay(mgl::Window&, const Widgets &widgets) override;
@@ -67,6 +67,8 @@ namespace QuickMedia {
std::shared_ptr<MatrixChatBodyDecryptJob> decrypt_job;
Matrix *matrix = nullptr;
std::string text_to_decrypt;
+ RoomData *room = nullptr;
+ uint64_t gpg_decrypt_message_id = 0;
};
// TODO: Remove. Not needed anymore.
@@ -235,6 +237,7 @@ namespace QuickMedia {
int notification_power_level = 50;
size_t index = 0;
+ std::atomic<uint64_t> gpg_decrypt_message_id = 0;
private:
std::mutex user_mutex;
std::recursive_mutex room_mutex;
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 13c6f4f..02fce63 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -333,7 +333,8 @@ namespace QuickMedia {
case DecryptState::DECRYPTING: {
if(decrypt_job->decrypt_state == MatrixChatBodyDecryptJob::DecryptState::DECRYPTED || decrypt_job->decrypt_state == MatrixChatBodyDecryptJob::DecryptState::FAILED_TO_DECRYPT) {
decrypt_state = DecryptState::DECRYPTED;
- widgets.body_item->set_description(std::move(decrypt_job->text));
+ if(!room || room->gpg_decrypt_message_id == gpg_decrypt_message_id)
+ widgets.body_item->set_description(std::move(decrypt_job->text));
decrypt_job.reset();
}
break;
@@ -928,6 +929,7 @@ namespace QuickMedia {
return;
if(last_unread_message) {
+ ++room->gpg_decrypt_message_id;
bool is_window_focused = program->is_window_focused();
RoomData *current_room = program->get_current_chat_room();
Body *chat_body = chat_page ? chat_page->chat_body : nullptr;
@@ -957,7 +959,7 @@ namespace QuickMedia {
room->body_item->set_description(std::move(room_desc));
room->body_item->set_description_max_lines(3);
if(should_message_by_decrypted(room->body_item->get_description()))
- room->body_item->extra = std::make_shared<MatrixChatBodyItemData>(matrix, room->body_item->get_description());
+ room->body_item->extra = std::make_shared<MatrixChatBodyItemData>(matrix, room->body_item->get_description(), room, room->gpg_decrypt_message_id);
if(set_room_as_unread)
room->body_item->set_title_color(get_theme().attention_alert_text_color, true);
room->last_message_read = false;
@@ -965,12 +967,13 @@ namespace QuickMedia {
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);
} else if(last_new_message) {
+ ++room->gpg_decrypt_message_id;
room->offset_to_latest_message_text = 0;
room->body_item->set_description(extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_new_message.get()), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(matrix, last_new_message.get(), custom_emoji_max_size));
room->body_item->set_description_color(get_theme().faded_text_color);
room->body_item->set_description_max_lines(3);
if(should_message_by_decrypted(room->body_item->get_description()))
- room->body_item->extra = std::make_shared<MatrixChatBodyItemData>(matrix, room->body_item->get_description());
+ room->body_item->extra = std::make_shared<MatrixChatBodyItemData>(matrix, room->body_item->get_description(), room, room->gpg_decrypt_message_id);
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);