Make a command that shows the Chatterino user card (/usercard) (#1375)
* Make UserInfoPopup be able to show that fetching the information failed.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "util/CombinePath.hpp"
|
#include "util/CombinePath.hpp"
|
||||||
#include "widgets/dialogs/LogsPopup.hpp"
|
#include "widgets/dialogs/LogsPopup.hpp"
|
||||||
|
#include "widgets/dialogs/UserInfoPopup.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -481,6 +482,21 @@ QString CommandController::execCommand(const QString &textNoEmoji,
|
|||||||
channelName + "/viewercard/" + words[1]);
|
channelName + "/viewercard/" + words[1]);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
else if (commandName == "/usercard")
|
||||||
|
{
|
||||||
|
if (words.size() < 2)
|
||||||
|
{
|
||||||
|
channel->addMessage(
|
||||||
|
makeSystemMessage("Usage /usercard [user]"));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
auto *userPopup = new UserInfoPopup;
|
||||||
|
userPopup->setData(words[1], channel);
|
||||||
|
userPopup->setActionOnFocusLoss(BaseWindow::Delete);
|
||||||
|
userPopup->move(QCursor::pos());
|
||||||
|
userPopup->show();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ PartialTwitchUser PartialTwitchUser::byId(const QString &id)
|
|||||||
|
|
||||||
void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
||||||
const QObject *caller)
|
const QObject *caller)
|
||||||
|
{
|
||||||
|
getId(
|
||||||
|
successCallback, [] {}, caller);
|
||||||
|
}
|
||||||
|
void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
||||||
|
std::function<void()> failureCallback,
|
||||||
|
const QObject *caller)
|
||||||
{
|
{
|
||||||
assert(!this->username_.isEmpty());
|
assert(!this->username_.isEmpty());
|
||||||
|
|
||||||
@@ -34,12 +41,13 @@ void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
|||||||
this->username_)
|
this->username_)
|
||||||
.caller(caller)
|
.caller(caller)
|
||||||
.authorizeTwitchV5(getDefaultClientID())
|
.authorizeTwitchV5(getDefaultClientID())
|
||||||
.onSuccess([successCallback](auto result) -> Outcome {
|
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
if (!root.value("users").isArray())
|
if (!root.value("users").isArray())
|
||||||
{
|
{
|
||||||
qDebug()
|
qDebug()
|
||||||
<< "API Error while getting user id, users is not an array";
|
<< "API Error while getting user id, users is not an array";
|
||||||
|
failureCallback();
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,12 +56,14 @@ void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
|||||||
{
|
{
|
||||||
qDebug() << "API Error while getting user id, users array size "
|
qDebug() << "API Error while getting user id, users array size "
|
||||||
"is not 1";
|
"is not 1";
|
||||||
|
failureCallback();
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
if (!users[0].isObject())
|
if (!users[0].isObject())
|
||||||
{
|
{
|
||||||
qDebug() << "API Error while getting user id, first user is "
|
qDebug() << "API Error while getting user id, first user is "
|
||||||
"not an object";
|
"not an object";
|
||||||
|
failureCallback();
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
auto firstUser = users[0].toObject();
|
auto firstUser = users[0].toObject();
|
||||||
@@ -62,6 +72,7 @@ void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
|||||||
{
|
{
|
||||||
qDebug() << "API Error: while getting user id, first user "
|
qDebug() << "API Error: while getting user id, first user "
|
||||||
"object `_id` key is not a string";
|
"object `_id` key is not a string";
|
||||||
|
failureCallback();
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
successCallback(id.toString());
|
successCallback(id.toString());
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public:
|
|||||||
|
|
||||||
void getId(std::function<void(QString)> successCallback,
|
void getId(std::function<void(QString)> successCallback,
|
||||||
const QObject *caller = nullptr);
|
const QObject *caller = nullptr);
|
||||||
|
|
||||||
|
void getId(std::function<void(QString)> successCallback,
|
||||||
|
std::function<void()> failureCallback,
|
||||||
|
const QObject *caller = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#define TEXT_VIEWS "Views: "
|
#define TEXT_VIEWS "Views: "
|
||||||
#define TEXT_CREATED "Created: "
|
#define TEXT_CREATED "Created: "
|
||||||
#define TEXT_USER_ID "ID: "
|
#define TEXT_USER_ID "ID: "
|
||||||
|
#define TEXT_UNAVAILABLE "(not available)"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -382,6 +383,22 @@ void UserInfoPopup::updateUserData()
|
|||||||
{
|
{
|
||||||
std::weak_ptr<bool> hack = this->hack_;
|
std::weak_ptr<bool> hack = this->hack_;
|
||||||
|
|
||||||
|
const auto onIdFetchFailed = [this]() {
|
||||||
|
// this can occur when the account doesn't exist.
|
||||||
|
this->ui_.followerCountLabel->setText(TEXT_FOLLOWERS +
|
||||||
|
QString(TEXT_UNAVAILABLE));
|
||||||
|
this->ui_.viewCountLabel->setText(TEXT_VIEWS +
|
||||||
|
QString(TEXT_UNAVAILABLE));
|
||||||
|
this->ui_.createdDateLabel->setText(TEXT_CREATED +
|
||||||
|
QString(TEXT_UNAVAILABLE));
|
||||||
|
|
||||||
|
this->ui_.nameLabel->setText(this->userName_);
|
||||||
|
|
||||||
|
this->ui_.userIDLabel->setText(QString("ID") +
|
||||||
|
QString(TEXT_UNAVAILABLE));
|
||||||
|
this->ui_.userIDLabel->setProperty("copy-text",
|
||||||
|
QString(TEXT_UNAVAILABLE));
|
||||||
|
};
|
||||||
const auto onIdFetched = [this, hack](QString id) {
|
const auto onIdFetched = [this, hack](QString id) {
|
||||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||||
|
|
||||||
@@ -462,7 +479,8 @@ void UserInfoPopup::updateUserData()
|
|||||||
this->ui_.ignoreHighlights->setChecked(isIgnoringHighlights);
|
this->ui_.ignoreHighlights->setChecked(isIgnoringHighlights);
|
||||||
};
|
};
|
||||||
|
|
||||||
PartialTwitchUser::byName(this->userName_).getId(onIdFetched, this);
|
PartialTwitchUser::byName(this->userName_)
|
||||||
|
.getId(onIdFetched, onIdFetchFailed, this);
|
||||||
|
|
||||||
this->ui_.follow->setEnabled(false);
|
this->ui_.follow->setEnabled(false);
|
||||||
this->ui_.ignore->setEnabled(false);
|
this->ui_.ignore->setEnabled(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user