feat: require filter to be enabled to report

This commit is contained in:
Anna 2021-05-15 20:31:22 -04:00
parent cd9a9c3e79
commit 90566f1435
7 changed files with 46 additions and 5 deletions

View File

@ -94,7 +94,8 @@ namespace NoSoliciting {
listing.Description,
category,
reason == "custom",
reason == "ilvl"
reason == "ilvl",
this.Plugin.Config.CreateFiltersClone()
));
if (category == null && reason == null) {
@ -160,7 +161,8 @@ namespace NoSoliciting {
message,
classification,
custom,
false
false,
this.Plugin.Config.CreateFiltersClone()
);
this.Plugin.AddMessageHistory(history);

View File

@ -4,7 +4,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using NoSoliciting.Ml;
namespace NoSoliciting {
public static class FilterUtil {
@ -123,9 +123,13 @@ namespace NoSoliciting {
}
}
public static class RmtExtensions {
public static class Extensions {
public static bool ContainsIgnoreCase(this string haystack, string needle) {
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0;
}
public static bool WasEnabled(this IEnumerable<MessageCategory> enabled, MessageCategory category) {
return enabled.Contains(category);
}
}
}

View File

@ -281,6 +281,8 @@ namespace NoSoliciting.Interface {
errorText = Language.ReportModalDisabledItemLevel;
} else if (message.ModelVersion == null) {
errorText = Language.ReportModalDisabledBadModel;
} else if (!message.EnabledSnapshot.WasEnabled(this._reportCategory ?? MessageCategory.Normal)) {
errorText = Language.ReportModalDisabledFilterNotEnabled;
} else if (this._reportCategory == (message.Classification ?? MessageCategory.Normal)) {
errorText = Language.ReportModalDisabledSameClassification;
} else {

View File

@ -27,6 +27,8 @@ namespace NoSoliciting {
public SeString Sender { get; }
public SeString Content { get; }
public IEnumerable<MessageCategory> EnabledSnapshot { get; }
public MessageCategory? Classification { get; }
public bool Custom { get; }
@ -40,7 +42,7 @@ namespace NoSoliciting {
? "ilvl"
: this.Classification?.Name();
internal Message(uint? defsVersion, ChatType type, uint actorId, SeString sender, SeString content, MessageCategory? classification, bool custom, bool ilvl) {
internal Message(uint? defsVersion, ChatType type, uint actorId, SeString sender, SeString content, MessageCategory? classification, bool custom, bool ilvl, IEnumerable<MessageCategory> enabledSnapshot) {
this.Id = Guid.NewGuid();
this.ModelVersion = defsVersion;
this.Timestamp = DateTime.Now;
@ -51,6 +53,7 @@ namespace NoSoliciting {
this.Classification = classification;
this.Custom = custom;
this.ItemLevel = ilvl;
this.EnabledSnapshot = enabledSnapshot;
}
[Serializable]

View File

@ -126,5 +126,23 @@ namespace NoSoliciting {
return filtered.Contains(chatType);
}
internal IEnumerable<MessageCategory> CreateFiltersClone() {
var filters = new HashSet<MessageCategory>();
foreach (var category in (MessageCategory[]) Enum.GetValues(typeof(MessageCategory))) {
if (this.AdvancedMode) {
if (this.MlFilters.TryGetValue(category, out var filtered) && filtered.Count > 0) {
filters.Add(category);
}
} else {
if (this.BasicMlFilters.Contains(category)) {
filters.Add(category);
}
}
}
return filters;
}
}
}

View File

@ -492,6 +492,15 @@ namespace NoSoliciting.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Reporting is disabled because you weren&apos;t filtering for this kind of message at the time you saw it..
/// </summary>
internal static string ReportModalDisabledFilterNotEnabled {
get {
return ResourceManager.GetString("ReportModalDisabledFilterNotEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You cannot report messages filtered because of item level..
/// </summary>

View File

@ -273,4 +273,7 @@
<data name="ReportModalSuggestedClassification" xml:space="preserve">
<value>How do you think this message should have been classified?</value>
</data>
<data name="ReportModalDisabledFilterNotEnabled" xml:space="preserve">
<value>Reporting is disabled because you weren't filtering for this kind of message at the time you saw it.</value>
</data>
</root>