Added a "CleanChannelName" virtual method to AbstractIrcServer

the TwitchServer implementation makes the channelName full lowercase

Fixes #293
This commit is contained in:
Rasmus Karlsson 2018-04-01 15:10:15 +02:00
parent 58fe1f6dcc
commit d075231081
4 changed files with 22 additions and 4 deletions

View file

@ -95,8 +95,10 @@ void AbstractIrcServer::writeConnectionMessageReceived(Communi::IrcMessage *mess
{ {
} }
std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &channelName) std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &dirtyChannelName)
{ {
auto channelName = this->CleanChannelName(dirtyChannelName);
// try get channel // try get channel
ChannelPtr chan = this->getChannel(channelName); ChannelPtr chan = this->getChannel(channelName);
if (chan != Channel::getEmpty()) { if (chan != Channel::getEmpty()) {
@ -137,8 +139,10 @@ std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &channelNam
return chan; return chan;
} }
std::shared_ptr<Channel> AbstractIrcServer::getChannel(const QString &channelName) std::shared_ptr<Channel> AbstractIrcServer::getChannel(const QString &dirtyChannelName)
{ {
auto channelName = this->CleanChannelName(dirtyChannelName);
std::lock_guard<std::mutex> lock(this->channelMutex); std::lock_guard<std::mutex> lock(this->channelMutex);
// try get special channel // try get special channel
@ -210,6 +214,11 @@ std::shared_ptr<Channel> AbstractIrcServer::getCustomChannel(const QString &chan
return nullptr; return nullptr;
} }
QString AbstractIrcServer::CleanChannelName(const QString &dirtyChannelName)
{
return dirtyChannelName;
}
void AbstractIrcServer::addFakeMessage(const QString &data) void AbstractIrcServer::addFakeMessage(const QString &data)
{ {
auto fakeMessage = Communi::IrcMessage::fromData(data.toUtf8(), this->readConnection.get()); auto fakeMessage = Communi::IrcMessage::fromData(data.toUtf8(), this->readConnection.get());

View file

@ -22,8 +22,8 @@ public:
void sendMessage(const QString &channelName, const QString &message); void sendMessage(const QString &channelName, const QString &message);
// channels // channels
std::shared_ptr<Channel> addChannel(const QString &channelName); std::shared_ptr<Channel> addChannel(const QString &dirtyChannelName);
std::shared_ptr<Channel> getChannel(const QString &channelName); std::shared_ptr<Channel> getChannel(const QString &dirtyChannelName);
// signals // signals
pajlada::Signals::NoArgSignal connected; pajlada::Signals::NoArgSignal connected;
@ -51,6 +51,8 @@ protected:
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelName); virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelName);
virtual QString CleanChannelName(const QString &dirtyChannelName);
QMap<QString, std::weak_ptr<Channel>> channels; QMap<QString, std::weak_ptr<Channel>> channels;
std::mutex channelMutex; std::mutex channelMutex;

View file

@ -168,6 +168,11 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
func(this->mentionsChannel); func(this->mentionsChannel);
} }
QString TwitchServer::CleanChannelName(const QString &dirtyChannelName)
{
return dirtyChannelName.toLower();
}
} // namespace twitch } // namespace twitch
} // namespace providers } // namespace providers
} // namespace chatterino } // namespace chatterino

View file

@ -33,6 +33,8 @@ protected:
virtual void writeConnectionMessageReceived(Communi::IrcMessage *message) override; virtual void writeConnectionMessageReceived(Communi::IrcMessage *message) override;
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override; virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
QString CleanChannelName(const QString &dirtyChannelName) override;
}; };
} // namespace twitch } // namespace twitch