using ChatTwo.Code; using Dalamud.Configuration; namespace ChatTwo; [Serializable] internal class Configuration : IPluginConfiguration { public int Version { get; set; } = 1; public bool HideChat = true; public float FontSize = 17f; public Dictionary ChatColours = new(); public List Tabs = new(); } [Serializable] internal class Tab { public string Name = "New tab"; public Dictionary ChatCodes = new(); public bool DisplayUnread = true; public bool DisplayTimestamp = true; [NonSerialized] public uint Unread; [NonSerialized] public Mutex MessagesMutex = new(); [NonSerialized] public List Messages = new(); ~Tab() { this.MessagesMutex.Dispose(); } internal bool Matches(Message message) { return this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source)); } internal void AddMessage(Message message) { this.MessagesMutex.WaitOne(); this.Messages.Add(message); if (this.Messages.Count > 1000) { this.Messages.RemoveAt(0); } this.MessagesMutex.ReleaseMutex(); this.Unread += 1; } internal Tab Clone() { return new Tab { Name = this.Name, ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value), DisplayUnread = this.DisplayUnread, DisplayTimestamp = this.DisplayTimestamp, }; } }