diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-03 11:07:11 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-03 11:07:11 +0200 |
commit | 769000b8f979fd2c4d7cd87fb83cf08912eb90dc (patch) | |
tree | 5950d0bd83a2a4b876b8e534329c87353798285b | |
parent | 27e748dec4792ac8612fb77e21a6d857a41a816c (diff) |
Matrix: use correct name for private chat rooms, move 4chan comment input to the top
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 8 | ||||
-rw-r--r-- | src/plugins/Fourchan.cpp | 25 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 22 |
4 files changed, 42 insertions, 17 deletions
@@ -56,7 +56,6 @@ Implement mentions in matrix with an autofill list, like on element. Also do the Add option to disable autosearch and search when pressing enter instead or something? this would be needed for mobile phones where typing is slow. Sleep when idle, to reduce cpu usage from 1-2% to 0%, important for mobile devices. Also render view to a rendertexture and render that instead of redrawing every time every time. Provide a way to specify when notifications should be received (using matrix api) and also read the notification config from matrix. Also provide a way to disable notifications globally. -Direct message room name should always be the name of the other peer, or in an anonymous room the room name should be some of their names and "X others". Add room search. Use quickmedia to show image in matrix rooms, instead of mpv. Respect ~/.Xresources dpi (read the file, loop lines and look for Xft.dpi). Fallback to 96 dpi. @@ -81,4 +80,5 @@ Support matrix html (for replies and text styling, such as greentext). Show deleted messages in matrix as MESSAGE DELETED or whatever. Use linear-interpolation for thumbnail creation. If --no-audio is used then music should be played with a lightweight music player instead. MPV is heavy even for music (60mb RAM). -Optimize startup time.
\ No newline at end of file +Optimize startup time. +Update 4chan thread in real time, just like 4chan-x.
\ No newline at end of file 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()); |