mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
link
This commit is contained in:
parent
5fcb033167
commit
77ea204be0
|
@ -1987,6 +1987,29 @@ MessagePtr MessageBuilder::makeLowTrustUpdateMessage(
|
|||
return builder.release();
|
||||
}
|
||||
|
||||
MessagePtrMut MessageBuilder::makeAccountExpiredMessage(
|
||||
const QString &expirationText)
|
||||
{
|
||||
auto loginPromptText = u"Try adding your account again."_s;
|
||||
|
||||
MessageBuilder builder;
|
||||
auto text = expirationText % ' ' % loginPromptText;
|
||||
builder->messageText = text;
|
||||
builder->searchText = text;
|
||||
builder->flags.set(MessageFlag::System,
|
||||
MessageFlag::DoNotTriggerNotification);
|
||||
|
||||
builder.emplace<TimestampElement>();
|
||||
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
|
||||
MessageColor::System);
|
||||
builder
|
||||
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
|
||||
MessageColor::Link)
|
||||
->setLink({Link::OpenAccountsPage, {}});
|
||||
|
||||
return builder.release();
|
||||
}
|
||||
|
||||
std::pair<MessagePtrMut, HighlightAlert> MessageBuilder::makeIrcMessage(
|
||||
/* mutable */ Channel *channel, const Communi::IrcMessage *ircMessage,
|
||||
const MessageParseArgs &args, /* mutable */ QString content,
|
||||
|
|
|
@ -258,6 +258,9 @@ public:
|
|||
const QVariantMap &tags,
|
||||
const QTime &time);
|
||||
|
||||
static MessagePtrMut makeAccountExpiredMessage(
|
||||
const QString &expirationText);
|
||||
|
||||
private:
|
||||
struct TextState {
|
||||
TwitchChannel *twitchChannel = nullptr;
|
||||
|
|
|
@ -230,29 +230,10 @@ MessagePtr parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
|||
|
||||
if (message->content().startsWith("Login auth", Qt::CaseInsensitive))
|
||||
{
|
||||
const auto linkColor = MessageColor(MessageColor::Link);
|
||||
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
|
||||
const auto curUser = getApp()->getAccounts()->twitch.getCurrent();
|
||||
const auto expirationText = QString("Login expired for user \"%1\"!")
|
||||
.arg(curUser->getUserName());
|
||||
const auto loginPromptText = QString("Try adding your account again.");
|
||||
|
||||
MessageBuilder builder;
|
||||
auto text = QString("%1 %2").arg(expirationText, loginPromptText);
|
||||
builder.message().messageText = text;
|
||||
builder.message().searchText = text;
|
||||
builder.message().flags.set(MessageFlag::System);
|
||||
builder.message().flags.set(MessageFlag::DoNotTriggerNotification);
|
||||
|
||||
builder.emplace<TimestampElement>();
|
||||
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
|
||||
MessageColor::System);
|
||||
builder
|
||||
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
|
||||
linkColor)
|
||||
->setLink(accountsLink);
|
||||
|
||||
return builder.release();
|
||||
return MessageBuilder::makeAccountExpiredMessage(
|
||||
u"Login expired for user \"" % curUser->getUserName() % u"\"!");
|
||||
}
|
||||
|
||||
if (message->content().startsWith("You are permanently banned "))
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "common/network/NetworkResult.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
|
@ -411,21 +412,29 @@ void TwitchAccountManager::refreshAccounts(bool emitChanged)
|
|||
})
|
||||
.onError([this, account](const auto &res) {
|
||||
auto json = res.parseJson();
|
||||
QString message =
|
||||
u"Failed to refresh OAuth token for " %
|
||||
account->getUserName() % u" error: " % res.formatError() %
|
||||
u" - " % json["message"_L1].toString(u"(no message)"_s);
|
||||
QString message = u"Failed to refresh OAuth token for " %
|
||||
account->getUserName() % u" (" %
|
||||
res.formatError() % u" - " %
|
||||
json["message"_L1].toString(u"no message"_s) %
|
||||
u").";
|
||||
qCWarning(chatterinoTwitch) << message;
|
||||
|
||||
if (account == this->getCurrent())
|
||||
{
|
||||
if (res.status().value_or(0) == 400) // invalid token
|
||||
{
|
||||
message +=
|
||||
QStringView(u". Consider re-adding your account.");
|
||||
auto msg =
|
||||
MessageBuilder::makeAccountExpiredMessage(message);
|
||||
getApp()->getTwitch()->forEachChannel(
|
||||
[msg](const auto &chan) {
|
||||
chan->addMessage(msg, MessageContext::Original);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
getApp()->getTwitch()->addGlobalSystemMessage(message);
|
||||
}
|
||||
}
|
||||
})
|
||||
.finally(tryFlush)
|
||||
.execute();
|
||||
|
|
Loading…
Reference in a new issue