From 937fffc34bc3f8aab9c908cf7dcf8b168909573a Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 May 2018 20:34:13 +0200 Subject: [PATCH] Implement /ignore and /unignore commands Simplify authorized network requests for Twitch V5 api add onShow virtual function to settings pages if they need to be refreshed when shown Actually ignoring messages from ignored users is still not implemented Working on #247 --- src/providers/twitch/twitchaccount.hpp | 1 - src/util/networkrequest.hpp | 49 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/providers/twitch/twitchaccount.hpp b/src/providers/twitch/twitchaccount.hpp index 649fd1f81..86f14153c 100644 --- a/src/providers/twitch/twitchaccount.hpp +++ b/src/providers/twitch/twitchaccount.hpp @@ -55,7 +55,6 @@ public: bool isAnon() const; void loadIgnores(); - void ignore(const QString &targetName, std::function onFinished); void ignoreByID(const QString &targetUserID, const QString &targetName, diff --git a/src/util/networkrequest.hpp b/src/util/networkrequest.hpp index 6131528c1..d90c63a0d 100644 --- a/src/util/networkrequest.hpp +++ b/src/util/networkrequest.hpp @@ -151,15 +151,26 @@ public: } void setRawHeader(const char *headerName, const char *value) +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df +======= { this->data.request.setRawHeader(headerName, value); } void setRawHeader(const char *headerName, const QByteArray &value) +>>>>>>> Implement /ignore and /unignore commands { this->data.request.setRawHeader(headerName, value); } +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df + void setRawHeader(const char *headerName, const QByteArray &value) + { + this->data.request.setRawHeader(headerName, value); + } + +======= +>>>>>>> Implement /ignore and /unignore commands void setRawHeader(const char *headerName, const QString &value) { this->data.request.setRawHeader(headerName, value.toUtf8()); @@ -302,16 +313,28 @@ public: void execute() { switch (this->data.requestType) { +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df case GetRequest: { this->executeGet(); } break; case PutRequest: { +======= + case GET: { + this->executeGet(); + } break; + + case PUT: { +>>>>>>> Implement /ignore and /unignore commands debug::Log("Call PUT request!"); this->executePut(); } break; +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df case DeleteRequest: { +======= + case DELETE: { +>>>>>>> Implement /ignore and /unignore commands debug::Log("Call DELETE request!"); this->executeDelete(); } break; @@ -369,6 +392,7 @@ private: worker->moveToThread(&NetworkManager::workerThread); if (this->data.caller != nullptr) { +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df QObject::connect(worker, &NetworkWorker::doneUrl, this->data.caller, [data = this->data](auto reply) mutable { auto &dat = data; @@ -377,6 +401,12 @@ private: if (data.onError) { data.onError(reply->error()); } +======= + QObject::connect(worker, &NetworkWorker::doneUrl, + this->data.caller, [data = this->data](auto reply) mutable { + if (reply->error() != QNetworkReply::NetworkError::NoError) { + // TODO: We might want to call an onError callback here +>>>>>>> Implement /ignore and /unignore commands return; } @@ -395,6 +425,7 @@ private: } QObject::connect(&requester, &NetworkRequester::requestUrl, worker, +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df [ timer, data = std::move(this->data), worker ]() { QNetworkReply *reply; switch (data.requestType) { @@ -407,6 +438,20 @@ private: } break; case DeleteRequest: { +======= + [ timer, data = std::move(this->data), worker ]() { + QNetworkReply *reply; + switch (data.requestType) { + case GET: { + reply = NetworkManager::NaM.get(data.request); + } break; + + case PUT: { + reply = NetworkManager::NaM.put(data.request, data.payload); + } break; + + case DELETE: { +>>>>>>> Implement /ignore and /unignore commands reply = NetworkManager::NaM.deleteResource(data.request); } break; } @@ -431,7 +476,11 @@ private: } QObject::connect(reply, &QNetworkReply::finished, worker, +<<<<<<< 5b26cdaa0777562a0b3c663a203528eca56bd5df [ data = std::move(data), worker, reply ]() mutable { +======= + [ data = std::move(data), worker, reply ]() mutable { +>>>>>>> Implement /ignore and /unignore commands if (data.caller == nullptr) { QByteArray bytes = reply->readAll(); data.writeToCache(bytes);