2017-06-11 09:31:45 +02:00
|
|
|
#include "ircmanager.hpp"
|
|
|
|
#include "accountmanager.hpp"
|
|
|
|
#include "asyncexec.hpp"
|
|
|
|
#include "channel.hpp"
|
|
|
|
#include "channelmanager.hpp"
|
2017-06-13 21:13:58 +02:00
|
|
|
#include "emotemanager.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/messageparseargs.hpp"
|
|
|
|
#include "twitch/twitchmessagebuilder.hpp"
|
|
|
|
#include "twitch/twitchparsemessage.hpp"
|
|
|
|
#include "twitch/twitchuser.hpp"
|
2017-06-26 16:41:20 +02:00
|
|
|
#include "util/urlfetch.hpp"
|
2017-06-13 21:13:58 +02:00
|
|
|
#include "windowmanager.hpp"
|
2017-01-16 03:15:07 +01:00
|
|
|
|
|
|
|
#include <irccommand.h>
|
|
|
|
#include <ircconnection.h>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QNetworkRequest>
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-01-16 03:15:07 +01:00
|
|
|
#include <future>
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
using namespace chatterino::messages;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
|
|
|
|
EmoteManager &_emoteManager, WindowManager &_windowManager)
|
|
|
|
: channelManager(_channelManager)
|
|
|
|
, resources(_resources)
|
|
|
|
, emoteManager(_emoteManager)
|
|
|
|
, windowManager(_windowManager)
|
2017-09-21 12:15:01 +02:00
|
|
|
, account(AccountManager::getInstance().getTwitchAnon())
|
2017-08-19 15:37:56 +02:00
|
|
|
, currentUser("/accounts/current")
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-08-19 15:37:56 +02:00
|
|
|
this->currentUser.getValueChangedSignal().connect([](const auto &newUsername) {
|
|
|
|
// TODO: Implement
|
|
|
|
qDebug() << "Current user changed, fetch new credentials and reconnect";
|
|
|
|
});
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const twitch::TwitchUser &IrcManager::getUser() const
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
return this->account;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void IrcManager::setUser(const twitch::TwitchUser &account)
|
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
this->account = account;
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void IrcManager::connect()
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
disconnect();
|
2017-01-15 17:34:48 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
async_exec([this] { beginConnecting(); });
|
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
Communi::IrcConnection *IrcManager::createConnection(bool doRead)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-06 15:57:54 +02:00
|
|
|
Communi::IrcConnection *connection = new Communi::IrcConnection;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
if (doRead) {
|
|
|
|
QObject::connect(connection, &Communi::IrcConnection::messageReceived, this,
|
|
|
|
&IrcManager::messageReceived);
|
|
|
|
QObject::connect(connection, &Communi::IrcConnection::privateMessageReceived, this,
|
|
|
|
&IrcManager::privateMessageReceived);
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
QString username = this->account.getUserName();
|
|
|
|
QString oauthClient = this->account.getOAuthClient();
|
|
|
|
QString oauthToken = this->account.getOAuthToken();
|
2017-07-28 19:46:53 +02:00
|
|
|
if (!oauthToken.startsWith("oauth:")) {
|
|
|
|
oauthToken.prepend("oauth:");
|
|
|
|
}
|
2017-05-27 17:45:40 +02:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
connection->setUserName(username);
|
|
|
|
connection->setNickName(username);
|
|
|
|
connection->setRealName(username);
|
2017-05-27 17:45:40 +02:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
if (!this->account.isAnon()) {
|
2017-06-06 15:57:54 +02:00
|
|
|
connection->setPassword(oauthToken);
|
|
|
|
|
|
|
|
this->refreshIgnoredUsers(username, oauthClient, oauthToken);
|
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-06-06 15:58:26 +02:00
|
|
|
if (doRead) {
|
|
|
|
connection->sendCommand(
|
|
|
|
Communi::IrcCommand::createCapability("REQ", "twitch.tv/membership"));
|
|
|
|
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
|
|
|
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
|
|
|
}
|
2017-01-11 18:52:09 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
connection->setHost("irc.chat.twitch.tv");
|
|
|
|
connection->setPort(6667);
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcManager::refreshIgnoredUsers(const QString &username, const QString &oauthClient,
|
|
|
|
const QString &oauthToken)
|
|
|
|
{
|
|
|
|
QString nextLink = "https://api.twitch.tv/kraken/users/" + username + "/blocks?limit=" + 100 +
|
|
|
|
"&client_id=" + oauthClient;
|
2017-01-11 18:52:09 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
|
|
|
QNetworkRequest req(QUrl(nextLink + "&oauth_token=" + oauthToken));
|
|
|
|
QNetworkReply *reply = manager->get(req);
|
2017-01-11 18:52:09 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->twitchBlockedUsersMutex.lock();
|
|
|
|
this->twitchBlockedUsers.clear();
|
|
|
|
this->twitchBlockedUsersMutex.unlock();
|
2017-01-11 18:52:09 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
QByteArray data = reply->readAll();
|
|
|
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
|
|
|
QJsonObject root = jsonDoc.object();
|
2017-01-11 18:52:09 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
// nextLink =
|
2017-09-21 12:15:01 +02:00
|
|
|
// root.value("this->links").toObject().value("next").toString();
|
2017-01-30 19:14:25 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
auto blocks = root.value("blocks").toArray();
|
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
this->twitchBlockedUsersMutex.lock();
|
2017-06-06 15:57:54 +02:00
|
|
|
for (QJsonValue block : blocks) {
|
|
|
|
QJsonObject user = block.toObject().value("user").toObject();
|
2017-09-21 12:15:01 +02:00
|
|
|
// displaythis->name
|
|
|
|
this->twitchBlockedUsers.insert(user.value("name").toString().toLower(), true);
|
2017-01-04 15:12:31 +01:00
|
|
|
}
|
2017-09-21 12:15:01 +02:00
|
|
|
this->twitchBlockedUsersMutex.unlock();
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
manager->deleteLater();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcManager::beginConnecting()
|
|
|
|
{
|
|
|
|
uint32_t generation = ++this->connectionGeneration;
|
|
|
|
|
|
|
|
Communi::IrcConnection *_writeConnection = this->createConnection(false);
|
|
|
|
Communi::IrcConnection *_readConnection = this->createConnection(true);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
std::lock_guard<std::mutex> locker(this->connectionMutex);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
if (generation == this->connectionGeneration) {
|
|
|
|
this->writeConnection = std::shared_ptr<Communi::IrcConnection>(_writeConnection);
|
|
|
|
this->readConnection = std::shared_ptr<Communi::IrcConnection>(_readConnection);
|
|
|
|
|
|
|
|
this->writeConnection->moveToThread(QCoreApplication::instance()->thread());
|
|
|
|
this->readConnection->moveToThread(QCoreApplication::instance()->thread());
|
2017-01-30 19:14:25 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
for (auto &channel : this->channelManager.getItems()) {
|
2017-07-23 09:53:50 +02:00
|
|
|
this->writeConnection->sendRaw("JOIN #" + channel->name);
|
|
|
|
this->readConnection->sendRaw("JOIN #" + channel->name);
|
2017-01-30 19:14:25 +01:00
|
|
|
}
|
2017-01-30 20:13:53 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
this->writeConnection->open();
|
|
|
|
this->readConnection->open();
|
2017-01-11 18:52:09 +01:00
|
|
|
} else {
|
2017-06-06 15:57:54 +02:00
|
|
|
delete _writeConnection;
|
|
|
|
delete _readConnection;
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void IrcManager::disconnect()
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.lock();
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
auto _readConnection = this->readConnection;
|
|
|
|
auto _writeConnection = this->writeConnection;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
this->readConnection.reset();
|
|
|
|
this->writeConnection.reset();
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.unlock();
|
2017-01-29 13:23:22 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
void IrcManager::sendMessage(const QString &channelName, const QString &message)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.lock();
|
2017-01-30 20:13:53 +01:00
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
if (this->writeConnection) {
|
|
|
|
this->writeConnection->sendRaw("PRIVMSG #" + channelName + " :" + message);
|
2017-05-27 17:45:40 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.unlock();
|
2017-06-17 11:37:45 +02:00
|
|
|
|
|
|
|
// DEBUGGING
|
2017-06-26 16:41:20 +02:00
|
|
|
/*
|
2017-06-17 11:37:45 +02:00
|
|
|
Communi::IrcPrivateMessage msg(this->readConnection.get());
|
|
|
|
|
|
|
|
QStringList params{"#pajlada", message};
|
|
|
|
|
|
|
|
qDebug() << params;
|
|
|
|
|
|
|
|
if (message == "COMIC SANS LOL") {
|
|
|
|
FontManager::getInstance().currentFontFamily = "Comic Sans MS";
|
|
|
|
} else if (message == "ARIAL LOL") {
|
|
|
|
FontManager::getInstance().currentFontFamily = "Arial";
|
|
|
|
} else if (message == "WINGDINGS LOL") {
|
|
|
|
FontManager::getInstance().currentFontFamily = "Wingdings";
|
|
|
|
}
|
|
|
|
|
|
|
|
msg.setParameters(params);
|
|
|
|
|
|
|
|
msg.setPrefix("pajlada!pajlada@pajlada");
|
|
|
|
|
|
|
|
this->privateMessageReceived(&msg);
|
2017-06-26 16:41:20 +02:00
|
|
|
*/
|
2017-05-27 17:45:40 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
void IrcManager::joinChannel(const QString &channelName)
|
2017-05-27 17:45:40 +02:00
|
|
|
{
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.lock();
|
2017-05-27 17:45:40 +02:00
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
if (this->readConnection && this->writeConnection) {
|
|
|
|
this->readConnection->sendRaw("JOIN #" + channelName);
|
|
|
|
this->writeConnection->sendRaw("JOIN #" + channelName);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
2017-01-30 20:13:53 +01:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.unlock();
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
void IrcManager::partChannel(const QString &channelName)
|
2017-01-17 00:15:44 +01:00
|
|
|
{
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.lock();
|
2017-01-30 20:13:53 +01:00
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
if (this->readConnection && this->writeConnection) {
|
2017-06-06 16:06:13 +02:00
|
|
|
this->readConnection->sendRaw("PART #" + channelName);
|
|
|
|
this->writeConnection->sendRaw("PART #" + channelName);
|
2017-01-17 00:15:44 +01:00
|
|
|
}
|
2017-01-30 20:13:53 +01:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
this->connectionMutex.unlock();
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
|
|
|
{
|
2017-06-26 16:41:20 +02:00
|
|
|
this->onPrivateMessage.invoke(message);
|
2017-09-16 00:05:06 +02:00
|
|
|
auto c = this->channelManager.getTwitchChannel(message->target().mid(1));
|
2017-06-16 10:01:21 +02:00
|
|
|
|
2017-07-02 18:12:11 +02:00
|
|
|
if (!c) {
|
|
|
|
return;
|
2017-06-16 10:01:21 +02:00
|
|
|
}
|
2017-07-02 18:12:11 +02:00
|
|
|
|
|
|
|
messages::MessageParseArgs args;
|
|
|
|
|
|
|
|
twitch::TwitchMessageBuilder builder(c.get(), this->resources, this->emoteManager,
|
|
|
|
this->windowManager, message, args);
|
|
|
|
|
|
|
|
c->addMessage(builder.parse());
|
2017-06-16 10:01:21 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
void IrcManager::messageReceived(Communi::IrcMessage *message)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-06-16 10:01:21 +02:00
|
|
|
if (message->type() == Communi::IrcMessage::Type::Private) {
|
|
|
|
// We already have a handler for private messages
|
|
|
|
return;
|
2017-06-06 15:57:54 +02:00
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
const QString &command = message->command();
|
2017-01-18 01:04:54 +01:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
if (command == "ROOMSTATE") {
|
|
|
|
this->handleRoomStateMessage(message);
|
|
|
|
} else if (command == "CLEARCHAT") {
|
|
|
|
this->handleClearChatMessage(message);
|
2017-05-27 16:16:39 +02:00
|
|
|
} else if (command == "USERSTATE") {
|
2017-06-16 10:01:21 +02:00
|
|
|
this->handleUserStateMessage(message);
|
2017-05-27 16:16:39 +02:00
|
|
|
} else if (command == "WHISPER") {
|
2017-06-16 10:01:21 +02:00
|
|
|
this->handleWhisperMessage(message);
|
2017-05-27 16:16:39 +02:00
|
|
|
} else if (command == "USERNOTICE") {
|
2017-06-16 10:01:21 +02:00
|
|
|
this->handleUserNoticeMessage(message);
|
2017-05-27 16:16:39 +02:00
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
void IrcManager::handleRoomStateMessage(Communi::IrcMessage *message)
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-06-16 10:01:21 +02:00
|
|
|
const auto &tags = message->tags();
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
auto iterator = tags.find("room-id");
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
if (iterator != tags.end()) {
|
|
|
|
std::string roomID = iterator.value().toString().toStdString();
|
2017-07-23 14:16:13 +02:00
|
|
|
|
2017-09-11 22:37:39 +02:00
|
|
|
auto channel = QString(message->toData()).split("#").at(1);
|
2017-09-16 00:05:06 +02:00
|
|
|
channelManager.getTwitchChannel(channel)->setRoomID(roomID);
|
2017-09-11 22:37:39 +02:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
this->resources.loadChannelData(roomID);
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-01-03 21:19:33 +01:00
|
|
|
}
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
void IrcManager::handleClearChatMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcManager::handleUserStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcManager::handleWhisperMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcManager::handleUserNoticeMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool IrcManager::isTwitchBlockedUser(QString const &username)
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
QMutexLocker locker(&this->twitchBlockedUsersMutex);
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
auto iterator = this->twitchBlockedUsers.find(username);
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
return iterator != this->twitchBlockedUsers.end();
|
2017-01-04 15:12:31 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool IrcManager::tryAddIgnoredUser(QString const &username, QString &errorMessage)
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
|
|
|
|
username + "?oauth_token=" + this->account.getOAuthToken() +
|
|
|
|
"&client_id=" + this->account.getOAuthClient());
|
2017-01-04 15:12:31 +01:00
|
|
|
|
|
|
|
QNetworkRequest request(url);
|
2017-07-02 13:10:06 +02:00
|
|
|
auto reply = this->networkAccessManager.put(request, QByteArray());
|
2017-01-04 15:12:31 +01:00
|
|
|
reply->waitForReadyRead(10000);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (reply->error() == QNetworkReply::NoError) {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->twitchBlockedUsersMutex.lock();
|
|
|
|
this->twitchBlockedUsers.insert(username, true);
|
|
|
|
this->twitchBlockedUsersMutex.unlock();
|
2017-01-04 15:12:31 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
errorMessage = "Error while ignoring user \"" + username + "\": " + reply->errorString();
|
2017-01-04 15:12:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void IrcManager::addIgnoredUser(QString const &username)
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
|
|
|
QString errorMessage;
|
2017-01-05 16:07:20 +01:00
|
|
|
if (!tryAddIgnoredUser(username, errorMessage)) {
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: Implement IrcManager::addIgnoredUser
|
2017-01-04 15:12:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage)
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
2017-09-21 12:15:01 +02:00
|
|
|
QUrl url("https://api.twitch.tv/kraken/users/" + this->account.getUserName() + "/blocks/" +
|
|
|
|
username + "?oauth_token=" + this->account.getOAuthToken() +
|
|
|
|
"&client_id=" + this->account.getOAuthClient());
|
2017-01-04 15:12:31 +01:00
|
|
|
|
|
|
|
QNetworkRequest request(url);
|
2017-07-02 13:10:06 +02:00
|
|
|
auto reply = this->networkAccessManager.deleteResource(request);
|
2017-01-04 15:12:31 +01:00
|
|
|
reply->waitForReadyRead(10000);
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
if (reply->error() == QNetworkReply::NoError) {
|
2017-09-21 12:15:01 +02:00
|
|
|
this->twitchBlockedUsersMutex.lock();
|
|
|
|
this->twitchBlockedUsers.remove(username);
|
|
|
|
this->twitchBlockedUsersMutex.unlock();
|
2017-01-04 15:12:31 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
reply->deleteLater();
|
|
|
|
|
|
|
|
errorMessage = "Error while unignoring user \"" + username + "\": " + reply->errorString();
|
2017-01-04 15:12:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void IrcManager::removeIgnoredUser(QString const &username)
|
2017-01-04 15:12:31 +01:00
|
|
|
{
|
|
|
|
QString errorMessage;
|
2017-01-05 16:07:20 +01:00
|
|
|
if (!tryRemoveIgnoredUser(username, errorMessage)) {
|
2017-01-15 17:21:28 +01:00
|
|
|
// TODO: Implement IrcManager::removeIgnoredUser
|
2017-01-04 15:12:31 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-05-27 16:16:39 +02:00
|
|
|
} // namespace chatterino
|