Only listen to new pubsub "moderator added" syntax (#1659)

This commit is contained in:
pajlada 2020-05-03 06:21:00 -04:00 committed by GitHub
parent 7719816891
commit ef9c631c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 22 deletions

View file

@ -347,30 +347,31 @@ PubSub::PubSub()
this->moderationActionHandlers["mod"] = [this](const auto &data,
const auto &roomID) {
ModerationStateAction action(data, roomID);
getTargetUser(data, action.target);
try
{
const auto &args = getArgs(data);
if (args.Size() < 1)
{
return;
}
if (!rj::getSafe(args[0], action.target.name))
{
return;
}
}
catch (const std::runtime_error &ex)
{
qDebug() << "Error parsing moderation action:" << ex.what();
}
action.modded = true;
QString innerType;
if (rj::getSafe(data, "type", innerType) &&
innerType == "chat_login_moderation")
{
// Don't display the old message type
return;
}
if (!getTargetUser(data, action.target))
{
qDebug() << "Error parsing moderation action mod: Unable to get "
"target_user_id";
return;
}
// Load target name from message.data.target_user_login
if (!getTargetUserName(data, action.target))
{
qDebug() << "Error parsing moderation action mod: Unable to get "
"target_user_name";
return;
}
this->signals_.moderation.moderationStateChanged.invoke(action);
};

View file

@ -46,6 +46,11 @@ bool getTargetUser(const rapidjson::Value &data, ActionUser &user)
return rj::getSafe(data, "target_user_id", user.id);
}
bool getTargetUserName(const rapidjson::Value &data, ActionUser &user)
{
return rj::getSafe(data, "target_user_login", user.name);
}
rapidjson::Document createListenMessage(const std::vector<QString> &topicsVec,
std::shared_ptr<TwitchAccount> account)
{

View file

@ -16,6 +16,7 @@ const rapidjson::Value &getMsgID(const rapidjson::Value &data);
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
bool getTargetUserName(const rapidjson::Value &data, ActionUser &user);
rapidjson::Document createListenMessage(const std::vector<QString> &topicsVec,
std::shared_ptr<TwitchAccount> account);