From 698814a21f52d3cc06fe9a0e970330330009fcef Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 11 Jun 2018 11:51:46 +0200 Subject: [PATCH] Fix live status tooltip not updating properly The issue was the TwitchChannel refreshLiveStatus function not calling the updateLiveInfo signal properly Fix #461 --- src/providers/twitch/twitchchannel.cpp | 32 +++++++++++++++++--------- src/providers/twitch/twitchchannel.hpp | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index 2feba3c49..9b1f3a4b7 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -31,19 +31,11 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection { debug::Log("[TwitchChannel:{}] Opened", this->name); + this->startRefreshLiveStatusTimer(60 * 1000); + auto app = getApp(); this->reloadChannelEmotes(); - this->liveStatusTimer = new QTimer; - QObject::connect(this->liveStatusTimer, &QTimer::timeout, [this]() { - this->refreshLiveStatus(); // - }); - this->liveStatusTimer->start(60000); - - this->roomIDchanged.connect([this]() { - this->refreshLiveStatus(); // - }); - this->managedConnect(app->accounts->twitch.currentUserChanged, [this]() { this->setMod(false); }); @@ -318,6 +310,7 @@ void TwitchChannel::setLive(bool newLiveStatus) void TwitchChannel::refreshLiveStatus() { if (this->roomID.isEmpty()) { + debug::Log("[TwitchChannel:{}] Refreshing live status (Missing ID)", this->name); this->setLive(false); return; } @@ -373,6 +366,7 @@ void TwitchChannel::refreshLiveStatus() { std::lock_guard lock(channel->streamStatusMutex); + channel->streamStatus.live = true; channel->streamStatus.viewerCount = stream["viewers"].GetUint(); channel->streamStatus.game = stream["game"].GetString(); channel->streamStatus.title = streamChannel["status"].GetString(); @@ -400,10 +394,26 @@ void TwitchChannel::refreshLiveStatus() } } - channel->setLive(true); + // Signal all listeners that the stream status has been updated + channel->updateLiveInfo.invoke(); }); } +void TwitchChannel::startRefreshLiveStatusTimer(int intervalMS) +{ + this->liveStatusTimer = new QTimer; + QObject::connect(this->liveStatusTimer, &QTimer::timeout, [this]() { + this->refreshLiveStatus(); // + }); + + // When the Room ID of a twitch channel has been set, refresh the live status an extra time + this->roomIDchanged.connect([this]() { + this->refreshLiveStatus(); // + }); + + this->liveStatusTimer->start(intervalMS); +} + void TwitchChannel::fetchRecentMessages() { static QString genericURL = diff --git a/src/providers/twitch/twitchchannel.hpp b/src/providers/twitch/twitchchannel.hpp index d1637b859..3811cc3ec 100644 --- a/src/providers/twitch/twitchchannel.hpp +++ b/src/providers/twitch/twitchchannel.hpp @@ -100,6 +100,7 @@ private: void setLive(bool newLiveStatus); void refreshLiveStatus(); + void startRefreshLiveStatusTimer(int intervalMS); mutable std::mutex streamStatusMutex; StreamStatus streamStatus;