fix: close logging-channels when closing channels (#5592)

Co-authored-by: kornes <28986062+kornes@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2024-09-14 12:17:31 +02:00 committed by GitHub
parent 2afa227139
commit 694cc2dbff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 106 additions and 15 deletions

View file

@ -48,6 +48,7 @@
- Bugfix: Fixed tab visibility being controllable in the emote popup. (#5530) - Bugfix: Fixed tab visibility being controllable in the emote popup. (#5530)
- Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558) - Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558)
- Bugfix: Fixed some tooltips not being readable. (#5578) - Bugfix: Fixed some tooltips not being readable. (#5578)
- Bugfix: Fixed log files being locked longer than needed. (#5592)
- Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420) - Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420)
- Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422) - Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422)
- Dev: Unsingletonize `ISoundController`. (#5462) - Dev: Unsingletonize `ISoundController`. (#5462)

View file

@ -18,6 +18,10 @@ public:
(const QString &channelName, MessagePtr message, (const QString &channelName, MessagePtr message,
const QString &platformName, const QString &streamID), const QString &platformName, const QString &streamID),
(override)); (override));
MOCK_METHOD(void, closeChannel,
(const QString &channelName, const QString &platformName),
(override));
}; };
class EmptyLogging : public ILogging class EmptyLogging : public ILogging
@ -32,6 +36,12 @@ public:
{ {
// //
} }
void closeChannel(const QString &channelName,
const QString &platformName) override
{
//
}
}; };
} // namespace chatterino::mock } // namespace chatterino::mock

View file

@ -149,6 +149,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, args_(_args) , args_(_args)
, themes(new Theme(paths)) , themes(new Theme(paths))
, fonts(new Fonts(_settings)) , fonts(new Fonts(_settings))
, logging(new Logging(_settings))
, emotes(new Emotes) , emotes(new Emotes)
, accounts(new AccountController) , accounts(new AccountController)
, hotkeys(new HotkeyController) , hotkeys(new HotkeyController)
@ -175,7 +176,6 @@ Application::Application(Settings &_settings, const Paths &paths,
, ffzEmotes(new FfzEmotes) , ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes) , seventvEmotes(new SeventvEmotes)
, seventvEventAPI(makeSeventvEventAPI(_settings)) , seventvEventAPI(makeSeventvEventAPI(_settings))
, logging(new Logging(_settings))
, linkResolver(new LinkResolver) , linkResolver(new LinkResolver)
, streamerMode(new StreamerMode) , streamerMode(new StreamerMode)
, twitchUsers(new TwitchUsers) , twitchUsers(new TwitchUsers)
@ -503,6 +503,7 @@ PubSub *Application::getTwitchPubSub()
ILogging *Application::getChatLogger() ILogging *Application::getChatLogger()
{ {
assertInGuiThread(); assertInGuiThread();
assert(this->logging);
return this->logging.get(); return this->logging.get();
} }
@ -697,4 +698,9 @@ IApplication *getApp()
return INSTANCE; return INSTANCE;
} }
IApplication *tryGetApp()
{
return INSTANCE;
}
} // namespace chatterino } // namespace chatterino

View file

@ -144,6 +144,7 @@ public:
private: private:
std::unique_ptr<Theme> themes; std::unique_ptr<Theme> themes;
std::unique_ptr<Fonts> fonts; std::unique_ptr<Fonts> fonts;
const std::unique_ptr<Logging> logging;
std::unique_ptr<Emotes> emotes; std::unique_ptr<Emotes> emotes;
std::unique_ptr<AccountController> accounts; std::unique_ptr<AccountController> accounts;
std::unique_ptr<HotkeyController> hotkeys; std::unique_ptr<HotkeyController> hotkeys;
@ -169,7 +170,6 @@ private:
std::unique_ptr<FfzEmotes> ffzEmotes; std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvEmotes> seventvEmotes; std::unique_ptr<SeventvEmotes> seventvEmotes;
std::unique_ptr<SeventvEventAPI> seventvEventAPI; std::unique_ptr<SeventvEventAPI> seventvEventAPI;
const std::unique_ptr<Logging> logging;
std::unique_ptr<ILinkResolver> linkResolver; std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode; std::unique_ptr<IStreamerMode> streamerMode;
std::unique_ptr<ITwitchUsers> twitchUsers; std::unique_ptr<ITwitchUsers> twitchUsers;
@ -239,4 +239,7 @@ private:
IApplication *getApp(); IApplication *getApp();
/// Might return `nullptr` if the app is being destroyed
IApplication *tryGetApp();
} // namespace chatterino } // namespace chatterino

View file

