2018-06-26 14:09:39 +02:00
|
|
|
#include "UserInfoPopup.hpp"
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "common/Channel.hpp"
|
2018-07-15 14:11:46 +02:00
|
|
|
#include "common/NetworkRequest.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2018-08-06 16:40:46 +02:00
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
#include "providers/twitch/PartialTwitchUser.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Resources.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/LayoutCreator.hpp"
|
|
|
|
#include "util/PostToThread.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "widgets/Label.hpp"
|
2018-07-05 22:47:51 +02:00
|
|
|
#include "widgets/dialogs/LogsPopup.hpp"
|
2018-08-08 15:35:54 +02:00
|
|
|
#include "widgets/helper/EffectLabel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/Line.hpp"
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QLabel>
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-06-06 15:54:14 +02:00
|
|
|
#define TEXT_FOLLOWERS "Followers: "
|
|
|
|
#define TEXT_VIEWS "Views: "
|
|
|
|
#define TEXT_CREATED "Created: "
|
|
|
|
|
2018-06-06 13:35:06 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
UserInfoPopup::UserInfoPopup()
|
2018-08-06 21:17:03 +02:00
|
|
|
: BaseWindow(nullptr, BaseWindow::Flags(BaseWindow::Frameless |
|
|
|
|
BaseWindow::FramelessDraggable))
|
2018-06-06 15:54:14 +02:00
|
|
|
, hack_(new bool)
|
2018-06-06 13:35:06 +02:00
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
this->setStayInScreenRect(true);
|
|
|
|
|
2018-06-22 12:44:10 +02:00
|
|
|
#ifdef Q_OS_LINUX
|
2018-06-19 22:29:58 +02:00
|
|
|
this->setWindowFlag(Qt::Popup);
|
2018-06-22 12:44:10 +02:00
|
|
|
#endif
|
2018-06-19 22:29:58 +02:00
|
|
|
|
2018-06-06 13:35:06 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
auto layout =
|
|
|
|
LayoutCreator<UserInfoPopup>(this).setLayoutType<QVBoxLayout>();
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
// first line
|
|
|
|
auto head = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
// avatar
|
2018-08-08 15:35:54 +02:00
|
|
|
auto avatar =
|
|
|
|
head.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);
|
2018-06-11 21:57:17 +02:00
|
|
|
avatar->setScaleIndependantSize(100, 100);
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(avatar.getElement(), &Button::leftClicked, [this] {
|
2018-08-08 15:35:54 +02:00
|
|
|
QDesktopServices::openUrl(
|
2018-08-22 15:16:19 +02:00
|
|
|
QUrl("https://twitch.tv/" + this->userName_.toLower()));
|
2018-08-08 15:35:54 +02:00
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
// items on the right
|
|
|
|
auto vbox = head.emplace<QVBoxLayout>();
|
|
|
|
{
|
2019-08-22 20:23:49 +02:00
|
|
|
auto name_box = vbox.emplace<QHBoxLayout>();
|
|
|
|
name_box.withoutMargin();
|
|
|
|
|
|
|
|
auto name = name_box.emplace<Label>().assign(&this->ui_.nameLabel);
|
|
|
|
|
|
|
|
LayoutCreator<EffectLabel2> copy_user_name = name_box.emplace<EffectLabel2>(this);
|
|
|
|
copy_user_name->getLabel().setText("Copy");
|
|
|
|
copy_user_name->getLabel().setCentered(true);
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
auto font = name->font();
|
|
|
|
font.setBold(true);
|
|
|
|
name->setFont(font);
|
2019-08-22 20:23:49 +02:00
|
|
|
|
|
|
|
name_box->addStretch(1);
|
|
|
|
|
|
|
|
QObject::connect(copy_user_name.getElement(), &Button::leftClicked, [this] {
|
|
|
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
|
|
|
clipboard->setText(this->userName_);
|
|
|
|
});
|
|
|
|
|
2018-06-11 21:57:17 +02:00
|
|
|
vbox.emplace<Label>(TEXT_VIEWS).assign(&this->ui_.viewCountLabel);
|
2018-08-06 21:17:03 +02:00
|
|
|
vbox.emplace<Label>(TEXT_FOLLOWERS)
|
|
|
|
.assign(&this->ui_.followerCountLabel);
|
|
|
|
vbox.emplace<Label>(TEXT_CREATED)
|
|
|
|
.assign(&this->ui_.createdDateLabel);
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.emplace<Line>(false);
|
|
|
|
|
|
|
|
// second line
|
|
|
|
auto user = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
user->addStretch(1);
|
|
|
|
|
2018-06-06 15:54:14 +02:00
|
|
|
user.emplace<QCheckBox>("Follow").assign(&this->ui_.follow);
|
|
|
|
user.emplace<QCheckBox>("Ignore").assign(&this->ui_.ignore);
|
2018-08-06 21:17:03 +02:00
|
|
|
user.emplace<QCheckBox>("Ignore highlights")
|
|
|
|
.assign(&this->ui_.ignoreHighlights);
|
2018-08-08 15:35:54 +02:00
|
|
|
auto viewLogs = user.emplace<EffectLabel2>(this);
|
2018-08-07 23:46:00 +02:00
|
|
|
viewLogs->getLabel().setText("Online logs");
|
2019-06-02 21:42:49 +02:00
|
|
|
auto usercard = user.emplace<EffectLabel2>(this);
|
|
|
|
usercard->getLabel().setText("Usercard");
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-08-08 15:35:54 +02:00
|
|
|
auto mod = user.emplace<Button>(this);
|
2018-06-06 13:35:06 +02:00
|
|
|
mod->setPixmap(app->resources->buttons.mod);
|
|
|
|
mod->setScaleIndependantSize(30, 30);
|
2018-08-08 15:35:54 +02:00
|
|
|
auto unmod = user.emplace<Button>(this);
|
2018-06-06 13:35:06 +02:00
|
|
|
unmod->setPixmap(app->resources->buttons.unmod);
|
|
|
|
unmod->setScaleIndependantSize(30, 30);
|
|
|
|
|
|
|
|
user->addStretch(1);
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(viewLogs.getElement(), &Button::leftClicked, [this] {
|
2018-08-08 15:35:54 +02:00
|
|
|
auto logs = new LogsPopup();
|
2018-11-03 15:37:56 +01:00
|
|
|
logs->setChannel(this->channel_);
|
|
|
|
logs->setTargetUserName(this->userName_);
|
|
|
|
logs->getLogs();
|
2018-08-08 15:35:54 +02:00
|
|
|
logs->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
logs->show();
|
|
|
|
});
|
|
|
|
|
2019-06-02 21:42:49 +02:00
|
|
|
QObject::connect(usercard.getElement(), &Button::leftClicked, [this] {
|
|
|
|
QDesktopServices::openUrl("https://www.twitch.tv/popout/" +
|
|
|
|
this->channel_->getName() +
|
|
|
|
"/viewercard/" + this->userName_);
|
|
|
|
});
|
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(mod.getElement(), &Button::leftClicked, [this] {
|
2018-08-08 15:35:54 +02:00
|
|
|
this->channel_->sendMessage("/mod " + this->userName_);
|
|
|
|
});
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(unmod.getElement(), &Button::leftClicked, [this] {
|
2018-08-08 15:35:54 +02:00
|
|
|
this->channel_->sendMessage("/unmod " + this->userName_);
|
|
|
|
});
|
2018-06-19 18:55:45 +02:00
|
|
|
|
2018-06-06 15:54:14 +02:00
|
|
|
// userstate
|
2018-07-06 19:23:47 +02:00
|
|
|
this->userStateChanged_.connect([this, mod, unmod]() mutable {
|
2018-08-06 21:17:03 +02:00
|
|
|
TwitchChannel *twitchChannel =
|
|
|
|
dynamic_cast<TwitchChannel *>(this->channel_.get());
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-11-27 19:29:59 +01:00
|
|
|
bool visibilityMod = false;
|
|
|
|
bool visibilityUnmod = false;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (twitchChannel)
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
qDebug() << this->userName_;
|
|
|
|
|
|
|
|
bool isMyself =
|
2018-08-06 21:17:03 +02:00
|
|
|
QString::compare(
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName(),
|
|
|
|
this->userName_, Qt::CaseInsensitive) == 0;
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-11-27 19:29:59 +01:00
|
|
|
visibilityMod = twitchChannel->isBroadcaster() && !isMyself;
|
2019-05-10 23:31:10 +02:00
|
|
|
visibilityUnmod =
|
|
|
|
visibilityMod || (twitchChannel->isMod() && isMyself);
|
2018-06-06 15:54:14 +02:00
|
|
|
}
|
2018-11-27 19:29:59 +01:00
|
|
|
mod->setVisible(visibilityMod);
|
|
|
|
unmod->setVisible(visibilityUnmod);
|
2018-06-06 15:54:14 +02:00
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 15:54:14 +02:00
|
|
|
auto lineMod = layout.emplace<Line>(false);
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
// third line
|
|
|
|
auto moderation = layout.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
auto timeout = moderation.emplace<TimeoutWidget>();
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->userStateChanged_.connect([this, lineMod, timeout]() mutable {
|
2018-08-06 21:17:03 +02:00
|
|
|
TwitchChannel *twitchChannel =
|
|
|
|
dynamic_cast<TwitchChannel *>(this->channel_.get());
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2019-05-10 23:31:10 +02:00
|
|
|
bool hasModRights =
|
|
|
|
twitchChannel ? twitchChannel->hasModRights() : false;
|
2018-11-27 19:29:59 +01:00
|
|
|
lineMod->setVisible(hasModRights);
|
|
|
|
timeout->setVisible(hasModRights);
|
2018-06-06 15:54:14 +02:00
|
|
|
});
|
2018-06-06 16:17:34 +02:00
|
|
|
|
|
|
|
timeout->buttonClicked.connect([this](auto item) {
|
|
|
|
TimeoutWidget::Action action;
|
|
|
|
int arg;
|
|
|
|
std::tie(action, arg) = item;
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case TimeoutWidget::Ban:
|
|
|
|
{
|
|
|
|
if (this->channel_)
|
|
|
|
{
|
2018-06-06 16:17:34 +02:00
|
|
|
this->channel_->sendMessage("/ban " + this->userName_);
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TimeoutWidget::Unban:
|
|
|
|
{
|
|
|
|
if (this->channel_)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->channel_->sendMessage("/unban " +
|
|
|
|
this->userName_);
|
2018-06-06 16:17:34 +02:00
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TimeoutWidget::Timeout:
|
|
|
|
{
|
|
|
|
if (this->channel_)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->channel_->sendMessage("/timeout " +
|
|
|
|
this->userName_ + " " +
|
2018-06-06 16:17:34 +02:00
|
|
|
QString::number(arg));
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-06-06 16:17:34 +02:00
|
|
|
}
|
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this->setStyleSheet("font-size: 11pt;");
|
2018-06-06 15:54:14 +02:00
|
|
|
|
|
|
|
this->installEvents();
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:11:37 +02:00
|
|
|
void UserInfoPopup::themeChangedEvent()
|
2018-06-07 17:43:21 +02:00
|
|
|
{
|
2018-07-06 17:11:37 +02:00
|
|
|
BaseWindow::themeChangedEvent();
|
2018-06-07 17:43:21 +02:00
|
|
|
|
|
|
|
this->setStyleSheet("background: #333");
|
|
|
|
}
|
|
|
|
|
2018-06-06 15:54:14 +02:00
|
|
|
void UserInfoPopup::installEvents()
|
|
|
|
{
|
|
|
|
std::weak_ptr<bool> hack = this->hack_;
|
|
|
|
|
|
|
|
// follow
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
this->ui_.follow, &QCheckBox::stateChanged, [this](int) mutable {
|
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QUrl requestUrl("https://api.twitch.tv/kraken/users/" +
|
|
|
|
currentUser->getUserId() + "/follows/channels/" +
|
|
|
|
this->userId_);
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
const auto reenableFollowCheckbox = [this] {
|
|
|
|
this->ui_.follow->setEnabled(true); //
|
|
|
|
};
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.follow->setEnabled(false);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.follow->isChecked())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
currentUser->followUser(this->userId_, reenableFollowCheckbox);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
currentUser->unfollowUser(this->userId_,
|
|
|
|
reenableFollowCheckbox);
|
|
|
|
}
|
|
|
|
});
|
2018-06-06 15:54:14 +02:00
|
|
|
|
|
|
|
std::shared_ptr<bool> ignoreNext = std::make_shared<bool>(false);
|
|
|
|
|
|
|
|
// ignore
|
|
|
|
QObject::connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.ignore, &QCheckBox::stateChanged,
|
|
|
|
[this, ignoreNext, hack](int) mutable {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (*ignoreNext)
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
*ignoreNext = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->ui_.ignore->setEnabled(false);
|
|
|
|
|
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->ui_.ignore->isChecked())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
currentUser->ignoreByID(
|
|
|
|
this->userId_, this->userName_,
|
|
|
|
[=](auto result, const auto &message) mutable {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hack.lock())
|
|
|
|
{
|
|
|
|
if (result == IgnoreResult_Failed)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
*ignoreNext = true;
|
|
|
|
this->ui_.ignore->setChecked(false);
|
|
|
|
}
|
|
|
|
this->ui_.ignore->setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
currentUser->unignoreByID(
|
|
|
|
this->userId_, this->userName_,
|
|
|
|
[=](auto result, const auto &message) mutable {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hack.lock())
|
|
|
|
{
|
|
|
|
if (result == UnignoreResult_Failed)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
*ignoreNext = true;
|
|
|
|
this->ui_.ignore->setChecked(true);
|
|
|
|
}
|
|
|
|
this->ui_.ignore->setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2018-06-06 15:54:14 +02:00
|
|
|
}
|
|
|
|
});
|
2018-08-06 16:40:46 +02:00
|
|
|
|
|
|
|
// ignore highlights
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
|
|
|
this->ui_.ignoreHighlights, &QCheckBox::clicked,
|
|
|
|
[this](bool checked) mutable {
|
|
|
|
this->ui_.ignoreHighlights->setEnabled(false);
|
2018-08-06 16:40:46 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (checked)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
getApp()->highlights->blacklistedUsers.insertItem(
|
|
|
|
HighlightBlacklistUser{this->userName_, false});
|
|
|
|
this->ui_.ignoreHighlights->setEnabled(true);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
const auto &vector =
|
|
|
|
getApp()->highlights->blacklistedUsers.getVector();
|
2018-08-06 16:40:46 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < vector.size(); i++)
|
|
|
|
{
|
|
|
|
if (this->userName_ == vector[i].getPattern())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
getApp()->highlights->blacklistedUsers.removeItem(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2018-10-21 13:43:02 +02:00
|
|
|
if (getApp()->highlights->blacklistContains(this->userName_))
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.ignoreHighlights->setToolTip(
|
|
|
|
"Name matched by regex");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.ignoreHighlights->setEnabled(true);
|
2018-08-06 16:40:46 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
|
|
|
|
{
|
|
|
|
this->userName_ = name;
|
|
|
|
this->channel_ = channel;
|
|
|
|
|
|
|
|
this->ui_.nameLabel->setText(name);
|
|
|
|
|
|
|
|
this->updateUserData();
|
2018-06-06 15:54:14 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->userStateChanged_.invoke();
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInfoPopup::updateUserData()
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
std::weak_ptr<bool> hack = this->hack_;
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
const auto onIdFetched = [this, hack](QString id) {
|
2018-06-06 15:54:14 +02:00
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
this->userId_ = id;
|
|
|
|
|
2018-07-15 14:11:46 +02:00
|
|
|
QString url("https://api.twitch.tv/kraken/channels/" + id);
|
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest::twitchRequest(url)
|
|
|
|
.caller(this)
|
|
|
|
.onSuccess([this](auto result) -> Outcome {
|
|
|
|
auto obj = result.parseJson();
|
|
|
|
this->ui_.followerCountLabel->setText(
|
|
|
|
TEXT_FOLLOWERS +
|
|
|
|
QString::number(obj.value("followers").toInt()));
|
|
|
|
this->ui_.viewCountLabel->setText(
|
|
|
|
TEXT_VIEWS + QString::number(obj.value("views").toInt()));
|
|
|
|
this->ui_.createdDateLabel->setText(
|
|
|
|
TEXT_CREATED +
|
|
|
|
obj.value("created_at").toString().section("T", 0, 0));
|
|
|
|
|
|
|
|
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
})
|
|
|
|
.execute();
|
2018-06-06 15:54:14 +02:00
|
|
|
|
|
|
|
// get follow state
|
|
|
|
currentUser->checkFollow(id, [this, hack](auto result) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (hack.lock())
|
|
|
|
{
|
|
|
|
if (result != FollowResult_Failed)
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
this->ui_.follow->setEnabled(true);
|
2018-08-06 21:17:03 +02:00
|
|
|
this->ui_.follow->setChecked(result ==
|
|
|
|
FollowResult_Following);
|
2018-06-06 15:54:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// get ignore state
|
|
|
|
bool isIgnoring = false;
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &ignoredUser : currentUser->getIgnores())
|
|
|
|
{
|
|
|
|
if (id == ignoredUser.id)
|
|
|
|
{
|
2018-06-06 15:54:14 +02:00
|
|
|
isIgnoring = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 16:40:46 +02:00
|
|
|
// get ignoreHighlights state
|
|
|
|
bool isIgnoringHighlights = false;
|
|
|
|
const auto &vector = getApp()->highlights->blacklistedUsers.getVector();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < vector.size(); i++)
|
|
|
|
{
|
|
|
|
if (this->userName_ == vector[i].getPattern())
|
|
|
|
{
|
2018-08-06 16:40:46 +02:00
|
|
|
isIgnoringHighlights = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-06 21:17:03 +02:00
|
|
|
if (getApp()->highlights->blacklistContains(this->userName_) &&
|
2018-10-21 13:43:02 +02:00
|
|
|
!isIgnoringHighlights)
|
|
|
|
{
|
2018-08-06 16:40:46 +02:00
|
|
|
this->ui_.ignoreHighlights->setToolTip("Name matched by regex");
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 16:40:46 +02:00
|
|
|
this->ui_.ignoreHighlights->setEnabled(true);
|
|
|
|
}
|
2018-06-06 15:54:14 +02:00
|
|
|
this->ui_.ignore->setEnabled(true);
|
|
|
|
this->ui_.ignore->setChecked(isIgnoring);
|
2018-08-06 16:40:46 +02:00
|
|
|
this->ui_.ignoreHighlights->setChecked(isIgnoringHighlights);
|
2018-07-07 13:08:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
PartialTwitchUser::byName(this->userName_).getId(onIdFetched, this);
|
2018-06-06 15:54:14 +02:00
|
|
|
|
|
|
|
this->ui_.follow->setEnabled(false);
|
|
|
|
this->ui_.ignore->setEnabled(false);
|
|
|
|
this->ui_.ignoreHighlights->setEnabled(false);
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInfoPopup::loadAvatar(const QUrl &url)
|
|
|
|
{
|
|
|
|
QNetworkRequest req(url);
|
|
|
|
static auto manager = new QNetworkAccessManager();
|
|
|
|
auto *reply = manager->get(req);
|
|
|
|
|
|
|
|
QObject::connect(reply, &QNetworkReply::finished, this, [=] {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (reply->error() == QNetworkReply::NoError)
|
|
|
|
{
|
2018-06-06 13:35:06 +02:00
|
|
|
const auto data = reply->readAll();
|
|
|
|
|
|
|
|
// might want to cache the avatar image
|
|
|
|
QPixmap avatar;
|
|
|
|
avatar.loadFromData(data);
|
|
|
|
this->ui_.avatarButton->setPixmap(avatar);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-06 13:35:06 +02:00
|
|
|
this->ui_.avatarButton->setPixmap(QPixmap());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// TimeoutWidget
|
|
|
|
//
|
|
|
|
UserInfoPopup::TimeoutWidget::TimeoutWidget()
|
|
|
|
: BaseWidget(nullptr)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
auto layout = LayoutCreator<TimeoutWidget>(this)
|
|
|
|
.setLayoutType<QHBoxLayout>()
|
|
|
|
.withoutMargin();
|
2018-06-06 13:35:06 +02:00
|
|
|
|
|
|
|
QColor color1(255, 255, 255, 80);
|
|
|
|
QColor color2(255, 255, 255, 0);
|
|
|
|
|
2018-06-19 18:55:45 +02:00
|
|
|
int buttonWidth = 24;
|
|
|
|
int buttonWidth2 = 32;
|
2018-06-06 13:35:06 +02:00
|
|
|
int buttonHeight = 32;
|
|
|
|
|
|
|
|
layout->setSpacing(16);
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
auto addButton = [&](Action action, const QString &text,
|
|
|
|
const QPixmap &pixmap) {
|
2018-06-06 13:35:06 +02:00
|
|
|
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
title->addStretch(1);
|
2018-06-11 21:57:17 +02:00
|
|
|
auto label = title.emplace<Label>(text);
|
2018-06-19 18:55:45 +02:00
|
|
|
label->setHasOffset(false);
|
2018-06-06 15:54:14 +02:00
|
|
|
label->setStyleSheet("color: #BBB");
|
2018-06-06 13:35:06 +02:00
|
|
|
title->addStretch(1);
|
|
|
|
|
|
|
|
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
hbox->setSpacing(0);
|
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
auto button = hbox.emplace<Button>(nullptr);
|
2018-06-06 16:17:34 +02:00
|
|
|
button->setPixmap(pixmap);
|
|
|
|
button->setScaleIndependantSize(buttonHeight, buttonHeight);
|
|
|
|
button->setBorderColor(QColor(255, 255, 255, 127));
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(
|
2018-10-21 16:13:26 +02:00
|
|
|
button.getElement(), &Button::leftClicked, [this, action] {
|
2018-08-06 21:17:03 +02:00
|
|
|
this->buttonClicked.invoke(std::make_pair(action, -1));
|
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 16:17:34 +02:00
|
|
|
};
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-06-06 16:17:34 +02:00
|
|
|
auto addTimeouts = [&](const QString &title_,
|
|
|
|
const std::vector<std::pair<QString, int>> &items) {
|
2018-06-06 13:35:06 +02:00
|
|
|
auto vbox = layout.emplace<QVBoxLayout>().withoutMargin();
|
|
|
|
{
|
|
|
|
auto title = vbox.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
title->addStretch(1);
|
2018-06-11 21:57:17 +02:00
|
|
|
auto label = title.emplace<Label>(title_);
|
2018-06-06 15:54:14 +02:00
|
|
|
label->setStyleSheet("color: #BBB");
|
2018-06-19 18:55:45 +02:00
|
|
|
label->setHasOffset(false);
|
2018-06-06 13:35:06 +02:00
|
|
|
title->addStretch(1);
|
|
|
|
|
|
|
|
auto hbox = vbox.emplace<QHBoxLayout>().withoutMargin();
|
|
|
|
hbox->setSpacing(0);
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &item : items)
|
|
|
|
{
|
2018-08-08 15:35:54 +02:00
|
|
|
auto a = hbox.emplace<EffectLabel2>();
|
2018-06-06 16:17:34 +02:00
|
|
|
a->getLabel().setText(std::get<0>(item));
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (std::get<0>(item).length() > 1)
|
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
a->setScaleIndependantSize(buttonWidth2, buttonHeight);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-19 18:55:45 +02:00
|
|
|
a->setScaleIndependantSize(buttonWidth, buttonHeight);
|
|
|
|
}
|
|
|
|
a->setBorderColor(color1);
|
2018-06-06 13:35:06 +02:00
|
|
|
|
2018-10-21 16:13:26 +02:00
|
|
|
QObject::connect(a.getElement(), &EffectLabel2::leftClicked,
|
2018-08-06 21:17:03 +02:00
|
|
|
[this, timeout = std::get<1>(item)] {
|
|
|
|
this->buttonClicked.invoke(std::make_pair(
|
|
|
|
Action::Timeout, timeout));
|
|
|
|
});
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-06 16:17:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
addButton(Unban, "unban", getApp()->resources->buttons.unban);
|
|
|
|
|
|
|
|
addTimeouts("sec", {{"1", 1}});
|
|
|
|
addTimeouts("min", {
|
2018-07-07 13:08:57 +02:00
|
|
|
{"1", 1 * 60},
|
|
|
|
{"5", 5 * 60},
|
|
|
|
{"10", 10 * 60},
|
2018-06-06 16:17:34 +02:00
|
|
|
});
|
|
|
|
addTimeouts("hour", {
|
2018-07-07 13:08:57 +02:00
|
|
|
{"1", 1 * 60 * 60},
|
|
|
|
{"4", 4 * 60 * 60},
|
2018-06-14 15:49:57 +02:00
|
|
|
});
|
|
|
|
addTimeouts("days", {
|
2018-07-07 13:08:57 +02:00
|
|
|
{"1", 1 * 60 * 60 * 24},
|
|
|
|
{"3", 3 * 60 * 60 * 24},
|
2018-06-06 16:17:34 +02:00
|
|
|
});
|
|
|
|
addTimeouts("weeks", {
|
2018-07-07 13:08:57 +02:00
|
|
|
{"1", 1 * 60 * 60 * 24 * 7},
|
|
|
|
{"2", 2 * 60 * 60 * 24 * 7},
|
2018-06-06 16:17:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
addButton(Ban, "ban", getApp()->resources->buttons.ban);
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
// QPainter painter(this);
|
|
|
|
|
|
|
|
// painter.setPen(QColor(255, 255, 255, 63));
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
// painter.drawLine(0, this->height() / 2, this->width(), this->height()
|
|
|
|
// / 2);
|
2018-06-06 13:35:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|