mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Changed how the channel live status is stored
This commit is contained in:
parent
1b9fa36e06
commit
1cac80c8ba
|
@ -24,7 +24,6 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
|
||||||
, subscriptionURL("https://www.twitch.tv/subs/" + name)
|
, subscriptionURL("https://www.twitch.tv/subs/" + name)
|
||||||
, channelURL("https://twitch.tv/" + name)
|
, channelURL("https://twitch.tv/" + name)
|
||||||
, popoutPlayerURL("https://player.twitch.tv/?channel=" + name)
|
, popoutPlayerURL("https://player.twitch.tv/?channel=" + name)
|
||||||
, isLive(false)
|
|
||||||
, mod(false)
|
, mod(false)
|
||||||
, readConnecetion(_readConnection)
|
, readConnecetion(_readConnection)
|
||||||
{
|
{
|
||||||
|
@ -176,11 +175,16 @@ void TwitchChannel::addRecentChatter(const std::shared_ptr<messages::Message> &m
|
||||||
|
|
||||||
void TwitchChannel::setLive(bool newLiveStatus)
|
void TwitchChannel::setLive(bool newLiveStatus)
|
||||||
{
|
{
|
||||||
if (this->isLive == newLiveStatus) {
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
||||||
|
if (this->streamStatus.live == newLiveStatus) {
|
||||||
|
// Nothing changed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->isLive = newLiveStatus;
|
this->streamStatus.live = newLiveStatus;
|
||||||
|
}
|
||||||
|
|
||||||
this->onlineStatusChanged();
|
this->onlineStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,13 +243,17 @@ void TwitchChannel::refreshLiveStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stream is live
|
// Stream is live
|
||||||
channel->streamViewerCount = QString::number(stream["viewers"].GetInt());
|
|
||||||
channel->streamGame = stream["game"].GetString();
|
{
|
||||||
channel->streamStatus = streamChannel["status"].GetString();
|
std::lock_guard<std::mutex> lock(channel->streamStatusMutex);
|
||||||
|
channel->streamStatus.viewerCount = stream["viewers"].GetUint();
|
||||||
|
channel->streamStatus.game = stream["game"].GetString();
|
||||||
|
channel->streamStatus.title = streamChannel["status"].GetString();
|
||||||
QDateTime since = QDateTime::fromString(stream["created_at"].GetString(), Qt::ISODate);
|
QDateTime since = QDateTime::fromString(stream["created_at"].GetString(), Qt::ISODate);
|
||||||
auto diff = since.secsTo(QDateTime::currentDateTime());
|
auto diff = since.secsTo(QDateTime::currentDateTime());
|
||||||
channel->streamUptime =
|
channel->streamStatus.uptime =
|
||||||
QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m";
|
QString::number(diff / 3600) + "h " + QString::number(diff % 3600 / 60) + "m";
|
||||||
|
}
|
||||||
|
|
||||||
channel->setLive(true);
|
channel->setLive(true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "singletons/ircmanager.hpp"
|
#include "singletons/ircmanager.hpp"
|
||||||
#include "util/concurrentmap.hpp"
|
#include "util/concurrentmap.hpp"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
@ -20,6 +22,14 @@ class TwitchChannel final : public Channel
|
||||||
QTimer *chattersListTimer;
|
QTimer *chattersListTimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct StreamStatus {
|
||||||
|
bool live = false;
|
||||||
|
unsigned viewerCount = 0;
|
||||||
|
QString title;
|
||||||
|
QString game;
|
||||||
|
QString uptime;
|
||||||
|
};
|
||||||
|
|
||||||
~TwitchChannel() final;
|
~TwitchChannel() final;
|
||||||
|
|
||||||
void reloadChannelEmotes();
|
void reloadChannelEmotes();
|
||||||
|
@ -50,23 +60,33 @@ public:
|
||||||
boost::signals2::signal<void()> userStateChanged;
|
boost::signals2::signal<void()> userStateChanged;
|
||||||
|
|
||||||
QString roomID;
|
QString roomID;
|
||||||
bool isLive;
|
|
||||||
QString streamViewerCount;
|
StreamStatus GetStreamStatus() const
|
||||||
QString streamStatus;
|
{
|
||||||
QString streamGame;
|
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
||||||
QString streamUptime;
|
return this->streamStatus;
|
||||||
|
}
|
||||||
|
|
||||||
struct NameOptions {
|
struct NameOptions {
|
||||||
QString displayName;
|
QString displayName;
|
||||||
QString localizedName;
|
QString localizedName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool IsLive() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->streamStatusMutex);
|
||||||
|
return this->streamStatus.live;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
|
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
|
||||||
|
|
||||||
void setLive(bool newLiveStatus);
|
void setLive(bool newLiveStatus);
|
||||||
void refreshLiveStatus();
|
void refreshLiveStatus();
|
||||||
|
|
||||||
|
mutable std::mutex streamStatusMutex;
|
||||||
|
StreamStatus streamStatus;
|
||||||
|
|
||||||
void fetchRecentMessages();
|
void fetchRecentMessages();
|
||||||
|
|
||||||
boost::signals2::connection connectedConnection;
|
boost::signals2::connection connectedConnection;
|
||||||
|
|
|
@ -112,8 +112,10 @@ QString CommandManager::execCommand(const QString &text, ChannelPtr channel, boo
|
||||||
|
|
||||||
if (!dryRun && twitchChannel != nullptr) {
|
if (!dryRun && twitchChannel != nullptr) {
|
||||||
if (commandName == "/uptime") {
|
if (commandName == "/uptime") {
|
||||||
|
const auto &streamStatus = twitchChannel->GetStreamStatus();
|
||||||
|
|
||||||
QString messageText =
|
QString messageText =
|
||||||
twitchChannel->isLive ? twitchChannel->streamUptime : "Channel is not live.";
|
streamStatus.live ? streamStatus.uptime : "Channel is not live.";
|
||||||
|
|
||||||
channel->addMessage(messages::Message::createSystemMessage(messageText));
|
channel->addMessage(messages::Message::createSystemMessage(messageText));
|
||||||
|
|
||||||
|
|
|
@ -157,30 +157,37 @@ void SplitHeader::updateChannelText()
|
||||||
const QString channelName = this->split->channelName;
|
const QString channelName = this->split->channelName;
|
||||||
if (channelName.isEmpty()) {
|
if (channelName.isEmpty()) {
|
||||||
this->titleLabel->setText("<no channel>");
|
this->titleLabel->setText("<no channel>");
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto channel = this->split->getChannel();
|
auto channel = this->split->getChannel();
|
||||||
|
|
||||||
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
TwitchChannel *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
if (twitchChannel != nullptr && twitchChannel->isLive) {
|
if (twitchChannel != nullptr) {
|
||||||
|
const auto &streamStatus = twitchChannel->GetStreamStatus();
|
||||||
|
|
||||||
|
if (streamStatus.live) {
|
||||||
this->isLive = true;
|
this->isLive = true;
|
||||||
this->tooltip = "<style>.center { text-align: center; }</style>"
|
this->tooltip = "<style>.center { text-align: center; }</style>"
|
||||||
"<p class = \"center\">" +
|
"<p class = \"center\">" +
|
||||||
twitchChannel->streamStatus + "<br><br>" + twitchChannel->streamGame +
|
streamStatus.title + "<br><br>" + streamStatus.game +
|
||||||
"<br>"
|
"<br>"
|
||||||
"Live for " +
|
"Live for " +
|
||||||
twitchChannel->streamUptime + " with " +
|
streamStatus.uptime + " with " +
|
||||||
twitchChannel->streamViewerCount +
|
QString::number(streamStatus.viewerCount) +
|
||||||
" viewers"
|
" viewers"
|
||||||
"</p>";
|
"</p>";
|
||||||
this->titleLabel->setText(channelName + " (live)");
|
this->titleLabel->setText(channelName + " (live)");
|
||||||
} else {
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->isLive = false;
|
this->isLive = false;
|
||||||
this->titleLabel->setText(channelName);
|
this->titleLabel->setText(channelName);
|
||||||
this->tooltip = "";
|
this->tooltip = "";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplitHeader::updateModerationModeIcon()
|
void SplitHeader::updateModerationModeIcon()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue