From 7dc83bb8a276e6ca50841c3a317a0e330cf2a005 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 27 Aug 2022 13:44:34 -0400 Subject: [PATCH] fix: make ExtraChat filtering actually work --- ChatTwo/Configuration.cs | 7 +++---- ChatTwo/Store.cs | 5 ++++- ChatTwo/Ui/SettingsTabs/Tabs.cs | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 03b07ed..9041bf9 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -175,17 +175,16 @@ internal class Tab { } internal bool Matches(Message message) { - var extraChatChannel = Guid.Empty; if (message.ContentSource.Payloads.Count > 0 && message.ContentSource.Payloads[0] is RawPayload raw) { // this does an encode and clone every time it's accessed, so cache var data = raw.Data; - if (data[1] == 0x27 && data[2] == 19 && data[3] == 0x20) { - extraChatChannel = new Guid(data[4..]); + if (data[1] == 0x27 && data[2] == 18 && data[3] == 0x20) { + var extraChatChannel = new Guid(data[4..^1]); + return this.ExtraChatAll || this.ExtraChatChannels.Contains(extraChatChannel); } } return message.Code.Type.IsGm() - || (extraChatChannel != Guid.Empty && (this.ExtraChatAll || this.ExtraChatChannels.Contains(extraChatChannel))) || this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source)); } diff --git a/ChatTwo/Store.cs b/ChatTwo/Store.cs index 313bea1..313eda6 100755 --- a/ChatTwo/Store.cs +++ b/ChatTwo/Store.cs @@ -229,7 +229,10 @@ internal class Store : IDisposable { .ToEnumerable() .Reverse(); foreach (var message in messages) { - tab.AddMessage(message, unread); + // redundant matches check for extrachat + if (tab.Matches(message)) { + tab.AddMessage(message, unread); + } } } diff --git a/ChatTwo/Ui/SettingsTabs/Tabs.cs b/ChatTwo/Ui/SettingsTabs/Tabs.cs index fcd4ded..711cc54 100755 --- a/ChatTwo/Ui/SettingsTabs/Tabs.cs +++ b/ChatTwo/Ui/SettingsTabs/Tabs.cs @@ -165,6 +165,10 @@ internal sealed class Tabs : ISettingsTab { ImGui.Separator(); + if (tab.ExtraChatAll) { + ImGui.BeginDisabled(); + } + foreach (var (id, name) in this.Plugin.ExtraChat.ChannelNames) { var enabled = tab.ExtraChatChannels.Contains(id); if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled)) { @@ -178,6 +182,10 @@ internal sealed class Tabs : ISettingsTab { } } + if (tab.ExtraChatAll) { + ImGui.EndDisabled(); + } + ImGui.TreePop(); }