From d62e45d9dd32921b470c97f8a42142ecf050b470 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 22 Apr 2018 15:36:01 +0200 Subject: [PATCH] Add function for getting a Twitch Channel from a server by its ID --- src/providers/twitch/twitchserver.cpp | 25 +++++++++++++++++++++++++ src/providers/twitch/twitchserver.hpp | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index a013481ed..3fe7e07a9 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -169,6 +169,31 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::functionmentionsChannel); } +std::shared_ptr TwitchServer::getChannelOrEmptyByID(const QString &channelID) +{ + { + std::lock_guard lock(this->channelMutex); + + for (const auto &weakChannel : this->channels) { + auto channel = weakChannel.lock(); + if (!channel) { + continue; + } + + auto twitchChannel = std::dynamic_pointer_cast(channel); + if (!twitchChannel) { + continue; + } + + if (twitchChannel->roomID == channelID) { + return twitchChannel; + } + } + } + + return Channel::getEmpty(); +} + QString TwitchServer::cleanChannelName(const QString &dirtyChannelName) { return dirtyChannelName.toLower(); diff --git a/src/providers/twitch/twitchserver.hpp b/src/providers/twitch/twitchserver.hpp index c529fc610..69052dda1 100644 --- a/src/providers/twitch/twitchserver.hpp +++ b/src/providers/twitch/twitchserver.hpp @@ -20,6 +20,8 @@ public: // fourtf: ugh void forEachChannelAndSpecialChannels(std::function func); + std::shared_ptr getChannelOrEmptyByID(const QString &channelID); + const ChannelPtr whispersChannel; const ChannelPtr mentionsChannel; IndirectChannel watchingChannel;