From ce947a89d7483d04a5344aa9432b9617684c409b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sat, 13 Mar 2021 17:54:34 +0100 Subject: [PATCH] Fixed deprecated method QTime::elapsed (#2504) Co-authored-by: pajlada --- src/providers/twitch/TwitchChannel.cpp | 33 ++++++++++++++------------ src/providers/twitch/TwitchChannel.hpp | 5 ++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index e51512a5a..91670206e 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -36,7 +36,7 @@ namespace chatterino { namespace { constexpr char MAGIC_MESSAGE_SUFFIX[] = u8" \U000E0000"; - constexpr int TITLE_REFRESH_PERIOD = 10; + constexpr int TITLE_REFRESH_PERIOD = 10000; constexpr int CLIP_CREATION_COOLDOWN = 5000; const QString CLIPS_LINK("https://clips.twitch.tv/%1"); const QString CLIPS_FAILURE_CLIPS_DISABLED_TEXT( @@ -159,7 +159,6 @@ TwitchChannel::TwitchChannel(const QString &name, , bttvEmotes_(std::make_shared()) , ffzEmotes_(std::make_shared()) , mod_(false) - , titleRefreshedTime_(QTime::currentTime().addSecs(-TITLE_REFRESH_PERIOD)) { qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened"; @@ -587,20 +586,20 @@ void TwitchChannel::setLive(bool newLiveStatus) void TwitchChannel::refreshTitle() { - auto roomID = this->roomId(); - if (roomID.isEmpty()) + // timer has never started, proceed and start it + if (!this->titleRefreshedTimer_.isValid()) + { + this->titleRefreshedTimer_.start(); + } + else if (this->roomId().isEmpty() || + this->titleRefreshedTimer_.elapsed() < TITLE_REFRESH_PERIOD) { return; } - - if (this->titleRefreshedTime_.elapsed() < TITLE_REFRESH_PERIOD * 1000) - { - return; - } - this->titleRefreshedTime_ = QTime::currentTime(); + this->titleRefreshedTimer_.restart(); getHelix()->getChannel( - roomID, + this->roomId(), [this, weak = weakOf(this)](HelixChannel channel) { ChannelPtr shared = weak.lock(); @@ -956,8 +955,13 @@ void TwitchChannel::createClip() return; } - if (QTime().currentTime() < this->timeNextClipCreationAllowed_ || - this->isClipCreationInProgress) + // timer has never started, proceed and start it + if (!this->clipCreationTimer_.isValid()) + { + this->clipCreationTimer_.start(); + } + else if (this->clipCreationTimer_.elapsed() < CLIP_CREATION_COOLDOWN || + this->isClipCreationInProgress) { return; } @@ -1037,8 +1041,7 @@ void TwitchChannel::createClip() }, // finallyCallback - this will always execute, so clip creation won't ever be stuck [this] { - this->timeNextClipCreationAllowed_ = - QTime().currentTime().addMSecs(CLIP_CREATION_COOLDOWN); + this->clipCreationTimer_.restart(); this->isClipCreationInProgress = false; }); } diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index f29eee4fe..a6f74f47b 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -188,8 +189,8 @@ private: QObject lifetimeGuard_; QTimer liveStatusTimer_; QTimer chattersListTimer_; - QTime titleRefreshedTime_; - QTime timeNextClipCreationAllowed_{QTime().currentTime()}; + QElapsedTimer titleRefreshedTimer_; + QElapsedTimer clipCreationTimer_; bool isClipCreationInProgress{false}; friend class TwitchIrcServer;