From c87114a640936cbc3471656fc7701863ddb43000 Mon Sep 17 00:00:00 2001 From: apa420 Date: Tue, 22 Jan 2019 23:20:43 +0100 Subject: [PATCH] rewrote the cases with enums --- src/messages/MessageBuilder.cpp | 66 +++++++++++++++----------- src/providers/twitch/PubsubActions.hpp | 10 +++- src/providers/twitch/PubsubClient.cpp | 10 ++-- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 9a4b1a00d..078e44251 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -244,34 +244,46 @@ MessageBuilder::MessageBuilder(const AutomodUserAction &action) this->message().flags.set(MessageFlag::System); QString text; - if (action.type == 1) + switch (action.type) { - text = QString("%1 added %2 as a permitted term on AutoMod.") - .arg(action.source.name) - .arg(action.message); - } - else if (action.type == 2) - { - text = QString("%1 added %2 as a blocked term on AutoMod.") - .arg(action.source.name) - .arg(action.message); - } - else if (action.type == 3) - { - text = QString("%1 removed %2 as a permitted term term on AutoMod.") - .arg(action.source.name) - .arg(action.message); - } - else if (action.type == 4) - { - text = QString("%1 removed %2 as a blocked term on AutoMod.") - .arg(action.source.name) - .arg(action.message); - } - else if (action.type == 5) - { - text = QString("%1 modified the AutoMod properties.") - .arg(action.source.name); + case action.AddPermitted: + { + text = QString("%1 added %2 as a permitted term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + break; + + case action.AddBlocked: + { + text = QString("%1 added %2 as a blocked term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + break; + + case action.RemovePermitted: + { + text = QString("%1 removed %2 as a permitted term term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + break; + + case action.RemoveBlocked: + { + text = QString("%1 removed %2 as a blocked term on AutoMod.") + .arg(action.source.name) + .arg(action.message); + } + break; + + case action.Properties: + { + text = QString("%1 modified the AutoMod properties.") + .arg(action.source.name); + } + break; } this->emplace(text, MessageElementFlag::Text, diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index 6377b6d4e..1356aac69 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -122,9 +122,15 @@ struct AutomodUserAction : PubSubAction { ActionUser target; - QString message; + enum { + AddPermitted, + RemovePermitted, + AddBlocked, + RemoveBlocked, + Properties, + } type; - qint8 type; + QString message; }; } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index f5fb54255..0a8976618 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -581,7 +581,7 @@ PubSub::PubSub() try { const auto &args = getArgs(data); - action.type = 1; + action.type = AutomodUserAction::AddPermitted; if (args.Size() < 1) { @@ -610,7 +610,7 @@ PubSub::PubSub() try { const auto &args = getArgs(data); - action.type = 2; + action.type = AutomodUserAction::AddBlocked; if (args.Size() < 1) { @@ -639,7 +639,7 @@ PubSub::PubSub() try { const auto &args = getArgs(data); - action.type = 3; + action.type = AutomodUserAction::RemovePermitted; if (args.Size() < 1) { @@ -669,7 +669,7 @@ PubSub::PubSub() try { const auto &args = getArgs(data); - action.type = 4; + action.type = AutomodUserAction::RemoveBlocked; if (args.Size() < 1) { @@ -694,7 +694,7 @@ PubSub::PubSub() // The automod settings got modified AutomodUserAction action(data, roomID); getCreatedByUser(data, action.source); - action.type = 5; + action.type = AutomodUserAction::Properties; this->signals_.moderation.automodUserMessage.invoke(action); };