channels now PART when they are destroyed

This commit is contained in:
fourtf
2018-04-21 00:40:17 +02:00
parent f571a336e0
commit f58ee01cf5
9 changed files with 48 additions and 24 deletions
+14 -6
View File
@@ -95,12 +95,12 @@ void AbstractIrcServer::writeConnectionMessageReceived(Communi::IrcMessage *mess
{
}
std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &dirtyChannelName)
std::shared_ptr<Channel> AbstractIrcServer::getOrAddChannel(const QString &dirtyChannelName)
{
auto channelName = this->CleanChannelName(dirtyChannelName);
auto channelName = this->cleanChannelName(dirtyChannelName);
// try get channel
ChannelPtr chan = this->getChannel(channelName);
ChannelPtr chan = this->getChannelOrEmpty(channelName);
if (chan != Channel::getEmpty()) {
return chan;
}
@@ -121,6 +121,14 @@ std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &dirtyChann
debug::Log("[AbstractIrcServer::addChannel] {} was destroyed", clojuresInCppAreShit);
this->channels.remove(clojuresInCppAreShit);
if (this->readConnection) {
this->readConnection->sendRaw("PART #" + clojuresInCppAreShit);
}
if (this->writeConnection) {
this->writeConnection->sendRaw("PART #" + clojuresInCppAreShit);
}
});
// join irc channel
@@ -139,9 +147,9 @@ std::shared_ptr<Channel> AbstractIrcServer::addChannel(const QString &dirtyChann
return chan;
}
std::shared_ptr<Channel> AbstractIrcServer::getChannel(const QString &dirtyChannelName)
std::shared_ptr<Channel> AbstractIrcServer::getChannelOrEmpty(const QString &dirtyChannelName)
{
auto channelName = this->CleanChannelName(dirtyChannelName);
auto channelName = this->cleanChannelName(dirtyChannelName);
std::lock_guard<std::mutex> lock(this->channelMutex);
@@ -214,7 +222,7 @@ std::shared_ptr<Channel> AbstractIrcServer::getCustomChannel(const QString &chan
return nullptr;
}
QString AbstractIrcServer::CleanChannelName(const QString &dirtyChannelName)
QString AbstractIrcServer::cleanChannelName(const QString &dirtyChannelName)
{
return dirtyChannelName;
}
+3 -3
View File
@@ -27,8 +27,8 @@ public:
void sendMessage(const QString &channelName, const QString &message);
// channels
std::shared_ptr<Channel> addChannel(const QString &dirtyChannelName);
std::shared_ptr<Channel> getChannel(const QString &dirtyChannelName);
std::shared_ptr<Channel> getOrAddChannel(const QString &dirtyChannelName);
std::shared_ptr<Channel> getChannelOrEmpty(const QString &dirtyChannelName);
// signals
pajlada::Signals::NoArgSignal connected;
@@ -56,7 +56,7 @@ protected:
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelName);
virtual QString CleanChannelName(const QString &dirtyChannelName);
virtual QString cleanChannelName(const QString &dirtyChannelName);
QMap<QString, std::weak_ptr<Channel>> channels;
std::mutex channelMutex;