Adds viewer list + livechecks (#105)
* Added check for livestatus + tooltip. * Also added live check on startup. * Added viewerlist + livesearch. * Refactored code to make it compacter.
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
#include "colorscheme.hpp"
|
||||
#include "notebookpage.hpp"
|
||||
#include "settingsmanager.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
#include "widgets/textinputdialog.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDockWidget>
|
||||
#include <QFileInfo>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QListWidget>
|
||||
#include <QPainter>
|
||||
#include <QProcess>
|
||||
#include <QShortcut>
|
||||
@@ -91,6 +94,9 @@ std::shared_ptr<Channel> &ChatWidget::getChannelRef()
|
||||
void ChatWidget::setChannel(std::shared_ptr<Channel> _newChannel)
|
||||
{
|
||||
this->channel = _newChannel;
|
||||
this->channel->roomIDchanged.connect([this](){
|
||||
this->header.checkLive();
|
||||
});
|
||||
|
||||
// on new message
|
||||
this->messageAppendedConnection =
|
||||
@@ -244,6 +250,9 @@ void ChatWidget::doCloseSplit()
|
||||
{
|
||||
NotebookPage *page = static_cast<NotebookPage *>(this->parentWidget());
|
||||
page->removeFromLayout(this);
|
||||
QTimer* timer = this->header.findChild<QTimer*>();
|
||||
timer->stop();
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
void ChatWidget::doChangeChannel()
|
||||
@@ -296,5 +305,83 @@ void ChatWidget::doOpenStreamlink()
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWidget::doOpenViewerList()
|
||||
{
|
||||
auto viewerDock = new QDockWidget("Viewer List",this);
|
||||
viewerDock->setAllowedAreas(Qt::LeftDockWidgetArea);
|
||||
viewerDock->setFeatures(QDockWidget::DockWidgetVerticalTitleBar |
|
||||
QDockWidget::DockWidgetClosable |
|
||||
QDockWidget::DockWidgetFloatable);
|
||||
viewerDock->setMaximumHeight(this->height());
|
||||
viewerDock->resize(0.5*this->width(),this->height());
|
||||
|
||||
auto multiWidget = new QWidget(viewerDock);
|
||||
auto dockVbox = new QVBoxLayout(viewerDock);
|
||||
auto searchBar = new QLineEdit(viewerDock);
|
||||
|
||||
auto chattersList = new QListWidget();
|
||||
auto resultList = new QListWidget();
|
||||
|
||||
static QStringList labels = {"Moderators", "Staff", "Admins", "Global Moderators", "Viewers"};
|
||||
static QStringList jsonLabels = {"moderators", "staff", "admins", "global_mods", "viewers"};
|
||||
QList<QListWidgetItem*> labelList;
|
||||
for(auto &x : labels)
|
||||
{
|
||||
auto label = new QListWidgetItem(x);
|
||||
label->setBackgroundColor(this->colorScheme.ChatHeaderBackground);
|
||||
labelList.append(label);
|
||||
}
|
||||
auto loadingLabel = new QLabel("Loading...");
|
||||
|
||||
util::twitch::get("https://tmi.twitch.tv/group/user/" + channel->name + "/chatters",[=](QJsonObject obj){
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
|
||||
loadingLabel->hide();
|
||||
for(int i = 0; i < jsonLabels.size(); i++)
|
||||
{
|
||||
chattersList->addItem(labelList.at(i));
|
||||
foreach (const QJsonValue & v, chattersObj.value(jsonLabels.at(i)).toArray())
|
||||
chattersList->addItem(v.toString());
|
||||
}
|
||||
});
|
||||
|
||||
searchBar->setPlaceholderText("Search User...");
|
||||
QObject::connect(searchBar,&QLineEdit::textEdited,this,[=](){
|
||||
auto query = searchBar->text();
|
||||
if(!query.isEmpty())
|
||||
{
|
||||
auto results = chattersList->findItems(query,Qt::MatchStartsWith);
|
||||
chattersList->hide();
|
||||
resultList->clear();
|
||||
for (auto & item : results)
|
||||
{
|
||||
if(!labels.contains(item->text()))
|
||||
resultList->addItem(item->text());
|
||||
}
|
||||
resultList->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
resultList->hide();
|
||||
chattersList->show();
|
||||
}
|
||||
});
|
||||
|
||||
QObject::connect(viewerDock,&QDockWidget::topLevelChanged,this,[=](){
|
||||
viewerDock->setMinimumWidth(300);
|
||||
});
|
||||
|
||||
dockVbox->addWidget(searchBar);
|
||||
dockVbox->addWidget(loadingLabel);
|
||||
dockVbox->addWidget(chattersList);
|
||||
dockVbox->addWidget(resultList);
|
||||
resultList->hide();
|
||||
|
||||
multiWidget->setStyleSheet(this->colorScheme.InputStyleSheet);
|
||||
multiWidget->setLayout(dockVbox);
|
||||
viewerDock->setWidget(multiWidget);
|
||||
viewerDock->show();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -115,6 +115,9 @@ public slots:
|
||||
|
||||
// Open twitch channel stream through streamlink
|
||||
void doOpenStreamlink();
|
||||
|
||||
// Open viewer list of the channel
|
||||
void doOpenViewerList();
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "colorscheme.hpp"
|
||||
#include "widgets/chatwidget.hpp"
|
||||
#include "widgets/notebookpage.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDrag>
|
||||
@@ -44,6 +45,7 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
||||
QKeySequence(tr("Ctrl+W")));
|
||||
this->leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
||||
this->leftMenu.addAction("Popup", this->chatWidget, &ChatWidget::doPopup);
|
||||
this->leftMenu.addAction("Open viewer list", this->chatWidget, &ChatWidget::doOpenViewerList);
|
||||
this->leftMenu.addSeparator();
|
||||
this->leftMenu.addAction("Change channel", this->chatWidget, &ChatWidget::doChangeChannel,
|
||||
QKeySequence(tr("Ctrl+R")));
|
||||
@@ -67,16 +69,36 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
|
||||
this->rightLabel.setMinimumWidth(this->height());
|
||||
this->rightLabel.getLabel().setTextFormat(Qt::RichText);
|
||||
this->rightLabel.getLabel().setText("ayy");
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, checkLive);
|
||||
timer->start(60000);
|
||||
}
|
||||
|
||||
void ChatWidgetHeader::updateChannelText()
|
||||
{
|
||||
const std::string channelName = this->chatWidget->channelName;
|
||||
|
||||
if (channelName.empty()) {
|
||||
this->channelNameLabel.setText("<no channel>");
|
||||
} else {
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
||||
if(this->chatWidget->getChannelRef()->isLive)
|
||||
{
|
||||
auto channel = this->chatWidget->getChannelRef();
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName) + " (live)");
|
||||
this->setToolTip("<style>.center { text-align: center; }</style>" \
|
||||
"<p class = \"center\">" + \
|
||||
channel->streamStatus + "<br><br>" + \
|
||||
channel->streamGame + "<br>" \
|
||||
"Live for " + channel->streamUptime + \
|
||||
" with " + channel->streamViewerCount + " viewers" \
|
||||
"</p>"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->channelNameLabel.setText(QString::fromStdString(channelName));
|
||||
this->setToolTip("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,5 +195,30 @@ void ChatWidgetHeader::menuShowChangelog()
|
||||
{
|
||||
}
|
||||
|
||||
void ChatWidgetHeader::checkLive()
|
||||
{
|
||||
auto channel = this->chatWidget->getChannelRef();
|
||||
auto id = QString::fromStdString(channel->roomID);
|
||||
util::twitch::get("https://api.twitch.tv/kraken/streams/" + id,[=](QJsonObject obj){
|
||||
if(obj.value("stream").isNull())
|
||||
{
|
||||
channel->isLive = false;
|
||||
this->updateChannelText();
|
||||
}
|
||||
else
|
||||
{
|
||||
channel->isLive = true;
|
||||
auto stream = obj.value("stream").toObject();
|
||||
channel->streamViewerCount = QString::number(stream.value("viewers").toDouble());
|
||||
channel->streamGame = stream.value("game").toString();
|
||||
channel->streamStatus = stream.value("channel").toObject().value("status").toString();
|
||||
QDateTime since = QDateTime::fromString(stream.value("created_at").toString(),Qt::ISODate);
|
||||
auto diff = since.secsTo(QDateTime::currentDateTime());
|
||||
channel->streamUptime = QString::number(diff/3600) + "h " + QString::number(diff % 3600 / 60) + "m";
|
||||
this->updateChannelText();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -27,9 +27,9 @@ class ChatWidgetHeader : public BaseWidget
|
||||
|
||||
public:
|
||||
explicit ChatWidgetHeader(ChatWidget *_chatWidget);
|
||||
|
||||
// Update channel text from chat widget
|
||||
void updateChannelText();
|
||||
void checkLive();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
@@ -66,6 +66,7 @@ public slots:
|
||||
void menuReloadChannelEmotes();
|
||||
void menuManualReconnect();
|
||||
void menuShowChangelog();
|
||||
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
Reference in New Issue
Block a user