@ -38,6 +38,11 @@ Channel::Channel(const QString &name, Type type)
Channel::~Channel() Channel::~Channel()
{ {
auto *app = tryGetApp();
if (app)
{
app->getChatLogger()->closeChannel(this->name_, this->platform_);
}
this->destroyed.invoke(); this->destroyed.invoke();
} }

View file

@ -2,7 +2,6 @@
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "singletons/helper/LoggingChannel.hpp" #include "singletons/helper/LoggingChannel.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include <QDir> #include <QDir>
@ -58,7 +57,7 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
auto map = std::map<QString, std::unique_ptr<LoggingChannel>>(); auto map = std::map<QString, std::unique_ptr<LoggingChannel>>();
this->loggingChannels_[platformName] = std::move(map); this->loggingChannels_[platformName] = std::move(map);
auto &ref = this->loggingChannels_.at(platformName); auto &ref = this->loggingChannels_.at(platformName);
ref.emplace(channelName, std::move(channel)); ref.emplace(channelName, channel);
return; return;
} }
auto chanIt = platIt->second.find(channelName); auto chanIt = platIt->second.find(channelName);
@ -66,7 +65,7 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
{ {
auto *channel = new LoggingChannel(channelName, platformName); auto *channel = new LoggingChannel(channelName, platformName);
channel->addMessage(message, streamID); channel->addMessage(message, streamID);
platIt->second.emplace(channelName, std::move(channel)); platIt->second.emplace(channelName, channel);
} }
else else
{ {
@ -74,4 +73,15 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
} }
} }
void Logging::closeChannel(const QString &channelName,
const QString &platformName)
{
auto platIt = this->loggingChannels_.find(platformName);
if (platIt == this->loggingChannels_.end())
{
return;
}
platIt->second.erase(channelName);
}
} // namespace chatterino } // namespace chatterino

View file

@ -24,6 +24,9 @@ public:
virtual void addMessage(const QString &channelName, MessagePtr message, virtual void addMessage(const QString &channelName, MessagePtr message,
const QString &platformName, const QString &platformName,
const QString &streamID) = 0; const QString &streamID) = 0;
virtual void closeChannel(const QString &channelName,
const QString &platformName) = 0;
}; };
class Logging : public ILogging class Logging : public ILogging
@ -35,6 +38,9 @@ public:
const QString &platformName, const QString &platformName,
const QString &streamID) override; const QString &streamID) override;
void closeChannel(const QString &channelName,
const QString &platformName) override;
private: private:
using PlatformName = QString; using PlatformName = QString;
using ChannelName = QString; using ChannelName = QString;

View file

@ -1,6 +1,8 @@
#include "common/ChannelChatters.hpp" #include "common/ChannelChatters.hpp"
#include "mocks/BaseApplication.hpp"
#include "mocks/Channel.hpp" #include "mocks/Channel.hpp"
#include "mocks/Logging.hpp"
#include "Test.hpp" #include "Test.hpp"
#include <QColor> #include <QColor>
@ -9,9 +11,28 @@
using namespace chatterino; using namespace chatterino;
using chatterino::mock::MockChannel; using chatterino::mock::MockChannel;
// Ensure inserting the same user does not increase the size of the stored colors namespace {
TEST(ChatterChatters, insertSameUser)
class MockApplication : public mock::BaseApplication
{ {
public:
MockApplication() = default;
ILogging *getChatLogger() override
{
return &this->logging;
}
mock::EmptyLogging logging;
};
} // namespace
// Ensure inserting the same user does not increase the size of the stored colors
TEST(ChannelChatters, insertSameUser)
{
MockApplication app;
MockChannel channel("test"); MockChannel channel("test");
ChannelChatters chatters(channel); ChannelChatters chatters(channel);
@ -24,8 +45,10 @@ TEST(ChatterChatters, insertSameUser)
} }
// Ensure we can update a chatters color // Ensure we can update a chatters color
TEST(ChatterChatters, insertSameUserUpdatesColor) TEST(ChannelChatters, insertSameUserUpdatesColor)
{ {
MockApplication app;
MockChannel channel("test"); MockChannel channel("test");
ChannelChatters chatters(channel); ChannelChatters chatters(channel);
@ -37,8 +60,10 @@ TEST(ChatterChatters, insertSameUserUpdatesColor)
} }
// Ensure getting a non-existant users color returns an invalid QColor // Ensure getting a non-existant users color returns an invalid QColor
TEST(ChatterChatters, getNonExistantUser) TEST(ChannelChatters, getNonExistantUser)
{ {
MockApplication app;
MockChannel channel("test"); MockChannel channel("test");
ChannelChatters chatters(channel); ChannelChatters chatters(channel);
@ -47,8 +72,10 @@ TEST(ChatterChatters, getNonExistantUser)
} }
// Ensure getting a user doesn't create an entry // Ensure getting a user doesn't create an entry
TEST(ChatterChatters, getDoesNotCreate) TEST(ChannelChatters, getDoesNotCreate)
{ {
MockApplication app;
MockChannel channel("test"); MockChannel channel("test");
ChannelChatters chatters(channel); ChannelChatters chatters(channel);
@ -59,8 +86,10 @@ TEST(ChatterChatters, getDoesNotCreate)
} }
// Ensure the least recently used entry is purged when we reach MAX_SIZE // Ensure the least recently used entry is purged when we reach MAX_SIZE
TEST(ChatterChatters, insertMaxSize) TEST(ChannelChatters, insertMaxSize)
{ {
MockApplication app;
MockChannel channel("test"); MockChannel channel("test");
ChannelChatters chatters(channel); ChannelChatters chatters(channel);

View file

@ -55,11 +55,11 @@ public:
return &this->chatLogger; return &this->chatLogger;
} }
mock::EmptyLogging chatLogger;
AccountController accounts; AccountController accounts;
CommandController commands; CommandController commands;
mock::MockTwitchIrcServer twitch; mock::MockTwitchIrcServer twitch;
Emotes emotes; Emotes emotes;
mock::EmptyLogging chatLogger;
}; };
} // namespace } // namespace

