From d21858b97fd04a8127b2b6d9b9368e18bc996b88 Mon Sep 17 00:00:00 2001 From: Tal Neoran Date: Sat, 19 Jun 2021 17:00:03 +0300 Subject: [PATCH] Fix moderation button time units when not using seconds (#2864) --- CHANGELOG.md | 1 + .../moderationactions/ModerationAction.cpp | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aca34963f..d350f6a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Minor: Now shows deletions of messages like timeouts (#1155, #2841, #2867, #2874) - Minor: Added a link to accounts page in settings to "You need to be logged in to send messages" message. (#2862) - Minor: Switch to Twitch v2 emote API for animated emote support. (#2863) +- Bugfix: Moderation buttons now show the correct time unit when using units other than seconds. (#1719, #2864) - Bugfix: Fixed FFZ emote links for global emotes (#2807, #2808) - Bugfix: Fixed pasting text with URLs included (#1688, #2855) - Bugfix: Fix reconnecting when IRC write connection is lost (#1831, #2356, #2850) diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index d94cb234d..467f9db5c 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -29,7 +29,7 @@ ModerationAction::ModerationAction(const QString &action) : action_(action) { static QRegularExpression replaceRegex("[!/.]"); - static QRegularExpression timeoutRegex("^[./]timeout.* (\\d+)"); + static QRegularExpression timeoutRegex("^[./]timeout.* (\\d+)([mhdw]?)"); auto timeoutMatch = timeoutRegex.match(action); @@ -39,27 +39,55 @@ ModerationAction::ModerationAction(const QString &action) // QString line1; // QString line2; - int amount = timeoutMatch.captured(1).toInt(); + constexpr int minute = 60; + constexpr int hour = 60 * minute; + constexpr int day = 24 * hour; + constexpr int week = 7 * day; - if (amount < 60) + int amount = timeoutMatch.captured(1).toInt(); + QString unit = timeoutMatch.captured(2); + + if (unit == "m") + { + amount *= minute; + } + else if (unit == "h") + { + amount *= hour; + } + else if (unit == "d") + { + amount *= day; + } + else if (unit == "w") + { + amount *= week; + } + + if (amount < minute) { this->line1_ = QString::number(amount); this->line2_ = "s"; } - else if (amount < 60 * 60) + else if (amount < hour) { - this->line1_ = QString::number(amount / 60); + this->line1_ = QString::number(amount / minute); this->line2_ = "m"; } - else if (amount < 60 * 60 * 24) + else if (amount < day) { - this->line1_ = QString::number(amount / 60 / 60); + this->line1_ = QString::number(amount / hour); this->line2_ = "h"; } + else if (amount < week) + { + this->line1_ = QString::number(amount / day); + this->line2_ = "d"; + } else { - this->line1_ = QString::number(amount / 60 / 60 / 24); - this->line2_ = "d"; + this->line1_ = QString::number(amount / week); + this->line2_ = "w"; } // line1 = this->line1_;