Add function for getting a Twitch Channel from a server by its ID

This commit is contained in:
Rasmus Karlsson 2018-04-22 15:36:01 +02:00
parent 3dad7e778a
commit d62e45d9dd
2 changed files with 27 additions and 0 deletions

View file

@ -169,6 +169,31 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
func(this->mentionsChannel);
}
std::shared_ptr<Channel> TwitchServer::getChannelOrEmptyByID(const QString &channelID)
{
{
std::lock_guard<std::mutex> lock(this->channelMutex);
for (const auto &weakChannel : this->channels) {
auto channel = weakChannel.lock();
if (!channel) {
continue;
}
auto twitchChannel = std::dynamic_pointer_cast<TwitchChannel>(channel);
if (!twitchChannel) {
continue;
}
if (twitchChannel->roomID == channelID) {
return twitchChannel;
}
}
}
return Channel::getEmpty();
}
QString TwitchServer::cleanChannelName(const QString &dirtyChannelName)
{
return dirtyChannelName.toLower();

View file

@ -20,6 +20,8 @@ public:
// fourtf: ugh
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
std::shared_ptr<Channel> getChannelOrEmptyByID(const QString &channelID);
const ChannelPtr whispersChannel;
const ChannelPtr mentionsChannel;
IndirectChannel watchingChannel;