Skip to content

Commit

Permalink
feat: prefer visible/selected channels when joining (#5850)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Jan 24, 2025
1 parent f4ff62f commit 35b15c4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Minor: Treat all browsers starting with `firefox` as a Firefox browser. (#5805)
- Minor: Remove incognito browser support for `opera/launcher` (this should no longer be a thing). (#5805)
- Minor: Remove incognito browser support for `iexplore`, because internet explorer is EOL. (#5810)
- Minor: When (re-)connecting, visible channels are now joined first. (#5850)
- Bugfix: Fixed a potential way to escape the Lua Plugin sandbox. (#5846)
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
- Bugfix: Fixed a crash that could occur on Linux and macOS when clicking "Install" from the update prompt. (#5818)
Expand Down
37 changes: 24 additions & 13 deletions src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Settings.hpp"
#include "singletons/StreamerMode.hpp"
#include "singletons/WindowManager.hpp"
#include "util/PostToThread.hpp"
#include "util/RatelimitBucket.hpp"

Expand Down Expand Up @@ -935,31 +936,41 @@ void TwitchIrcServer::onReadConnected(IrcConnection *connection)
{
(void)connection;

std::lock_guard lock(this->channelMutex);

// join channels
for (auto &&weak : this->channels)
std::vector<ChannelPtr> activeChannels;
{
if (auto channel = weak.lock())
std::lock_guard lock(this->channelMutex);

activeChannels.reserve(this->channels.size());
for (const auto &weak : this->channels)
{
this->joinBucket_->send(channel->getName());
if (auto channel = weak.lock())
{
activeChannels.push_back(channel);
}
}
}

// put the visible channels first
auto visible = getApp()->getWindows()->getVisibleChannelNames();

std::ranges::stable_partition(activeChannels, [&](const auto &chan) {
return visible.contains(chan->getName());
});

// join channels
for (const auto &channel : activeChannels)
{
this->joinBucket_->send(channel->getName());
}

// connected/disconnected message
auto connectedMsg = makeSystemMessage("connected");
connectedMsg->flags.set(MessageFlag::ConnectedMessage);
auto reconnected = makeSystemMessage("reconnected");
reconnected->flags.set(MessageFlag::ConnectedMessage);

for (std::weak_ptr<Channel> &weak : this->channels.values())
for (const auto &chan : activeChannels)
{
std::shared_ptr<Channel> chan = weak.lock();
if (!chan)
{
continue;
}

LimitedQueueSnapshot<MessagePtr> snapshot = chan->getMessageSnapshot();

bool replaceMessage =
Expand Down
20 changes: 20 additions & 0 deletions src/singletons/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,26 @@ void WindowManager::toggleAllOverlayInertia()
}
}

std::set<QString> WindowManager::getVisibleChannelNames() const
{
std::set<QString> visible;
for (auto *window : this->windows_)
{
auto *page = window->getNotebook().getSelectedPage();
if (!page)
{
continue;
}

for (auto *split : page->getSplits())
{
visible.emplace(split->getChannel()->getName());
}
}

return visible;
}

void WindowManager::encodeTab(SplitContainer *tab, bool isSelected,
QJsonObject &obj)
{
Expand Down
3 changes: 3 additions & 0 deletions src/singletons/WindowManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QTimer>

#include <memory>
#include <set>

namespace chatterino {

Expand Down Expand Up @@ -131,6 +132,8 @@ class WindowManager final
/// Toggles the inertia in all open overlay windows
void toggleAllOverlayInertia();

std::set<QString> getVisibleChannelNames() const;

/// Signals
pajlada::Signals::NoArgSignal gifRepaintRequested;

Expand Down

0 comments on commit 35b15c4

Please sign in to comment.