From 36c6732cb0cc6ef5a65f9678493bc3fdfd9f3fbd Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Fri, 4 Sep 2020 15:25:36 -0400 Subject: [PATCH] feat: include defs version in reports --- NoSoliciting/Filter.cs | 2 ++ NoSoliciting/Message.cs | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/NoSoliciting/Filter.cs b/NoSoliciting/Filter.cs index 16774a4..7996eed 100644 --- a/NoSoliciting/Filter.cs +++ b/NoSoliciting/Filter.cs @@ -81,6 +81,7 @@ namespace NoSoliciting { && SetReason(ref reason, "custom")); this.plugin.AddPartyFinderHistory(new Message( + defs: this.plugin.Definitions, type: ChatType.None, sender: listing.Name(), content: listing.Description(), @@ -149,6 +150,7 @@ namespace NoSoliciting { && SetReason(ref reason, "custom")); this.plugin.AddMessageHistory(new Message( + defs: this.plugin.Definitions, type: (ChatType)type, sender: sender, content: message, diff --git a/NoSoliciting/Message.cs b/NoSoliciting/Message.cs index b9b4c16..9838010 100644 --- a/NoSoliciting/Message.cs +++ b/NoSoliciting/Message.cs @@ -9,14 +9,20 @@ using System.Linq; namespace NoSoliciting { public class Message { public Guid Id { get; private set; } + public uint DefinitionsVersion { get; private set; } public DateTime Timestamp { get; private set; } public ChatType ChatType { get; private set; } public SeString Sender { get; private set; } public SeString Content { get; private set; } public string FilterReason { get; private set; } - public Message(ChatType type, SeString sender, SeString content, string reason) { + public Message(Definitions defs, ChatType type, SeString sender, SeString content, string reason) { + if (defs == null) { + throw new ArgumentNullException(nameof(defs), "Definitions cannot be null"); + } + this.Id = Guid.NewGuid(); + this.DefinitionsVersion = defs.Version; this.Timestamp = DateTime.Now; this.ChatType = type; this.Sender = sender; @@ -24,19 +30,19 @@ namespace NoSoliciting { this.FilterReason = reason; } - public Message(ChatType type, string sender, string content, string reason) { - this.Id = Guid.NewGuid(); - this.Timestamp = DateTime.Now; - this.ChatType = type; - this.Sender = new SeString(new Payload[] { new TextPayload(sender) }); - this.Content = new SeString(new Payload[] { new TextPayload(content) }); - this.FilterReason = reason; - } + public Message(Definitions defs, ChatType type, string sender, string content, string reason) : this( + defs, + type, + new SeString(new Payload[] { new TextPayload(sender) }), + new SeString(new Payload[] { new TextPayload(content) }), + reason + ) { } [Serializable] [JsonObject(NamingStrategyType = typeof(SnakeCaseNamingStrategy))] private class JsonMessage { public Guid Id { get; set; } + public uint DefinitionsVersion { get; set; } public DateTime Timestamp { get; set; } public ushort Type { get; set; } // note: cannot use byte[] because Newtonsoft thinks it's a good idea to always base64 byte[] @@ -49,6 +55,7 @@ namespace NoSoliciting { public string ToJson() { JsonMessage msg = new JsonMessage { Id = this.Id, + DefinitionsVersion = this.DefinitionsVersion, Timestamp = this.Timestamp, Type = (ushort)this.ChatType, Sender = this.Sender.Encode().ToList(),