aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-12-17 01:25:10 +0100
committerdec05eba <dec05eba@protonmail.com>2023-12-17 01:25:10 +0100
commit785a3f0a062247910f1ae988c141a7c613a90d51 (patch)
tree6105b414c7ae7589c8a61e1909c42254ddad4517 /src
parent7b91566f303b4afd2deeb6c893ee805e4d62fdaf (diff)
Matrix: keep edited in progress message on esc, clear text when going from edit to insert/reply
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp37
-rw-r--r--src/plugins/Matrix.cpp4
2 files changed, 35 insertions, 6 deletions
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, &current_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;