forked from SevenTV/chatterino7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e15eb1
commit 3417f93
Showing
5 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifdef CHATTERINO_HAVE_PLUGINS | ||
#include "Api.hpp" | ||
|
||
#include "common/NetworkRequest.hpp" | ||
#include "common/NetworkResult.hpp" | ||
#include "common/Outcome.hpp" | ||
|
||
#include <QJsonArray> | ||
#include <QJsonObject> | ||
#include <QJsonValue> | ||
|
||
namespace chatterino::pronouns { | ||
|
||
void fetchPronounsForUser(const QString &userName, | ||
ResultCallback onLoaded, ErrorCallback onError) | ||
{ | ||
|
||
NetworkRequest("https://pronouns.alejo.io/api/users/" + userName) | ||
.timeout(5 * 1000) | ||
.header("Accept", "application/json") | ||
.onSuccess([onLoaded, onError](auto result) -> Outcome { | ||
auto data = result.parseJsonArray(); | ||
QString pronoun("None"); | ||
|
||
if (!data.isEmpty()) | ||
{ | ||
pronoun = data[0].toObject().value("pronoun_id").toString(); | ||
} | ||
|
||
onLoaded(pronoun); | ||
|
||
return Success; | ||
}) | ||
.onError([onError](auto /* result */) { | ||
// TODO: make better xd | ||
|
||
onError(); | ||
}) | ||
.execute(); | ||
} | ||
|
||
} // namespace chatterino::pronouns | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#ifdef CHATTERINO_HAVE_PLUGINS | ||
#include <QString> | ||
|
||
|
||
#include <functional> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace chatterino::pronouns { | ||
|
||
using ResultCallback = std::function<void(const QString &)>; | ||
using ErrorCallback = std::function<void()>; | ||
|
||
/** | ||
* @brief Loads pronouns for user provided | ||
* | ||
* @param userName Name of Twitch User | ||
* @param onLoaded Callback taking the pronouns of the user | ||
* @param onError Callback called when the network request fails | ||
*/ | ||
void fetchPronounsForUser(const QString &userName, | ||
ResultCallback onLoaded, ErrorCallback onError); | ||
|
||
|
||
} // namespace chatterino::recentmessages | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters