Fix moderation button time units when not using seconds (#2864)

This commit is contained in:
Tal Neoran 2021-06-19 17:00:03 +03:00 committed by GitHub
parent 9640837957
commit d21858b97f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 9 deletions

View file

@ -15,6 +15,7 @@
- Minor: Now shows deletions of messages like timeouts (#1155, #2841, #2867, #2874) - 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: 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) - 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 FFZ emote links for global emotes (#2807, #2808)
- Bugfix: Fixed pasting text with URLs included (#1688, #2855) - Bugfix: Fixed pasting text with URLs included (#1688, #2855)
- Bugfix: Fix reconnecting when IRC write connection is lost (#1831, #2356, #2850) - Bugfix: Fix reconnecting when IRC write connection is lost (#1831, #2356, #2850)

View file

@ -29,7 +29,7 @@ ModerationAction::ModerationAction(const QString &action)
: action_(action) : action_(action)
{ {
static QRegularExpression replaceRegex("[!/.]"); static QRegularExpression replaceRegex("[!/.]");
static QRegularExpression timeoutRegex("^[./]timeout.* (\\d+)"); static QRegularExpression timeoutRegex("^[./]timeout.* (\\d+)([mhdw]?)");
auto timeoutMatch = timeoutRegex.match(action); auto timeoutMatch = timeoutRegex.match(action);
@ -39,27 +39,55 @@ ModerationAction::ModerationAction(const QString &action)
// QString line1; // QString line1;
// QString line2; // 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->line1_ = QString::number(amount);
this->line2_ = "s"; 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"; 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"; this->line2_ = "h";
} }
else if (amount < week)
{
this->line1_ = QString::number(amount / day);
this->line2_ = "d";
}
else else
{ {
this->line1_ = QString::number(amount / 60 / 60 / 24); this->line1_ = QString::number(amount / week);
this->line2_ = "d"; this->line2_ = "w";
} }
// line1 = this->line1_; // line1 = this->line1_;