From cf19ee36c326f89ebd1835a8dbdae07e56fb4043 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 25 Mar 2021 00:03:35 +0100 Subject: 4chan: fix crash when posting a reply --- src/Body.cpp | 2 +- src/QuickMedia.cpp | 27 ++++++++++++++------------- src/SearchBar.cpp | 2 +- src/plugins/Youtube.cpp | 7 ++++--- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Body.cpp b/src/Body.cpp index b7cfe4b..10708f0 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -1075,7 +1075,7 @@ namespace QuickMedia { if(!item->reactions.empty() && include_embedded_item) { sf::RoundedRectangleShape reaction_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10); - reaction_background.setFillColor(sf::Color(31, 35, 41)); + reaction_background.setFillColor(sf::Color(33, 37, 44)); float reaction_offset_x = 0.0f; item_pos.y += reaction_padding_y; float reaction_max_height = 0.0f; 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 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 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); diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index df7d951..676618a 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -48,7 +48,7 @@ namespace QuickMedia { //background.setCornersRadius(5); background_shadow.setFillColor(sf::Color(23, 25, 27)); //background_shadow.setPosition(background.getPosition() + sf::Vector2f(5.0f, 5.0f)); - shade.setFillColor(sf::Color(31, 35, 41)); + shade.setFillColor(sf::Color(33, 37, 44)); //background.setOutlineThickness(1.0f); //background.setOutlineColor(sf::Color(13, 15, 17)); if(plugin_logo && plugin_logo->getNativeHandle() != 0) diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 76f98e2..99227d5 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -712,12 +712,13 @@ namespace QuickMedia { if(!author_text) return nullptr; - std::string title = author_text.value(); + std::string author = author_text.value(); std::optional published_time_text = yt_json_get_text(comment_renderer_json, "publishedTimeText"); if(published_time_text) - title += " - " + published_time_text.value(); + author += " - " + published_time_text.value(); - auto body_item = BodyItem::create(std::move(title)); + auto body_item = BodyItem::create(""); + body_item->set_author(std::move(author)); std::string description; const Json::Value &author_is_channel_owner_json = comment_renderer_json["authorIsChannelOwner"]; -- cgit v1.2.3