Add support for non-highlight channel point rewards (#1809)

This commit is contained in:
Jonas Schmitt
2020-08-08 15:37:22 +02:00
committed by GitHub
parent 1bd3d10eef
commit 11b8948290
23 changed files with 498 additions and 25 deletions
+48
View File
@@ -804,6 +804,26 @@ void PubSub::listenToChannelModerationActions(
this->listenToTopic(topic, account);
}
void PubSub::listenToChannelPointRewards(const QString &channelID,
std::shared_ptr<TwitchAccount> account)
{
static const QString topicFormat("community-points-channel-v1.%1");
assert(!channelID.isEmpty());
assert(account != nullptr);
QString userID = account->getUserId();
auto topic = topicFormat.arg(channelID);
if (this->isListeningToTopic(topic))
{
return;
}
qDebug() << "Listen to topic" << topic;
this->listenToTopic(topic, account);
}
void PubSub::listenToTopic(const QString &topic,
std::shared_ptr<TwitchAccount> account)
{
@@ -1093,6 +1113,34 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData)
// Invoke handler function
handlerIt->second(data, topicParts[2]);
}
else if (topic.startsWith("community-points-channel-v1."))
{
std::string pointEventType;
if (!rj::getSafe(msg, "type", pointEventType))
{
qDebug() << "Bad channel point event data";
return;
}
if (pointEventType == "reward-redeemed")
{
if (!rj::getSafeObject(msg, "data", msg))
{
qDebug() << "No data found for redeemed reward";
return;
}
if (!rj::getSafeObject(msg, "redemption", msg))
{
qDebug() << "No redemption info found for redeemed reward";
return;
}
this->signals_.pointReward.redeemed.invoke(msg);
}
else
{
qDebug() << "Invalid point event type:" << pointEventType.c_str();
}
}
else
{
qDebug() << "Unknown topic:" << topic;