diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-03-25 00:03:35 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-03-25 00:03:35 +0100 |
commit | cf19ee36c326f89ebd1835a8dbdae07e56fb4043 (patch) | |
tree | a2499f8b104fcac724b1ffdd5a75991fb53f8964 /src/QuickMedia.cpp | |
parent | 5756acdbf1a2679db8db91d873f57eeb2387c32f (diff) |
4chan: fix crash when posting a reply
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 9fced02..39b4c30 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1265,7 +1265,7 @@ namespace QuickMedia { sf::Event event; - tab_shade.setFillColor(sf::Color(31, 35, 41)); + tab_shade.setFillColor(sf::Color(33, 37, 44)); tab_background.setFillColor(tab_selected_color); sf::Clock frame_timer; @@ -2718,11 +2718,16 @@ namespace QuickMedia { } }; - comment_input.on_submit_callback = [&post_comment_future, &navigation_stage, &request_new_google_captcha_challenge, &comment_to_post, &captcha_post_id, &captcha_solved_time, &post_comment, &thread_page](std::string text) -> bool { + bool frame_skip_text_entry = false; + + comment_input.on_submit_callback = [&frame_skip_text_entry, &comment_input, &post_comment_future, &navigation_stage, &request_new_google_captcha_challenge, &comment_to_post, &captcha_post_id, &captcha_solved_time, &post_comment, &thread_page](std::string text) -> bool { if(text.empty()) return false; + comment_input.set_editable(false); + frame_skip_text_entry = true; assert(navigation_stage == NavigationStage::REPLYING); + comment_to_post = std::move(text); if(!captcha_post_id.empty() && captcha_solved_time.getElapsedTime().asSeconds() < 120) { post_comment_future = std::async(std::launch::async, [&post_comment]() -> bool { @@ -2741,7 +2746,7 @@ namespace QuickMedia { }; sf::RectangleShape comment_input_shade; - comment_input_shade.setFillColor(sf::Color(31, 35, 41)); + comment_input_shade.setFillColor(sf::Color(33, 37, 44)); sf::Sprite logo_sprite(plugin_logo); logo_sprite.setScale(0.8f * get_ui_scale(), 0.8f * get_ui_scale()); @@ -2756,7 +2761,6 @@ namespace QuickMedia { sf::Vector2f body_pos; sf::Vector2f body_size; bool redraw = true; - bool frame_skip_text_entry = false; sf::Event event; std::stack<int> comment_navigation_stack; @@ -2772,10 +2776,8 @@ namespace QuickMedia { event_idle_handler(event); if(!frame_skip_text_entry) comment_input.process_event(event); + if(navigation_stage == NavigationStage::REPLYING && !frame_skip_text_entry) { - // To prevent pressing enter in comment_input text submit from also immediately sending captcha solution.. is there no better solution? - if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Enter) - break; if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { comment_input.set_editable(false); navigation_stage = NavigationStage::VIEWING_COMMENTS; @@ -2893,7 +2895,7 @@ namespace QuickMedia { } } - if(event.type == sf::Event::KeyPressed && navigation_stage == NavigationStage::SOLVING_POST_CAPTCHA) { + if(event.type == sf::Event::KeyPressed && navigation_stage == NavigationStage::SOLVING_POST_CAPTCHA && !frame_skip_text_entry) { int num = -1; if(event.key.code >= sf::Keyboard::Num1 && event.key.code <= sf::Keyboard::Num9) { num = event.key.code - sf::Keyboard::Num1; @@ -2959,7 +2961,6 @@ namespace QuickMedia { if(redraw) { redraw = false; - comment_input.set_max_width(window_size.x); comment_input.set_max_width(window_size.x - (logo_padding_x + logo_size.x + chat_input_padding_x + logo_padding_x)); comment_input.set_position(sf::Vector2f(std::floor(logo_padding_x + logo_size.x + chat_input_padding_x), chat_input_padding_y)); @@ -3192,7 +3193,7 @@ namespace QuickMedia { static std::shared_ptr<BodyItem> message_to_body_item(RoomData *room, Message *message, const std::string &my_display_name, const std::string &my_user_id) { auto body_item = BodyItem::create(""); body_item->set_author(room->get_user_display_name(message->user)); - body_item->set_description(message_get_body_remove_formatting(message)); + body_item->set_description(strip(message_get_body_remove_formatting(message))); body_item->set_timestamp(message->timestamp); if(!message->thumbnail_url.empty()) { body_item->thumbnail_url = message->thumbnail_url; @@ -4016,7 +4017,7 @@ namespace QuickMedia { sf::Event event; sf::RectangleShape tab_shade; - tab_shade.setFillColor(sf::Color(31, 35, 41)); + tab_shade.setFillColor(sf::Color(33, 37, 44)); sf::RoundedRectangleShape tab_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10); tab_background.setFillColor(tab_selected_color); @@ -4055,7 +4056,7 @@ namespace QuickMedia { more_messages_below_rect.setFillColor(sf::Color(128, 50, 50)); sf::RectangleShape chat_input_shade; - chat_input_shade.setFillColor(sf::Color(31, 35, 41)); + chat_input_shade.setFillColor(sf::Color(33, 37, 44)); sf::Clock start_typing_timer; const double typing_timeout_seconds = 3.0; @@ -4899,7 +4900,7 @@ namespace QuickMedia { if(draw_room_list) { sf::RectangleShape room_list_background(sf::Vector2f(this->body_size.x, window_size.y)); //room_list_background.setPosition(this->body_pos); - room_list_background.setFillColor(sf::Color(31, 35, 41)); + room_list_background.setFillColor(sf::Color(33, 37, 44)); glEnable(GL_SCISSOR_TEST); glScissor(0.0f, 0.0f, this->body_size.x, window_size.y); window.draw(room_list_background); |