Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: change from to std::ranges::find_if in Chat::getPrivateChannel #2996

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/creatures/interactions/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,14 @@ std::shared_ptr<ChatChannel> Chat::getChannelById(uint16_t channelId) {
return it->second;
}

std::shared_ptr<PrivateChatChannel> Chat::getPrivateChannel(const std::shared_ptr<Player> &player) {
for (auto &it : privateChannels) {
if (it.second->getOwner() == player->getGUID()) {
return it.second;
}
std::shared_ptr<PrivateChatChannel> Chat::getPrivateChannel(const std::shared_ptr<Player> &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;
}
2 changes: 1 addition & 1 deletion src/creatures/interactions/chat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Chat {
std::shared_ptr<ChatChannel> getChannel(const std::shared_ptr<Player> &player, uint16_t channelId);
std::shared_ptr<ChatChannel> getChannelById(uint16_t channelId);
std::shared_ptr<ChatChannel> getGuildChannelById(uint32_t guildId);
std::shared_ptr<PrivateChatChannel> getPrivateChannel(const std::shared_ptr<Player> &player);
std::shared_ptr<PrivateChatChannel> getPrivateChannel(const std::shared_ptr<Player> &player) const;

LuaScriptInterface* getScriptInterface() {
return &scriptInterface;
Expand Down
Loading