Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prefer visible/selected channels when joining #5850

Merged
merged 5 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading