Merge branch 'master' of https://github.com/fourtf/chatterino2
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "widgets/accountpopup.hpp"
|
||||
#include "util/urlfetch.hpp"
|
||||
#include "accountmanager.hpp"
|
||||
#include "channel.hpp"
|
||||
#include "credentials.hpp"
|
||||
#include "settingsmanager.hpp"
|
||||
#include "ui_accountpopupform.h"
|
||||
#include "util/urlfetch.hpp"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
@@ -32,20 +32,16 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> channel)
|
||||
SettingsManager &settings = SettingsManager::getInstance();
|
||||
|
||||
permission = permissions::User;
|
||||
for(auto button : this->_ui->profileLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
for (auto button : this->_ui->profileLayout->findChildren<QPushButton *>()) {
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->userLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
for (auto button : this->_ui->userLayout->findChildren<QPushButton *>()) {
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->modLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
for (auto button : this->_ui->modLayout->findChildren<QPushButton *>()) {
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->ownerLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
for (auto button : this->_ui->ownerLayout->findChildren<QPushButton *>()) {
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
|
||||
@@ -60,41 +56,42 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> channel)
|
||||
sendCommand(this->_ui->mod, "/mod ");
|
||||
sendCommand(this->_ui->unMod, "/unmod ");
|
||||
|
||||
QObject::connect(this->_ui->profile, &QPushButton::clicked, this, [=](){
|
||||
QDesktopServices::openUrl(QUrl("https://twitch.tv/" +
|
||||
this->_ui->lblUsername->text()));
|
||||
auto &accountManager = AccountManager::getInstance();
|
||||
QString userId;
|
||||
QString userNickname;
|
||||
auto currentTwitchUser = accountManager.Twitch.getCurrent();
|
||||
if (currentTwitchUser) {
|
||||
userId = currentTwitchUser->getUserId();
|
||||
userNickname = currentTwitchUser->getNickName();
|
||||
}
|
||||
|
||||
QObject::connect(this->_ui->profile, &QPushButton::clicked, this, [=]() {
|
||||
QDesktopServices::openUrl(QUrl("https://twitch.tv/" + this->_ui->lblUsername->text()));
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->sendMessage, &QPushButton::clicked, this, [=](){
|
||||
QDesktopServices::openUrl(QUrl("https://www.twitch.tv/message/compose?to=" +
|
||||
this->_ui->lblUsername->text()));
|
||||
QObject::connect(this->_ui->sendMessage, &QPushButton::clicked, this, [=]() {
|
||||
QDesktopServices::openUrl(
|
||||
QUrl("https://www.twitch.tv/message/compose?to=" + this->_ui->lblUsername->text()));
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->copy, &QPushButton::clicked, this, [=](){
|
||||
QApplication::clipboard()->setText(this->_ui->lblUsername->text());
|
||||
QObject::connect(this->_ui->copy, &QPushButton::clicked, this,
|
||||
[=]() { QApplication::clipboard()->setText(this->_ui->lblUsername->text()); });
|
||||
|
||||
QObject::connect(this->_ui->follow, &QPushButton::clicked, this, [=]() {
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + userId + "/follows/channels/" +
|
||||
this->userID);
|
||||
|
||||
util::twitch::put(requestUrl,
|
||||
[](QJsonObject obj) { qDebug() << "follows channel: " << obj; });
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->follow, &QPushButton::clicked, this, [=](){
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" +
|
||||
AccountManager::getInstance().getTwitchUser().getUserId() +
|
||||
"/follows/channels/" + this->userID);
|
||||
QObject::connect(this->_ui->ignore, &QPushButton::clicked, this, [=]() {
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + userId + "/blocks/" + this->userID);
|
||||
|
||||
util::twitch::put(requestUrl,[](QJsonObject obj){
|
||||
qDebug() << "follows channel: " << obj;
|
||||
});
|
||||
util::twitch::put(requestUrl, [](QJsonObject obj) { qDebug() << "blocks user: " << obj; });
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->ignore, &QPushButton::clicked, this, [=](){
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" +
|
||||
AccountManager::getInstance().getTwitchUser().getUserId() +
|
||||
"/blocks/" + this->userID);
|
||||
|
||||
util::twitch::put(requestUrl,[](QJsonObject obj){
|
||||
qDebug() << "blocks user: " << obj;
|
||||
});
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->disableHighlights, &QPushButton::clicked, this, [=, &settings](){
|
||||
QObject::connect(this->_ui->disableHighlights, &QPushButton::clicked, this, [=, &settings]() {
|
||||
QString str = settings.highlightUserBlacklist.getnonConst();
|
||||
str.append(this->_ui->lblUsername->text() + "\n");
|
||||
settings.highlightUserBlacklist.set(str);
|
||||
@@ -102,7 +99,7 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> channel)
|
||||
this->_ui->enableHighlights->show();
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->enableHighlights, &QPushButton::clicked, this, [=, &settings](){
|
||||
QObject::connect(this->_ui->enableHighlights, &QPushButton::clicked, this, [=, &settings]() {
|
||||
QString str = settings.highlightUserBlacklist.getnonConst();
|
||||
QStringList list = str.split("\n");
|
||||
list.removeAll(this->_ui->lblUsername->text());
|
||||
@@ -111,20 +108,17 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> channel)
|
||||
this->_ui->disableHighlights->show();
|
||||
});
|
||||
|
||||
|
||||
updateButtons(this->_ui->userLayout,false);
|
||||
updateButtons(this->_ui->modLayout,false);
|
||||
updateButtons(this->_ui->ownerLayout,false);
|
||||
updateButtons(this->_ui->userLayout, false);
|
||||
updateButtons(this->_ui->modLayout, false);
|
||||
updateButtons(this->_ui->ownerLayout, false);
|
||||
|
||||
// Close button
|
||||
connect(_ui->btnClose, &QPushButton::clicked, [=]() {
|
||||
hide(); //
|
||||
});
|
||||
|
||||
util::twitch::getUserID(AccountManager::getInstance().getTwitchUser().getNickName(), this,
|
||||
[=](const QString &id){
|
||||
AccountManager::getInstance().getTwitchUser().setUserId(id);
|
||||
});
|
||||
util::twitch::getUserID(userNickname, this,
|
||||
[=](const QString &id) { currentTwitchUser->setUserId(id); });
|
||||
}
|
||||
|
||||
void AccountPopupWidget::setName(const QString &name)
|
||||
@@ -140,7 +134,7 @@ void AccountPopupWidget::setChannel(std::shared_ptr<Channel> channel)
|
||||
|
||||
void AccountPopupWidget::getUserId()
|
||||
{
|
||||
util::twitch::getUserID(this->_ui->lblUsername->text(), this, [=](const QString &id){
|
||||
util::twitch::getUserID(this->_ui->lblUsername->text(), this, [=](const QString &id) {
|
||||
userID = id;
|
||||
getUserData();
|
||||
});
|
||||
@@ -148,13 +142,14 @@ void AccountPopupWidget::getUserId()
|
||||
|
||||
void AccountPopupWidget::getUserData()
|
||||
{
|
||||
util::twitch::get("https://api.twitch.tv/kraken/channels/" + userID, this, [=](const QJsonObject &obj){
|
||||
_ui->lblFollowers->setText(QString::number(obj.value("followers").toInt()));
|
||||
_ui->lblViews->setText(QString::number(obj.value("views").toInt()));
|
||||
_ui->lblAccountAge->setText(obj.value("created_at").toString().section("T", 0, 0));
|
||||
util::twitch::get(
|
||||
"https://api.twitch.tv/kraken/channels/" + userID, this, [=](const QJsonObject &obj) {
|
||||
_ui->lblFollowers->setText(QString::number(obj.value("followers").toInt()));
|
||||
_ui->lblViews->setText(QString::number(obj.value("views").toInt()));
|
||||
_ui->lblAccountAge->setText(obj.value("created_at").toString().section("T", 0, 0));
|
||||
|
||||
loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
});
|
||||
loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
|
||||
@@ -185,35 +180,40 @@ void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
|
||||
|
||||
void AccountPopupWidget::updatePermissions()
|
||||
{
|
||||
if(this->_channel.get()->name == AccountManager::getInstance().getTwitchUser().getNickName())
|
||||
{
|
||||
permission = permissions::Owner;
|
||||
AccountManager &accountManager = AccountManager::getInstance();
|
||||
auto currentTwitchUser = accountManager.Twitch.getCurrent();
|
||||
if (!currentTwitchUser) {
|
||||
// No twitch user set (should never happen)
|
||||
return;
|
||||
}
|
||||
else if(this->_channel->modList.contains(AccountManager::getInstance().getTwitchUser().getNickName()))
|
||||
{
|
||||
|
||||
if (this->_channel.get()->name == currentTwitchUser->getNickName()) {
|
||||
permission = permissions::Owner;
|
||||
} else if (this->_channel->modList.contains(currentTwitchUser->getNickName())) {
|
||||
// XXX(pajlada): This might always trigger if user is anonymous (if nickName is empty?)
|
||||
permission = permissions::Mod;
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPopupWidget::updateButtons(QWidget* layout, bool state)
|
||||
void AccountPopupWidget::updateButtons(QWidget *layout, bool state)
|
||||
{
|
||||
for(auto button : layout->findChildren<QPushButton*>())
|
||||
{
|
||||
for (auto button : layout->findChildren<QPushButton *>()) {
|
||||
button->setVisible(state);
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPopupWidget::timeout(QPushButton *button, int time)
|
||||
{
|
||||
QObject::connect(button, &QPushButton::clicked, this, [=](){
|
||||
this->_channel->sendMessage("/timeout " + this->_ui->lblUsername->text() + " " + QString::number(time));
|
||||
QObject::connect(button, &QPushButton::clicked, this, [=]() {
|
||||
this->_channel->sendMessage("/timeout " + this->_ui->lblUsername->text() + " " +
|
||||
QString::number(time));
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::sendCommand(QPushButton *button, QString command)
|
||||
{
|
||||
QObject::connect(button, &QPushButton::clicked, this, [=](){
|
||||
this->_channel->sendMessage(command + this->_ui->lblUsername->text());
|
||||
QObject::connect(button, &QPushButton::clicked, this, [=]() {
|
||||
this->_channel->sendMessage(command + this->_ui->lblUsername->text());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -229,42 +229,39 @@ void AccountPopupWidget::focusOutEvent(QFocusEvent *event)
|
||||
|
||||
void AccountPopupWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
if(this->_ui->lblUsername->text() != AccountManager::getInstance().getTwitchUser().getNickName())
|
||||
{
|
||||
AccountManager &accountManager = AccountManager::getInstance();
|
||||
auto currentTwitchUser = accountManager.Twitch.getCurrent();
|
||||
if (!currentTwitchUser) {
|
||||
// No twitch user set (should never happen)
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->_ui->lblUsername->text() != currentTwitchUser->getNickName()) {
|
||||
updateButtons(this->_ui->userLayout, true);
|
||||
if(permission != permissions::User)
|
||||
{
|
||||
if(!this->_channel->modList.contains(this->_ui->lblUsername->text()))
|
||||
{
|
||||
if (permission != permissions::User) {
|
||||
if (!this->_channel->modList.contains(this->_ui->lblUsername->text())) {
|
||||
updateButtons(this->_ui->modLayout, true);
|
||||
}
|
||||
if(permission == permissions::Owner)
|
||||
{
|
||||
if (permission == permissions::Owner) {
|
||||
updateButtons(this->_ui->ownerLayout, true);
|
||||
updateButtons(this->_ui->modLayout, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
updateButtons(this->_ui->modLayout, false);
|
||||
updateButtons(this->_ui->userLayout, false);
|
||||
updateButtons(this->_ui->ownerLayout, false);
|
||||
}
|
||||
|
||||
QString blacklisted = SettingsManager::getInstance().highlightUserBlacklist.getnonConst();
|
||||
QStringList list = blacklisted.split("\n",QString::SkipEmptyParts);
|
||||
if(list.contains(this->_ui->lblUsername->text(),Qt::CaseInsensitive))
|
||||
{
|
||||
QStringList list = blacklisted.split("\n", QString::SkipEmptyParts);
|
||||
if (list.contains(this->_ui->lblUsername->text(), Qt::CaseInsensitive)) {
|
||||
this->_ui->disableHighlights->hide();
|
||||
this->_ui->enableHighlights->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this->_ui->disableHighlights->show();
|
||||
this->_ui->enableHighlights->hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "concurrentmap.hpp"
|
||||
#include "twitch/twitchchannel.hpp"
|
||||
|
||||
@@ -35,9 +36,9 @@ private:
|
||||
void getUserData();
|
||||
void loadAvatar(const QUrl &avatarUrl);
|
||||
|
||||
void updateButtons(QWidget* layout, bool state);
|
||||
void timeout(QPushButton* button, int time);
|
||||
void sendCommand(QPushButton* button, QString command);
|
||||
void updateButtons(QWidget *layout, bool state);
|
||||
void timeout(QPushButton *button, int time);
|
||||
void sendCommand(QPushButton *button, QString command);
|
||||
|
||||
enum class permissions { User, Mod, Owner };
|
||||
permissions permission;
|
||||
|
||||
@@ -802,7 +802,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
|
||||
float distance = util::distanceBetweenPoints(this->lastPressPosition, event->screenPos());
|
||||
|
||||
qDebug() << "Distance: " << distance;
|
||||
// qDebug() << "Distance: " << distance;
|
||||
|
||||
if (fabsf(distance) > 15.f) {
|
||||
// It wasn't a proper click, so we don't care about that here
|
||||
|
||||
@@ -129,13 +129,14 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
|
||||
// listview
|
||||
auto listWidget = new QListWidget(this);
|
||||
|
||||
for (auto &user : AccountManager::getInstance().getTwitchUsers()) {
|
||||
listWidget->addItem(user.getUserName());
|
||||
for (const auto &userName : AccountManager::getInstance().Twitch.getUsernames()) {
|
||||
listWidget->addItem(userName);
|
||||
}
|
||||
|
||||
// Select the currently logged in user
|
||||
if (listWidget->count() > 0) {
|
||||
const auto ¤tUser = AccountManager::getInstance().getTwitchUser();
|
||||
QString currentUsername = currentUser.getUserName();
|
||||
const QString ¤tUsername =
|
||||
AccountManager::getInstance().Twitch.getCurrent()->getUserName();
|
||||
for (int i = 0; i < listWidget->count(); ++i) {
|
||||
QString itemText = listWidget->item(i)->text();
|
||||
if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) {
|
||||
@@ -147,7 +148,8 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
|
||||
|
||||
QObject::connect(listWidget, &QListWidget::clicked, this, [&, listWidget] {
|
||||
if (!listWidget->selectedItems().isEmpty()) {
|
||||
AccountManager::getInstance().setCurrentTwitchUser(listWidget->currentItem()->text());
|
||||
QString newUsername = listWidget->currentItem()->text();
|
||||
AccountManager::getInstance().Twitch.currentUsername = newUsername.toStdString();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+4
-72
@@ -79,15 +79,10 @@ Split::Split(ChannelManager &_channelManager, SplitContainer *parent)
|
||||
ezShortcut(this, "CTRL+R", &Split::doChangeChannel);
|
||||
|
||||
// xd
|
||||
//ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
|
||||
//ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
|
||||
//ezShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
||||
//ezShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
||||
|
||||
#ifndef NDEBUG
|
||||
// F12: Toggle message spawning
|
||||
ezShortcut(this, "ALT+Q", &Split::doToggleMessageSpawning);
|
||||
#endif
|
||||
// ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
|
||||
// ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
|
||||
// ezShortcut(this, "ALT+SHIFT+UP", &Split::doIncFlexY);
|
||||
// ezShortcut(this, "ALT+SHIFT+DOWN", &Split::doDecFlexY);
|
||||
|
||||
this->channelName.getValueChangedSignal().connect(
|
||||
std::bind(&Split::channelNameUpdated, this, std::placeholders::_1));
|
||||
@@ -102,10 +97,6 @@ Split::Split(ChannelManager &_channelManager, SplitContainer *parent)
|
||||
this->input.clearSelection();
|
||||
}
|
||||
});
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, &QTimer::timeout, this, &Split::test);
|
||||
timer->start(1000);
|
||||
}
|
||||
|
||||
Split::~Split()
|
||||
@@ -462,30 +453,6 @@ void Split::doCopy()
|
||||
QApplication::clipboard()->setText(this->view.getSelectedText());
|
||||
}
|
||||
|
||||
static std::vector<std::string> usernameVariants = {
|
||||
"pajlada", //
|
||||
"trump", //
|
||||
"Chancu", //
|
||||
"pajaWoman", //
|
||||
"fourtf", //
|
||||
"weneedmoreautisticbots", //
|
||||
"fourtfbot", //
|
||||
"pajbot", //
|
||||
"snusbot", //
|
||||
};
|
||||
|
||||
static std::vector<std::string> messageVariants = {
|
||||
"hehe", //
|
||||
"lol pajlada", //
|
||||
"hehe BANNEDWORD", //
|
||||
"someone ordered pizza", //
|
||||
"for ice poseidon", //
|
||||
"and delivery guy said it is for enza denino", //
|
||||
"!gn", //
|
||||
"for my laptop", //
|
||||
"should I buy a Herschel backpack?", //
|
||||
};
|
||||
|
||||
template <typename Iter, typename RandomGenerator>
|
||||
static Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
|
||||
{
|
||||
@@ -502,41 +469,6 @@ static Iter select_randomly(Iter start, Iter end)
|
||||
return select_randomly(start, end, gen);
|
||||
}
|
||||
|
||||
void Split::test()
|
||||
{
|
||||
if (this->testEnabled) {
|
||||
messages::MessageParseArgs args;
|
||||
|
||||
auto message =
|
||||
new Communi::IrcPrivateMessage(this->channelManager.ircManager.readConnection.get());
|
||||
|
||||
std::string text = *(select_randomly(messageVariants.begin(), messageVariants.end()));
|
||||
std::string username = *(select_randomly(usernameVariants.begin(), usernameVariants.end()));
|
||||
std::string usernameString = username + "!" + username + "@" + username;
|
||||
|
||||
QStringList params{"#pajlada", text.c_str()};
|
||||
|
||||
qDebug() << params;
|
||||
|
||||
message->setParameters(params);
|
||||
|
||||
message->setPrefix(usernameString.c_str());
|
||||
|
||||
auto twitchChannel = std::dynamic_pointer_cast<twitch::TwitchChannel>(this->channel);
|
||||
|
||||
twitch::TwitchMessageBuilder builder(
|
||||
twitchChannel.get(), this->channelManager.ircManager.resources,
|
||||
this->channelManager.emoteManager, this->channelManager.windowManager, message, args);
|
||||
|
||||
twitchChannel->addMessage(builder.parse());
|
||||
}
|
||||
}
|
||||
|
||||
void Split::doToggleMessageSpawning()
|
||||
{
|
||||
this->testEnabled = !this->testEnabled;
|
||||
}
|
||||
|
||||
void Split::doIncFlexX()
|
||||
{
|
||||
this->setFlexSizeX(this->getFlexSizeX() * 1.2);
|
||||
|
||||
@@ -52,7 +52,6 @@ public:
|
||||
CompletionManager &completionManager;
|
||||
pajlada::Settings::Setting<std::string> channelName;
|
||||
boost::signals2::signal<void()> channelChanged;
|
||||
bool testEnabled = false;
|
||||
|
||||
std::shared_ptr<Channel> getChannel() const;
|
||||
std::shared_ptr<Channel> &getChannelRef();
|
||||
@@ -122,8 +121,6 @@ public slots:
|
||||
// Open viewer list of the channel
|
||||
void doOpenViewerList();
|
||||
|
||||
void doToggleMessageSpawning();
|
||||
void test();
|
||||
void doIncFlexX();
|
||||
void doDecFlexX();
|
||||
void doIncFlexY();
|
||||
|
||||
Reference in New Issue
Block a user