From 655831d154d08b1906fdbf4e935024f40d0bc01f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 30 Mar 2018 15:42:59 +0200 Subject: [PATCH] Add setting to not fetch chatters for bigger streamers Work on #57 --- src/providers/twitch/twitchchannel.cpp | 9 +++++++++ src/singletons/settingsmanager.hpp | 7 +++++++ src/widgets/settingspages/behaviourpage.cpp | 17 +++++++++++++++-- src/widgets/settingspages/settingspage.cpp | 14 ++++++++++++++ src/widgets/settingspages/settingspage.hpp | 2 ++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index e6562c3a8..45b22e69f 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -59,6 +59,15 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection }; auto doRefreshChatters = [=]() { + const auto streamStatus = this->GetStreamStatus(); + + auto &settingManager = singletons::SettingManager::getInstance(); + if (settingManager.onlyFetchChattersForSmallerStreamers) { + if (streamStatus.live && streamStatus.viewerCount > settingManager.smallStreamerLimit) { + return; + } + } + util::twitch::get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters", QThread::currentThread(), refreshChatters); }; diff --git a/src/singletons/settingsmanager.hpp b/src/singletons/settingsmanager.hpp index b3dce5221..0e3979923 100644 --- a/src/singletons/settingsmanager.hpp +++ b/src/singletons/settingsmanager.hpp @@ -50,6 +50,13 @@ public: BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", true}; BoolSetting mentionUsersWithAt = {"/behaviour/mentionUsersWithAt", false}; FloatSetting mouseScrollMultiplier = {"/behaviour/mouseScrollMultiplier", 1.0}; + + // Auto-completion + BoolSetting onlyFetchChattersForSmallerStreamers = { + "/behaviour/autocompletion/onlyFetchChattersForSmallerStreamers", true}; + IntSetting smallStreamerLimit = {"/behaviour/autocompletion/smallStreamerLimit", 1000}; + + // Streamlink QStringSetting streamlinkPath = {"/behaviour/streamlink/path", ""}; QStringSetting preferredQuality = {"/behaviour/streamlink/quality", "Choose"}; QStringSetting streamlinkOpts = {"/behaviour/streamlink/options", ""}; diff --git a/src/widgets/settingspages/behaviourpage.cpp b/src/widgets/settingspages/behaviourpage.cpp index 82419e106..c596d2104 100644 --- a/src/widgets/settingspages/behaviourpage.cpp +++ b/src/widgets/settingspages/behaviourpage.cpp @@ -12,6 +12,8 @@ #define LAST_MSG "Show last read message indicator (marks the spot where you left the window)" #define PAUSE_HOVERING "When hovering" +#define LIMIT_CHATTERS_FOR_SMALLER_STREAMERS "Only fetch chatters list for viewers under X viewers" + #define STREAMLINK_QUALITY "Choose", "Source", "High", "Medium", "Low", "Audio only" namespace chatterino { @@ -39,8 +41,19 @@ BehaviourPage::BehaviourPage() layout->addSpacing(16); - auto group = layout.emplace("Streamlink"); { + auto group = layout.emplace("Auto-completion"); + auto groupLayout = group.setLayoutType(); + groupLayout->addRow( + LIMIT_CHATTERS_FOR_SMALLER_STREAMERS, + this->createCheckBox("", settings.onlyFetchChattersForSmallerStreamers)); + + groupLayout->addRow("What viewer count counts as a \"smaller streamer\"", + this->createSpinBox(settings.smallStreamerLimit, 10, 50000)); + } + + { + auto group = layout.emplace("Streamlink"); auto groupLayout = group.setLayoutType(); groupLayout->addRow("Streamlink path:", this->createLineEdit(settings.streamlinkPath)); groupLayout->addRow("Prefered quality:", @@ -53,7 +66,7 @@ BehaviourPage::BehaviourPage() QSlider *BehaviourPage::createMouseScrollSlider() { - QSlider *slider = new QSlider(Qt::Horizontal); + auto slider = new QSlider(Qt::Horizontal); float currentValue = singletons::SettingManager::getInstance().mouseScrollMultiplier; int sliderValue = ((currentValue - 0.1f) / 2.f) * 99.f; diff --git a/src/widgets/settingspages/settingspage.cpp b/src/widgets/settingspages/settingspage.cpp index ca9153ba3..1d6bb9d2f 100644 --- a/src/widgets/settingspages/settingspage.cpp +++ b/src/widgets/settingspages/settingspage.cpp @@ -79,6 +79,20 @@ QLineEdit *SettingsPage::createLineEdit(pajlada::Settings::Setting &set return edit; } +QSpinBox *SettingsPage::createSpinBox(pajlada::Settings::Setting &setting, int min, int max) +{ + QSpinBox *w = new QSpinBox; + + w->setMinimum(min); + w->setMaximum(max); + + setting.connect([w](const int &value, auto) { w->setValue(value); }); + QObject::connect(w, QOverload::of(&QSpinBox::valueChanged), + [&setting](int value) { setting.setValue(value); }); + + return w; +} + } // namespace settingspages } // namespace widgets } // namespace chatterino diff --git a/src/widgets/settingspages/settingspage.hpp b/src/widgets/settingspages/settingspage.hpp index e669f37f9..1e800878a 100644 --- a/src/widgets/settingspages/settingspage.hpp +++ b/src/widgets/settingspages/settingspage.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "singletons/settingsmanager.hpp" @@ -25,6 +26,7 @@ public: QComboBox *createComboBox(const QStringList &items, pajlada::Settings::Setting &setting); QLineEdit *createLineEdit(pajlada::Settings::Setting &setting); + QSpinBox *createSpinBox(pajlada::Settings::Setting &setting, int min = 0, int max = 2500); protected: QString name;