From 319657e815f4021455936185b6f778a19f6cf06c Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Fri, 2 Feb 2024 00:35:09 +0100 Subject: [PATCH] Review fixes --- rpcs3/Emu/NP/np_handler.cpp | 14 ++++--------- rpcs3/Emu/NP/np_handler.h | 2 +- rpcs3/Emu/NP/rpcn_client.cpp | 2 +- rpcs3/rpcs3qt/rpcn_settings_dialog.cpp | 27 +++++++++++++++----------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 6c21460410..94a9da6d23 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -1358,17 +1358,10 @@ namespace np } const std::string communication_id_str = std::string(basic_handler.context.data); - u32 count = 0; - - for (auto it = players_history.begin(); it != players_history.end(); it++) - { - if (it->second.communication_ids.contains(communication_id_str)) + return std::count_if(players_history.begin(), players_history.end(), [&](const auto& entry) { - count++; - } - } - - return count; + return entry.second.communication_ids.contains(communication_id_str); + }); } bool np_handler::get_player_history_entry(u32 options, u32 index, SceNpId* npid) @@ -1392,6 +1385,7 @@ namespace np { const std::string communication_id_str = std::string(basic_handler.context.data); + // Get the nth element that contains the current communication_id for (auto it = players_history.begin(); it != players_history.end(); it++) { if (it->second.communication_ids.contains(communication_id_str)) diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index 2c2075331f..085dfa522e 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -42,7 +42,7 @@ namespace np struct player_history { - u64 timestamp; + u64 timestamp{}; std::set communication_ids; std::string description; }; diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 41eac9784e..187f73542a 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -1200,7 +1200,7 @@ namespace rpcn vec_stream reply(packet_data); auto error = static_cast(reply.get()); - if (error == ErrorType::NotFound) + if (is_error(error)) { return false; } diff --git a/rpcs3/rpcs3qt/rpcn_settings_dialog.cpp b/rpcs3/rpcs3qt/rpcn_settings_dialog.cpp index f4c9fbf99b..d5b151d2f6 100644 --- a/rpcs3/rpcs3qt/rpcn_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/rpcn_settings_dialog.cpp @@ -889,7 +889,7 @@ namespace np { struct player_history { - u64 timestamp; + u64 timestamp{}; std::set communication_ids; std::string description; }; @@ -1012,17 +1012,23 @@ rpcn_friends_dialog::rpcn_friends_dialog(QWidget* parent) } auto history = np::load_players_history(); - std::map> sorted_history; + std::map, std::greater> sorted_history; for (const auto& [username, user_info] : history) { if (!data.friends.contains(username) && !data.requests_sent.contains(username) && !data.requests_received.contains(username)) - sorted_history.insert(std::make_pair(user_info.timestamp, std::move(username))); + sorted_history.insert(std::make_pair(user_info.timestamp, std::make_pair(std::move(username), std::move(user_info.description)))); } - for (const auto& [_, username] : sorted_history) + for (const auto& [_, username_and_description] : sorted_history) { - m_lst_history->addItem(new QListWidgetItem(QString::fromStdString(username))); + const auto& [username, description] = username_and_description; + auto* item = new QListWidgetItem(QString::fromStdString(username)); + + if (!description.empty()) + item->setToolTip(QString::fromStdString(description)); + + m_lst_history->addItem(item); } connect(this, &rpcn_friends_dialog::signal_add_update_friend, this, &rpcn_friends_dialog::add_update_friend); @@ -1113,13 +1119,12 @@ rpcn_friends_dialog::rpcn_friends_dialog(QWidget* parent) if (!m_rpcn->add_friend(str_sel_friend)) { QMessageBox::critical(this, tr("Error sending a friend request!"), tr("An error occurred while trying to send a friend request!"), QMessageBox::Ok); + return; } - else - { - QString qstr_friend = QString::fromStdString(str_sel_friend); - add_update_list(m_lst_requests, qstr_friend, m_orange_icon, QVariant(false)); - remove_list(m_lst_history, qstr_friend); - } + + QString qstr_friend = QString::fromStdString(str_sel_friend); + add_update_list(m_lst_requests, qstr_friend, m_orange_icon, QVariant(false)); + remove_list(m_lst_history, qstr_friend); }); context_menu->exec(m_lst_history->viewport()->mapToGlobal(pos));