From d075231081ade44e3debd94b9537d7ec5cb93d86 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 1 Apr 2018 15:10:15 +0200 Subject: [PATCH] Added a "CleanChannelName" virtual method to AbstractIrcServer the TwitchServer implementation makes the channelName full lowercase Fixes #293 --- src/providers/irc/abstractircserver.cpp | 13 +++++++++++-- src/providers/irc/abstractircserver.hpp | 6 ++++-- src/providers/twitch/twitchserver.cpp | 5 +++++ src/providers/twitch/twitchserver.hpp | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/providers/irc/abstractircserver.cpp b/src/providers/irc/abstractircserver.cpp index 83450b65c..4bd95a0de 100644 --- a/src/providers/irc/abstractircserver.cpp +++ b/src/providers/irc/abstractircserver.cpp @@ -95,8 +95,10 @@ void AbstractIrcServer::writeConnectionMessageReceived(Communi::IrcMessage *mess { } -std::shared_ptr AbstractIrcServer::addChannel(const QString &channelName) +std::shared_ptr AbstractIrcServer::addChannel(const QString &dirtyChannelName) { + auto channelName = this->CleanChannelName(dirtyChannelName); + // try get channel ChannelPtr chan = this->getChannel(channelName); if (chan != Channel::getEmpty()) { @@ -137,8 +139,10 @@ std::shared_ptr AbstractIrcServer::addChannel(const QString &channelNam return chan; } -std::shared_ptr AbstractIrcServer::getChannel(const QString &channelName) +std::shared_ptr AbstractIrcServer::getChannel(const QString &dirtyChannelName) { + auto channelName = this->CleanChannelName(dirtyChannelName); + std::lock_guard lock(this->channelMutex); // try get special channel @@ -210,6 +214,11 @@ std::shared_ptr AbstractIrcServer::getCustomChannel(const QString &chan return nullptr; } +QString AbstractIrcServer::CleanChannelName(const QString &dirtyChannelName) +{ + return dirtyChannelName; +} + void AbstractIrcServer::addFakeMessage(const QString &data) { auto fakeMessage = Communi::IrcMessage::fromData(data.toUtf8(), this->readConnection.get()); diff --git a/src/providers/irc/abstractircserver.hpp b/src/providers/irc/abstractircserver.hpp index 823071f80..266c2226d 100644 --- a/src/providers/irc/abstractircserver.hpp +++ b/src/providers/irc/abstractircserver.hpp @@ -22,8 +22,8 @@ public: void sendMessage(const QString &channelName, const QString &message); // channels - std::shared_ptr addChannel(const QString &channelName); - std::shared_ptr getChannel(const QString &channelName); + std::shared_ptr addChannel(const QString &dirtyChannelName); + std::shared_ptr getChannel(const QString &dirtyChannelName); // signals pajlada::Signals::NoArgSignal connected; @@ -51,6 +51,8 @@ protected: virtual std::shared_ptr getCustomChannel(const QString &channelName); + virtual QString CleanChannelName(const QString &dirtyChannelName); + QMap> channels; std::mutex channelMutex; diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index 1ea956910..aec19a32e 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -168,6 +168,11 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::functionmentionsChannel); } +QString TwitchServer::CleanChannelName(const QString &dirtyChannelName) +{ + return dirtyChannelName.toLower(); +} + } // namespace twitch } // namespace providers } // namespace chatterino diff --git a/src/providers/twitch/twitchserver.hpp b/src/providers/twitch/twitchserver.hpp index 9932204b2..891868aef 100644 --- a/src/providers/twitch/twitchserver.hpp +++ b/src/providers/twitch/twitchserver.hpp @@ -33,6 +33,8 @@ protected: virtual void writeConnectionMessageReceived(Communi::IrcMessage *message) override; virtual std::shared_ptr getCustomChannel(const QString &channelname) override; + + QString CleanChannelName(const QString &dirtyChannelName) override; }; } // namespace twitch