diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 8 | ||||
-rw-r--r-- | src/plugins/Fourchan.cpp | 25 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 22 |
3 files changed, 40 insertions, 15 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 64955dd..0b02000 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3098,7 +3098,7 @@ namespace QuickMedia { comment_input.set_max_width(window_size.x); comment_input.set_max_width(window_size.x - (logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x * 2.0f)); - comment_input.set_position(sf::Vector2f(logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x, window_size.y - chat_height - chat_input_padding_y)); + comment_input.set_position(sf::Vector2f(logo_padding_x + plugin_logo.getSize().x + chat_input_padding_x, chat_input_padding_y)); float body_padding_horizontal = 25.0f; float body_padding_vertical = 5.0f; @@ -3109,12 +3109,12 @@ namespace QuickMedia { } comment_input_shade.setSize(sf::Vector2f(window_size.x, chat_input_height_full)); - comment_input_shade.setPosition(0.0f, window_size.y - comment_input_shade.getSize().y); + comment_input_shade.setPosition(0.0f, 0.0f); - body_pos = sf::Vector2f(body_padding_horizontal, body_padding_vertical); + body_pos = sf::Vector2f(body_padding_horizontal, comment_input_shade.getSize().y + body_padding_vertical); body_size = sf::Vector2f(body_width, window_size.y - comment_input_shade.getSize().y - body_padding_vertical); - logo_sprite.setPosition(logo_padding_x, window_size.y - comment_input_shade.getSize().y * 0.5f - plugin_logo.getSize().y * 0.5f); + logo_sprite.setPosition(logo_padding_x, comment_input_shade.getSize().y * 0.5f - plugin_logo.getSize().y * 0.5f); } //comment_input.update(); diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 111aca1..757a0e1 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -251,31 +251,36 @@ namespace QuickMedia { if(!thread_num.isNumeric()) continue; - std::string comment_text; + std::string title_text; extract_comment_pieces(sub_begin, sub_end - sub_begin, - [&comment_text](const CommentPiece &cp) { + [&title_text](const CommentPiece &cp) { switch(cp.type) { case CommentPiece::Type::TEXT: - comment_text.append(cp.text.data, cp.text.size); + title_text.append(cp.text.data, cp.text.size); break; case CommentPiece::Type::QUOTE: - comment_text += '>'; - comment_text.append(cp.text.data, cp.text.size); + title_text += '>'; + title_text.append(cp.text.data, cp.text.size); //comment_text += '\n'; break; case CommentPiece::Type::QUOTELINK: { - comment_text.append(cp.text.data, cp.text.size); + title_text.append(cp.text.data, cp.text.size); break; } case CommentPiece::Type::LINE_CONTINUE: { - if(!comment_text.empty() && comment_text.back() == '\n') { - comment_text.pop_back(); + if(!title_text.empty() && title_text.back() == '\n') { + title_text.pop_back(); } break; } } } ); + if(!title_text.empty() && title_text.back() == '\n') + title_text.back() = ' '; + html_unescape_sequences(title_text); + + std::string comment_text; extract_comment_pieces(comment_begin, comment_end - comment_begin, [&comment_text](const CommentPiece &cp) { switch(cp.type) { @@ -300,8 +305,6 @@ namespace QuickMedia { } } ); - if(!comment_text.empty() && comment_text.back() == '\n') - comment_text.back() = ' '; html_unescape_sequences(comment_text); // TODO: Do the same when wrapping is implemented // TODO: Remove this @@ -316,6 +319,7 @@ namespace QuickMedia { } } auto body_item = BodyItem::create(std::move(comment_text)); + body_item->set_author(std::move(title_text)); body_item->url = std::to_string(thread_num.asInt64()); const Json::Value &ext = thread["ext"]; @@ -395,6 +399,7 @@ namespace QuickMedia { return PluginResult::OK; } + // TODO: Merge with get_threads_internal PluginResult Fourchan::get_thread_comments(const std::string &list_url, const std::string &url, BodyItems &result_items) { cached_media_urls.clear(); std::string server_response; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 48d29eb..8796729 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -573,6 +573,26 @@ namespace QuickMedia { return user_id.substr(1, index - 1); } + static std::string combine_user_display_names_for_room_name(const std::string &my_user_id, const std::vector<UserInfo> &user_info, const std::string &fallback_user_id) { + std::vector<const UserInfo*> users_excluding_me; + for(const UserInfo &user : user_info) { + if(user.user_id != my_user_id) { + users_excluding_me.push_back(&user); + } + } + + std::string result; + if(users_excluding_me.size() == 0) + result = extract_user_name_from_user_id(fallback_user_id); + else if(users_excluding_me.size() == 1) + result = users_excluding_me[0]->display_name; + else if(users_excluding_me.size() == 2) + result = users_excluding_me[0]->display_name + " and " + users_excluding_me[1]->display_name; + else if(users_excluding_me.size() > 2) + result = users_excluding_me[0]->display_name + ", " + users_excluding_me[1]->display_name + " and " + std::to_string(users_excluding_me.size() - 2) + " other(s)"; + return result; + } + void Matrix::events_set_room_name(const Json::Value &events_json, RoomData *room_data) { if(!events_json.isArray()) return; @@ -613,7 +633,7 @@ namespace QuickMedia { continue; if(room_data->name.empty()) - room_data->name = extract_user_name_from_user_id(creator_json.asString()); + room_data->name = combine_user_display_names_for_room_name(user_id, room_data->user_info, creator_json.asString()); if(room_data->avatar_url.empty()) { auto user_it = room_data->user_info_by_user_id.find(creator_json.asString()); |