From 769000b8f979fd2c4d7cd87fb83cf08912eb90dc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 3 Oct 2020 11:07:11 +0200 Subject: Matrix: use correct name for private chat rooms, move 4chan comment input to the top --- src/plugins/Fourchan.cpp | 25 +++++++++++++++---------- src/plugins/Matrix.cpp | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 11 deletions(-) (limited to 'src/plugins') 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 &user_info, const std::string &fallback_user_id) { + std::vector 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()); -- cgit v1.2.3