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

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;
}

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;

View file

@ -39,7 +39,11 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
QString channelName = words.at(1);
auto channel = TwitchServer::getInstance().getChannel(channelName);
auto channel = TwitchServer::getInstance().getChannelOrEmpty(channelName);
if (channel->isEmpty()) {
return;
}
if (auto twitchChannel = dynamic_cast<twitch::TwitchChannel *>(channel.get())) {
// set the room id of the channel
@ -63,9 +67,9 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
}
// get channel
auto chan = TwitchServer::getInstance().getChannel(chanName);
auto chan = TwitchServer::getInstance().getChannelOrEmpty(chanName);
if (!chan) {
if (chan->isEmpty()) {
debug::Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
chanName);
return;
@ -133,7 +137,11 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
return;
}
auto c = TwitchServer::getInstance().getChannel(channelName);
auto c = TwitchServer::getInstance().getChannelOrEmpty(channelName);
if (c->isEmpty()) {
return;
}
twitch::TwitchChannel *tc = dynamic_cast<twitch::TwitchChannel *>(c.get());
if (tc != nullptr) {
tc->setMod(_mod == "1");
@ -177,7 +185,12 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
{
auto channel = TwitchServer::getInstance().getChannel(message->parameter(0).remove(0, 1));
auto channel =
TwitchServer::getInstance().getChannelOrEmpty(message->parameter(0).remove(0, 1));
if (channel->isEmpty()) {
return;
}
if (message->parameter(1) == "+o") {
channel->modList.append(message->parameter(2));
@ -200,9 +213,9 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
return;
}
auto channel = TwitchServer::getInstance().getChannel(channelName);
auto channel = TwitchServer::getInstance().getChannelOrEmpty(channelName);
if (!channel) {
if (channel->isEmpty()) {
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
channelName);
return;

View file

@ -81,9 +81,9 @@ void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
}
this->onPrivateMessage.invoke(message);
auto chan = TwitchServer::getInstance().getChannel(channelName);
auto chan = TwitchServer::getInstance().getChannelOrEmpty(channelName);
if (!chan) {
if (chan->isEmpty()) {
return;
}
@ -169,7 +169,7 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
func(this->mentionsChannel);
}
QString TwitchServer::CleanChannelName(const QString &dirtyChannelName)
QString TwitchServer::cleanChannelName(const QString &dirtyChannelName)
{
return dirtyChannelName.toLower();
}

View file

@ -35,7 +35,7 @@ protected:
std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
QString CleanChannelName(const QString &dirtyChannelName) override;
QString cleanChannelName(const QString &dirtyChannelName) override;
};
} // namespace twitch

View file

@ -146,7 +146,7 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
util::postToThread([name] {
auto &ts = providers::twitch::TwitchServer::getInstance();
ts.watchingChannel.update(ts.addChannel(name));
ts.watchingChannel.update(ts.getOrAddChannel(name));
});
} else {
qDebug() << "NM unknown channel type";

View file

@ -317,7 +317,7 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
{
QString type = obj.value("type").toString();
if (type == "twitch") {
return providers::twitch::TwitchServer::getInstance().addChannel(
return providers::twitch::TwitchServer::getInstance().getOrAddChannel(
obj.value("name").toString());
} else if (type == "mentions") {
return providers::twitch::TwitchServer::getInstance().mentionsChannel;

View file

@ -182,7 +182,7 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
switch (this->ui.notebook->getSelectedIndex()) {
case TAB_TWITCH: {
if (this->ui.twitch.channel->isChecked()) {
return providers::twitch::TwitchServer::getInstance().addChannel(
return providers::twitch::TwitchServer::getInstance().getOrAddChannel(
this->ui.twitch.channelName->text());
} else if (this->ui.twitch.watching->isChecked()) {
return providers::twitch::TwitchServer::getInstance().watchingChannel;

View file

@ -64,7 +64,10 @@ AppearancePage::AppearancePage()
tbox.append(this->createComboBox({TIMESTAMP_FORMATS}, settings.timestampFormat));
tbox->addStretch(1);
}
messages.append(this->createCheckBox("Show badges", settings.showBadges));
auto checkbox = this->createCheckBox("Show badges", settings.showBadges);
checkbox->setEnabled(false);
messages.append(checkbox);
messages.append(this->createCheckBox("Seperate messages", settings.seperateMessages));
messages.append(
this->createCheckBox("Show message length while typing", settings.showMessageLength));