From 4ff0c8a47e659200b3e778400d05575eed988398 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 18 Oct 2024 16:35:50 -0300 Subject: [PATCH 1/2] enhance: change from to std::ranges::find_if in Chat::getPrivateChannel --- src/creatures/interactions/chat.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/creatures/interactions/chat.cpp b/src/creatures/interactions/chat.cpp index 1d006ca95aa..9b73e6caad8 100644 --- a/src/creatures/interactions/chat.cpp +++ b/src/creatures/interactions/chat.cpp @@ -604,11 +604,14 @@ std::shared_ptr Chat::getChannelById(uint16_t channelId) { return it->second; } -std::shared_ptr Chat::getPrivateChannel(const std::shared_ptr &player) { - for (auto &it : privateChannels) { - if (it.second->getOwner() == player->getGUID()) { - return it.second; - } +std::shared_ptr Chat::getPrivateChannel(const std::shared_ptr &player) const { + auto it = std::ranges::find_if(privateChannels, [&player](const auto &channelPair) { + const auto &[channelId, channel] = channelPair; + return channel->getOwner() == player->getGUID(); + }); + + if (it != privateChannels.end()) { + return it->second; } return nullptr; } From 9297f5b9f5790087e4f4f72942e735a31420220f Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 18 Oct 2024 16:36:29 -0300 Subject: [PATCH 2/2] to const --- src/creatures/interactions/chat.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/interactions/chat.hpp b/src/creatures/interactions/chat.hpp index 3643086184c..fcc74563c34 100644 --- a/src/creatures/interactions/chat.hpp +++ b/src/creatures/interactions/chat.hpp @@ -137,7 +137,7 @@ class Chat { std::shared_ptr getChannel(const std::shared_ptr &player, uint16_t channelId); std::shared_ptr getChannelById(uint16_t channelId); std::shared_ptr getGuildChannelById(uint32_t guildId); - std::shared_ptr getPrivateChannel(const std::shared_ptr &player); + std::shared_ptr getPrivateChannel(const std::shared_ptr &player) const; LuaScriptInterface* getScriptInterface() { return &scriptInterface;