diff --git a/MixItUp.Base/Model/Currency/CurrencyModel.cs b/MixItUp.Base/Model/Currency/CurrencyModel.cs index 11381440c..9712bd22a 100644 --- a/MixItUp.Base/Model/Currency/CurrencyModel.cs +++ b/MixItUp.Base/Model/Currency/CurrencyModel.cs @@ -198,6 +198,9 @@ public CurrencyModel() [JsonIgnore] public string AllTotalAmountDisplaySpecialIdentifier { get { return string.Format("{0}display", this.AllTotalAmountSpecialIdentifier); } } + [JsonIgnore] + public string RankCountSpecialIdentifierHeader { get { return string.Format("{0}rankcount", this.SpecialIdentifier); } } + [JsonIgnore] public string TopRegexSpecialIdentifier { get { return string.Format("{0}\\d+{1}", SpecialIdentifierStringBuilder.TopSpecialIdentifierHeader, this.SpecialIdentifier); } } diff --git a/MixItUp.Base/Util/SpecialIdentifierStringBuilder.cs b/MixItUp.Base/Util/SpecialIdentifierStringBuilder.cs index 1f1c29027..7204381da 100644 --- a/MixItUp.Base/Util/SpecialIdentifierStringBuilder.cs +++ b/MixItUp.Base/Util/SpecialIdentifierStringBuilder.cs @@ -403,6 +403,25 @@ await this.ReplaceNumberBasedRegexSpecialIdentifier(currency.TopRegexSpecialIden this.ReplaceSpecialIdentifier(currency.AllTotalAmountDisplaySpecialIdentifier, total.ToNumberDisplayString()); this.ReplaceSpecialIdentifier(currency.AllTotalAmountSpecialIdentifier, total.ToString()); } + + if (currency.IsRank && this.ContainsSpecialIdentifier(currency.RankCountSpecialIdentifierHeader)) + { + await ServiceManager.Get().LoadAllUserData(); + + IEnumerable applicableUsers = await SpecialIdentifierStringBuilder.GetAllNonExemptUsers(); + + foreach (RankModel rank in currency.Ranks.OrderByDescending(r => r.Name.Length)) + { + string rankSpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(rank.Name); + string fullIdentifier = currency.RankCountSpecialIdentifierHeader + rankSpecialIdentifier; + + if (this.ContainsSpecialIdentifier(fullIdentifier)) + { + int count = applicableUsers.Count(u => currency.GetRank(u).Name.Equals(rank.Name, StringComparison.OrdinalIgnoreCase)); + this.ReplaceSpecialIdentifier(fullIdentifier, count.ToString()); + } + } + } } if (ChannelSession.Settings.QuotesEnabled && ChannelSession.Settings.Quotes.Count > 0)