mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Fix chatters recursion not working (#4114)
This commit is contained in:
parent
e531161c7f
commit
2ec26f57cc
|
@ -70,7 +70,7 @@
|
||||||
- Minor: Migrated /commercial to Helix API. (#4094)
|
- Minor: Migrated /commercial to Helix API. (#4094)
|
||||||
- Minor: Added stream titles to windows live toast notifications. (#1297)
|
- Minor: Added stream titles to windows live toast notifications. (#1297)
|
||||||
- Minor: Make menus and placeholders display appropriate custom key combos. (#4045)
|
- Minor: Make menus and placeholders display appropriate custom key combos. (#4045)
|
||||||
- Minor: Migrated /chatters to Helix API. (#4088, #4097)
|
- Minor: Migrated /chatters to Helix API. (#4088, #4097, #4114)
|
||||||
- Minor: Migrated /mods to Helix API. (#4103)
|
- Minor: Migrated /mods to Helix API. (#4103)
|
||||||
- Minor: Add settings tooltips. (#3437)
|
- Minor: Add settings tooltips. (#3437)
|
||||||
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
|
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
|
||||||
|
|
|
@ -878,8 +878,8 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
return "";
|
return "";
|
||||||
});
|
});
|
||||||
|
|
||||||
this->registerCommand("/chatters", [](const auto &words, auto channel) {
|
auto formatChattersError = [](HelixGetChattersError error,
|
||||||
auto formatError = [](HelixGetChattersError error, QString message) {
|
QString message) {
|
||||||
using Error = HelixGetChattersError;
|
using Error = HelixGetChattersError;
|
||||||
|
|
||||||
QString errorMessage = QString("Failed to get chatter count: ");
|
QString errorMessage = QString("Failed to get chatter count: ");
|
||||||
|
@ -912,7 +912,9 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
this->registerCommand(
|
||||||
|
"/chatters", [formatChattersError](const auto &words, auto channel) {
|
||||||
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
if (twitchChannel == nullptr)
|
if (twitchChannel == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -926,12 +928,59 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
twitchChannel->roomId(),
|
twitchChannel->roomId(),
|
||||||
getApp()->accounts->twitch.getCurrent()->getUserId(), 1,
|
getApp()->accounts->twitch.getCurrent()->getUserId(), 1,
|
||||||
[channel](auto result) {
|
[channel](auto result) {
|
||||||
channel->addMessage(
|
channel->addMessage(makeSystemMessage(
|
||||||
makeSystemMessage(QString("Chatter count: %1")
|
QString("Chatter count: %1")
|
||||||
.arg(localizeNumbers(result.total))));
|
.arg(localizeNumbers(result.total))));
|
||||||
},
|
},
|
||||||
[channel, formatError](auto error, auto message) {
|
[channel, formatChattersError](auto error, auto message) {
|
||||||
auto errorMessage = formatError(error, message);
|
auto errorMessage = formatChattersError(error, message);
|
||||||
|
channel->addMessage(makeSystemMessage(errorMessage));
|
||||||
|
});
|
||||||
|
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
|
||||||
|
this->registerCommand("/test-chatters", [formatChattersError](
|
||||||
|
const auto & /*words*/,
|
||||||
|
auto channel) {
|
||||||
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||||
|
|
||||||
|
if (twitchChannel == nullptr)
|
||||||
|
{
|
||||||
|
channel->addMessage(makeSystemMessage(
|
||||||
|
"The /test-chatters command only works in Twitch Channels"));
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
getHelix()->getChatters(
|
||||||
|
twitchChannel->roomId(),
|
||||||
|
getApp()->accounts->twitch.getCurrent()->getUserId(), 5000,
|
||||||
|
[channel, twitchChannel](auto result) {
|
||||||
|
QStringList entries;
|
||||||
|
for (const auto &username : result.chatters)
|
||||||
|
{
|
||||||
|
entries << username;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString prefix = "Chatters ";
|
||||||
|
|
||||||
|
if (result.total > 5000)
|
||||||
|
{
|
||||||
|
prefix += QString("(5000/%1):").arg(result.total);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prefix += QString("(%1):").arg(result.total);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBuilder builder;
|
||||||
|
TwitchMessageBuilder::listOfUsersSystemMessage(
|
||||||
|
prefix, entries, twitchChannel, &builder);
|
||||||
|
|
||||||
|
channel->addMessage(builder.release());
|
||||||
|
},
|
||||||
|
[channel, formatChattersError](auto error, auto message) {
|
||||||
|
auto errorMessage = formatChattersError(error, message);
|
||||||
channel->addMessage(makeSystemMessage(errorMessage));
|
channel->addMessage(makeSystemMessage(errorMessage));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ using namespace chatterino;
|
||||||
|
|
||||||
static constexpr auto NUM_MODERATORS_TO_FETCH_PER_REQUEST = 100;
|
static constexpr auto NUM_MODERATORS_TO_FETCH_PER_REQUEST = 100;
|
||||||
|
|
||||||
|
static constexpr auto NUM_CHATTERS_TO_FETCH = 1000;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -1790,6 +1792,37 @@ void Helix::updateChatSettings(
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Helix::onFetchChattersSuccess(
|
||||||
|
std::shared_ptr<HelixChatters> finalChatters, QString broadcasterID,
|
||||||
|
QString moderatorID, int maxChattersToFetch,
|
||||||
|
ResultCallback<HelixChatters> successCallback,
|
||||||
|
FailureCallback<HelixGetChattersError, QString> failureCallback,
|
||||||
|
HelixChatters chatters)
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoTwitch)
|
||||||
|
<< "Fetched" << chatters.chatters.size() << "chatters";
|
||||||
|
|
||||||
|
finalChatters->chatters.merge(chatters.chatters);
|
||||||
|
finalChatters->total = chatters.total;
|
||||||
|
|
||||||
|
if (chatters.cursor.isEmpty() ||
|
||||||
|
finalChatters->chatters.size() >= maxChattersToFetch)
|
||||||
|
{
|
||||||
|
// Done paginating
|
||||||
|
successCallback(*finalChatters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->fetchChatters(
|
||||||
|
broadcasterID, moderatorID, NUM_CHATTERS_TO_FETCH, chatters.cursor,
|
||||||
|
[=](auto chatters) {
|
||||||
|
this->onFetchChattersSuccess(
|
||||||
|
finalChatters, broadcasterID, moderatorID, maxChattersToFetch,
|
||||||
|
successCallback, failureCallback, chatters);
|
||||||
|
},
|
||||||
|
failureCallback);
|
||||||
|
}
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-chatters
|
// https://dev.twitch.tv/docs/api/reference#get-chatters
|
||||||
void Helix::fetchChatters(
|
void Helix::fetchChatters(
|
||||||
QString broadcasterID, QString moderatorID, int first, QString after,
|
QString broadcasterID, QString moderatorID, int first, QString after,
|
||||||
|
@ -2191,36 +2224,17 @@ void Helix::getChatters(
|
||||||
ResultCallback<HelixChatters> successCallback,
|
ResultCallback<HelixChatters> successCallback,
|
||||||
FailureCallback<HelixGetChattersError, QString> failureCallback)
|
FailureCallback<HelixGetChattersError, QString> failureCallback)
|
||||||
{
|
{
|
||||||
static const auto NUM_CHATTERS_TO_FETCH = 1000;
|
|
||||||
|
|
||||||
auto finalChatters = std::make_shared<HelixChatters>();
|
auto finalChatters = std::make_shared<HelixChatters>();
|
||||||
|
|
||||||
auto fetchSuccess = [this, broadcasterID, moderatorID, maxChattersToFetch,
|
|
||||||
finalChatters, successCallback,
|
|
||||||
failureCallback](auto fs) {
|
|
||||||
return [=](auto chatters) {
|
|
||||||
qCDebug(chatterinoTwitch)
|
|
||||||
<< "Fetched" << chatters.chatters.size() << "chatters";
|
|
||||||
finalChatters->chatters.merge(chatters.chatters);
|
|
||||||
finalChatters->total = chatters.total;
|
|
||||||
|
|
||||||
if (chatters.cursor.isEmpty() ||
|
|
||||||
finalChatters->chatters.size() >= maxChattersToFetch)
|
|
||||||
{
|
|
||||||
// Done paginating
|
|
||||||
successCallback(*finalChatters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->fetchChatters(broadcasterID, moderatorID,
|
|
||||||
NUM_CHATTERS_TO_FETCH, chatters.cursor, fs,
|
|
||||||
failureCallback);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initiate the recursive calls
|
// Initiate the recursive calls
|
||||||
this->fetchChatters(broadcasterID, moderatorID, NUM_CHATTERS_TO_FETCH, "",
|
this->fetchChatters(
|
||||||
fetchSuccess(fetchSuccess), failureCallback);
|
broadcasterID, moderatorID, NUM_CHATTERS_TO_FETCH, "",
|
||||||
|
[=](auto chatters) {
|
||||||
|
this->onFetchChattersSuccess(
|
||||||
|
finalChatters, broadcasterID, moderatorID, maxChattersToFetch,
|
||||||
|
successCallback, failureCallback, chatters);
|
||||||
|
},
|
||||||
|
failureCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-moderators
|
// https://dev.twitch.tv/docs/api/reference#get-moderators
|
||||||
|
|
|
@ -1206,6 +1206,14 @@ protected:
|
||||||
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
|
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
|
||||||
final;
|
final;
|
||||||
|
|
||||||
|
// Recursive boy
|
||||||
|
void onFetchChattersSuccess(
|
||||||
|
std::shared_ptr<HelixChatters> finalChatters, QString broadcasterID,
|
||||||
|
QString moderatorID, int maxChattersToFetch,
|
||||||
|
ResultCallback<HelixChatters> successCallback,
|
||||||
|
FailureCallback<HelixGetChattersError, QString> failureCallback,
|
||||||
|
HelixChatters chatters);
|
||||||
|
|
||||||
// Get chatters list - This method is what actually runs the API request
|
// Get chatters list - This method is what actually runs the API request
|
||||||
// https://dev.twitch.tv/docs/api/reference#get-chatters
|
// https://dev.twitch.tv/docs/api/reference#get-chatters
|
||||||
void fetchChatters(
|
void fetchChatters(
|
||||||
|
|
Loading…
Reference in a new issue