diff options
-rw-r--r-- | plugins/Matrix.hpp | 10 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 37 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 4 |
3 files changed, 44 insertions, 7 deletions
diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index de66481..a3ce633 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -238,7 +238,6 @@ namespace QuickMedia { int notification_power_level = 50; size_t index = 0; std::atomic<uint64_t> gpg_decrypt_message_id = 0; - std::string chat_message; private: std::mutex user_mutex; std::recursive_mutex room_mutex; @@ -257,6 +256,11 @@ namespace QuickMedia { std::set<std::string> tags; }; + struct RoomExtraData { + std::string chat_message; + std::string editing_message_id; + }; + struct Invite { std::string room_name; std::string room_avatar_url; @@ -745,6 +749,8 @@ namespace QuickMedia { std::string get_media_url(const std::string &mxc_id); + RoomExtraData& get_room_extra_data(RoomData *room); + void append_system_message(RoomData *room_data, std::shared_ptr<Message> message); std::string body_to_formatted_body(RoomData *room, const std::string &body); void on_exit_room(RoomData *room); @@ -847,5 +853,7 @@ namespace QuickMedia { MessageQueue<std::shared_ptr<MatrixChatBodyDecryptJob>> decrypt_task; std::thread decrypt_thread; + + std::unordered_map<std::string, RoomExtraData> room_extra_data_by_id; }; }
\ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 7b052f4..c348e1c 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -6011,7 +6011,7 @@ namespace QuickMedia { Entry chat_input("Press i to start writing a message...", &rounded_rectangle_shader); chat_input.set_editable(false); chat_input.set_padding_scale(1.5f); - chat_input.set_text(current_room->chat_message); + chat_input.set_text(matrix->get_room_extra_data(current_room).chat_message); struct ProvisionalMessage { std::shared_ptr<BodyItem> body_item; @@ -6156,6 +6156,7 @@ namespace QuickMedia { new_page = PageType::FILE_MANAGER; chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else if(strncmp(text.c_str(), "/join ", 6) == 0) { text.erase(text.begin(), text.begin() + 6); @@ -6171,6 +6172,7 @@ namespace QuickMedia { show_notification("QuickMedia", "You joined " + text, Urgency::NORMAL); chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else { return false; @@ -6180,11 +6182,13 @@ namespace QuickMedia { new_page = PageType::CHAT_INVITE; chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else if(text == "/logout") { new_page = PageType::CHAT_LOGIN; chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else if(text == "/leave") { TaskResult task_result = run_task_with_loading_screen([this, ¤t_room]() { @@ -6194,6 +6198,7 @@ namespace QuickMedia { go_to_previous_page = true; chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); } return true; } else if(text == "/help") { @@ -6215,6 +6220,7 @@ namespace QuickMedia { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else if(text == "/id") { auto message = std::make_shared<Message>(); @@ -6226,6 +6232,7 @@ namespace QuickMedia { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); return true; } else if(strncmp(text.c_str(), "/me ", 4) == 0) { msgtype = "m.emote"; @@ -6333,6 +6340,7 @@ namespace QuickMedia { } chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); if(scroll_to_end) tabs[MESSAGES_TAB_INDEX].body->select_last_item(); return true; @@ -6360,6 +6368,7 @@ namespace QuickMedia { }); chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); currently_operating_on_item = nullptr; if(scroll_to_end) tabs[MESSAGES_TAB_INDEX].body->select_last_item(); @@ -6400,6 +6409,7 @@ namespace QuickMedia { chat_input.set_editable(false); chat_state = ChatState::NAVIGATING; + matrix->get_room_extra_data(current_room).editing_message_id.clear(); currently_operating_on_item = nullptr; return true; } else { @@ -7182,8 +7192,13 @@ namespace QuickMedia { } if(event.key.code == mgl::Keyboard::I && !event.key.control) { + RoomExtraData &room_extra_data = matrix->get_room_extra_data(current_room); frame_skip_text_entry = true; chat_input.set_editable(true); + if(!room_extra_data.editing_message_id.empty()) { + chat_input.set_text(""); + room_extra_data.editing_message_id.clear(); + } chat_state = ChatState::TYPING_MESSAGE; } @@ -7271,9 +7286,14 @@ namespace QuickMedia { // TODO: Show inline notification show_notification("QuickMedia", "You can't reply to a message that hasn't been sent yet"); } else { + RoomExtraData &room_extra_data = matrix->get_room_extra_data(current_room); chat_state = ChatState::REPLYING; currently_operating_on_item = selected; chat_input.set_editable(true); + if(!room_extra_data.editing_message_id.empty()) { + chat_input.set_text(""); + room_extra_data.editing_message_id.clear(); + } replying_to_text.set_string("Replying to:"); frame_skip_text_entry = true; } @@ -7291,8 +7311,9 @@ namespace QuickMedia { frame_skip_text_entry = true; std::shared_ptr<BodyItem> selected = tabs[selected_tab].body->get_selected_shared(); if(selected) { - if(!is_state_message_type(static_cast<Message*>(selected->userdata))) { - if(static_cast<Message*>(selected->userdata)->event_id.empty()) { + const Message *message = static_cast<Message*>(selected->userdata); + if(!is_state_message_type(message)) { + if(message->event_id.empty()) { // TODO: Show inline notification show_notification("QuickMedia", "You can't edit a message that hasn't been sent yet"); } else if(!selected->url.empty()) { // cant edit messages that are image/video posts @@ -7302,14 +7323,18 @@ namespace QuickMedia { // TODO: Show inline notification show_notification("QuickMedia", "You can't edit a message that was posted by somebody else"); } else { - const std::string body_text_unformatted = Text::to_printable_string(selected->get_description()); + RoomExtraData &room_extra_data = matrix->get_room_extra_data(current_room); + std::string body_text_unformatted = Text::to_printable_string(selected->get_description()); chat_state = ChatState::EDITING; currently_operating_on_item = selected; chat_input.set_editable(true); - chat_input.set_text(std::move(body_text_unformatted)); // TODO: Description? it may change in the future, in which case this should be edited + if(room_extra_data.editing_message_id.empty() || message->event_id != room_extra_data.editing_message_id) { + chat_input.set_text(std::move(body_text_unformatted)); // TODO: Description? it may change in the future, in which case this should be edited + } chat_input.move_caret_to_end(); replying_to_text.set_string("Editing message:"); + room_extra_data.editing_message_id = message->event_id; } } } else { @@ -7963,7 +7988,7 @@ namespace QuickMedia { } chat_page_end: - current_room->chat_message = chat_input.get_text(); + matrix->get_room_extra_data(current_room).chat_message = chat_input.get_text(); matrix_chat_page->set_current_room(nullptr, nullptr, nullptr); fetch_messages_future.cancel(); cleanup_tasks(); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 5882653..aef65fa 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -2469,6 +2469,10 @@ namespace QuickMedia { return homeserver + "/_matrix/media/r0/download/" + thumbnail_url_extract_media_id(mxc_id); } + RoomExtraData& Matrix::get_room_extra_data(RoomData *room) { + return room_extra_data_by_id[room->id]; + } + std::shared_ptr<UserInfo> Matrix::parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data, int64_t timestamp) { assert(json.IsObject()); std::string avatar_url_str; |