View file

@ -8,6 +8,7 @@
#include "mocks/Channel.hpp" #include "mocks/Channel.hpp"
#include "mocks/ChatterinoBadges.hpp" #include "mocks/ChatterinoBadges.hpp"
#include "mocks/EmptyApplication.hpp" #include "mocks/EmptyApplication.hpp"
#include "mocks/Logging.hpp"
#include "mocks/TwitchIrcServer.hpp" #include "mocks/TwitchIrcServer.hpp"
#include "mocks/UserData.hpp" #include "mocks/UserData.hpp"
#include "providers/ffz/FfzBadges.hpp" #include "providers/ffz/FfzBadges.hpp"
@ -75,6 +76,12 @@ public:
return &this->highlights; return &this->highlights;
} }
ILogging *getChatLogger() override
{
return &this->logging;
}
mock::EmptyLogging logging;
AccountController accounts; AccountController accounts;
Emotes emotes; Emotes emotes;
mock::UserDataController userData; mock::UserDataController userData;

View file

@ -8,6 +8,7 @@
#include "mocks/BaseApplication.hpp" #include "mocks/BaseApplication.hpp"
#include "mocks/Channel.hpp" #include "mocks/Channel.hpp"
#include "mocks/Helix.hpp" #include "mocks/Helix.hpp"
#include "mocks/Logging.hpp"
#include "mocks/TwitchIrcServer.hpp" #include "mocks/TwitchIrcServer.hpp"
#include "singletons/Emotes.hpp" #include "singletons/Emotes.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
@ -69,6 +70,12 @@ public:
return &this->seventvEmotes; return &this->seventvEmotes;
} }
ILogging *getChatLogger() override
{
return &this->logging;
}
mock::EmptyLogging logging;
AccountController accounts; AccountController accounts;
mock::MockTwitchIrcServer twitch; mock::MockTwitchIrcServer twitch;
Emotes emotes; Emotes emotes;
@ -133,9 +140,9 @@ protected:
void TearDown() override void TearDown() override
{ {
this->mockApplication.reset();
this->mockHelix.reset();
this->channelPtr.reset(); this->channelPtr.reset();
this->mockHelix.reset();
this->mockApplication.reset();
} }
std::unique_ptr<MockApplication> mockApplication; std::unique_ptr<MockApplication> mockApplication;

View file

@ -7,6 +7,7 @@
#include "mocks/Channel.hpp" #include "mocks/Channel.hpp"
#include "mocks/ChatterinoBadges.hpp" #include "mocks/ChatterinoBadges.hpp"
#include "mocks/DisabledStreamerMode.hpp" #include "mocks/DisabledStreamerMode.hpp"
#include "mocks/Logging.hpp"
#include "mocks/TwitchIrcServer.hpp" #include "mocks/TwitchIrcServer.hpp"
#include "mocks/UserData.hpp" #include "mocks/UserData.hpp"
#include "providers/ffz/FfzBadges.hpp" #include "providers/ffz/FfzBadges.hpp"
@ -91,6 +92,12 @@ public:
return &this->seventvEmotes; return &this->seventvEmotes;
} }
ILogging *getChatLogger() override
{
return &this->logging;
}
mock::EmptyLogging logging;
AccountController accounts; AccountController accounts;
Emotes emotes; Emotes emotes;
mock::UserDataController userData; mock::UserDataController userData;