fix: make ExtraChat filtering actually work

This commit is contained in:
Anna 2022-08-27 13:44:34 -04:00
parent cfa57ae11a
commit 7dc83bb8a2
3 changed files with 15 additions and 5 deletions

View File

@ -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));
}

View File

@ -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);
}
}
}

View File

@ -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();
}