Fix double messages on startup
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.20.4</Version>
|
<Version>1.20.5</Version>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
@@ -87,5 +86,4 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="images\" />
|
<Folder Include="images\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+72
-42
@@ -7,7 +7,8 @@ using ImGuiNET;
|
|||||||
namespace ChatTwo;
|
namespace ChatTwo;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal class Configuration : IPluginConfiguration {
|
internal class Configuration : IPluginConfiguration
|
||||||
|
{
|
||||||
private const int LatestVersion = 5;
|
private const int LatestVersion = 5;
|
||||||
internal const int LatestDbVersion = 1;
|
internal const int LatestDbVersion = 1;
|
||||||
|
|
||||||
@@ -56,7 +57,8 @@ internal class Configuration : IPluginConfiguration {
|
|||||||
|
|
||||||
public uint DatabaseMigration = LatestDbVersion;
|
public uint DatabaseMigration = LatestDbVersion;
|
||||||
|
|
||||||
internal void UpdateFrom(Configuration other) {
|
internal void UpdateFrom(Configuration other)
|
||||||
|
{
|
||||||
HideChat = other.HideChat;
|
HideChat = other.HideChat;
|
||||||
HideDuringCutscenes = other.HideDuringCutscenes;
|
HideDuringCutscenes = other.HideDuringCutscenes;
|
||||||
HideWhenNotLoggedIn = other.HideWhenNotLoggedIn;
|
HideWhenNotLoggedIn = other.HideWhenNotLoggedIn;
|
||||||
@@ -97,14 +99,17 @@ internal class Configuration : IPluginConfiguration {
|
|||||||
ChosenStyle = other.ChosenStyle;
|
ChosenStyle = other.ChosenStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Migrate() {
|
public void Migrate()
|
||||||
|
{
|
||||||
var loop = true;
|
var loop = true;
|
||||||
while (loop && Version < LatestVersion) {
|
while (loop && Version < LatestVersion)
|
||||||
|
{
|
||||||
switch (Version) {
|
switch (Version) {
|
||||||
case 1: {
|
case 1: {
|
||||||
Version = 2;
|
Version = 2;
|
||||||
|
|
||||||
foreach (var tab in Tabs) {
|
foreach (var tab in Tabs)
|
||||||
|
{
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
tab.UnreadMode = tab.DisplayUnread ? UnreadMode.Unseen : UnreadMode.None;
|
tab.UnreadMode = tab.DisplayUnread ? UnreadMode.Unseen : UnreadMode.None;
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
@@ -126,10 +131,8 @@ internal class Configuration : IPluginConfiguration {
|
|||||||
case 4:
|
case 4:
|
||||||
Version = 5;
|
Version = 5;
|
||||||
|
|
||||||
foreach (var tab in Tabs) {
|
foreach (var tab in Tabs)
|
||||||
tab.ExtraChatAll = true;
|
tab.ExtraChatAll = true;
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Plugin.Log.Warning($"Couldn't migrate config version {Version}");
|
Plugin.Log.Warning($"Couldn't migrate config version {Version}");
|
||||||
@@ -141,21 +144,25 @@ internal class Configuration : IPluginConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal enum UnreadMode {
|
internal enum UnreadMode
|
||||||
|
{
|
||||||
All,
|
All,
|
||||||
Unseen,
|
Unseen,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class UnreadModeExt {
|
internal static class UnreadModeExt
|
||||||
internal static string Name(this UnreadMode mode) => mode switch {
|
{
|
||||||
|
internal static string Name(this UnreadMode mode) => mode switch
|
||||||
|
{
|
||||||
UnreadMode.All => Language.UnreadMode_All,
|
UnreadMode.All => Language.UnreadMode_All,
|
||||||
UnreadMode.Unseen => Language.UnreadMode_Unseen,
|
UnreadMode.Unseen => Language.UnreadMode_Unseen,
|
||||||
UnreadMode.None => Language.UnreadMode_None,
|
UnreadMode.None => Language.UnreadMode_None,
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static string? Tooltip(this UnreadMode mode) => mode switch {
|
internal static string? Tooltip(this UnreadMode mode) => mode switch
|
||||||
|
{
|
||||||
UnreadMode.All => Language.UnreadMode_All_Tooltip,
|
UnreadMode.All => Language.UnreadMode_All_Tooltip,
|
||||||
UnreadMode.Unseen => Language.UnreadMode_Unseen_Tooltip,
|
UnreadMode.Unseen => Language.UnreadMode_Unseen_Tooltip,
|
||||||
UnreadMode.None => Language.UnreadMode_None_Tooltip,
|
UnreadMode.None => Language.UnreadMode_None_Tooltip,
|
||||||
@@ -164,7 +171,8 @@ internal static class UnreadModeExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal class Tab {
|
internal class Tab
|
||||||
|
{
|
||||||
public string Name = Language.Tab_DefaultName;
|
public string Name = Language.Tab_DefaultName;
|
||||||
public Dictionary<ChatType, ChatSource> ChatCodes = new();
|
public Dictionary<ChatType, ChatSource> ChatCodes = new();
|
||||||
public bool ExtraChatAll;
|
public bool ExtraChatAll;
|
||||||
@@ -189,41 +197,48 @@ internal class Tab {
|
|||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public List<Message> Messages = new();
|
public List<Message> Messages = new();
|
||||||
|
|
||||||
~Tab() {
|
~Tab() { MessagesMutex.Dispose(); }
|
||||||
MessagesMutex.Dispose();
|
|
||||||
|
internal bool Contains(Message message)
|
||||||
|
{
|
||||||
|
return Messages.Any(m => m.Hash == message.Hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool Matches(Message message) {
|
internal bool Matches(Message message)
|
||||||
if (message.ExtraChatChannel != Guid.Empty) {
|
{
|
||||||
|
if (message.ExtraChatChannel != Guid.Empty)
|
||||||
return ExtraChatAll || ExtraChatChannels.Contains(message.ExtraChatChannel);
|
return ExtraChatAll || ExtraChatChannels.Contains(message.ExtraChatChannel);
|
||||||
}
|
|
||||||
|
|
||||||
return message.Code.Type.IsGm()
|
return message.Code.Type.IsGm()
|
||||||
|| ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
|
|| 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, bool unread = true) {
|
internal void AddMessage(Message message, bool unread = true)
|
||||||
|
{
|
||||||
MessagesMutex.Wait();
|
MessagesMutex.Wait();
|
||||||
Messages.Add(message);
|
Messages.Add(message);
|
||||||
while (Messages.Count > Store.MessagesLimit) {
|
while (Messages.Count > Store.MessagesLimit)
|
||||||
Messages.RemoveAt(0);
|
Messages.RemoveAt(0);
|
||||||
}
|
|
||||||
|
|
||||||
MessagesMutex.Release();
|
MessagesMutex.Release();
|
||||||
|
|
||||||
if (unread) {
|
if (unread)
|
||||||
Unread += 1;
|
Unread += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void Clear() {
|
internal void Clear()
|
||||||
|
{
|
||||||
MessagesMutex.Wait();
|
MessagesMutex.Wait();
|
||||||
Messages.Clear();
|
Messages.Clear();
|
||||||
MessagesMutex.Release();
|
MessagesMutex.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Tab Clone() {
|
internal Tab Clone()
|
||||||
return new Tab {
|
{
|
||||||
|
return new Tab
|
||||||
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
ChatCodes = ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
|
ChatCodes = ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
|
||||||
ExtraChatAll = ExtraChatAll,
|
ExtraChatAll = ExtraChatAll,
|
||||||
@@ -242,14 +257,17 @@ internal class Tab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal enum CommandHelpSide {
|
internal enum CommandHelpSide
|
||||||
|
{
|
||||||
None,
|
None,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class CommandHelpSideExt {
|
internal static class CommandHelpSideExt
|
||||||
internal static string Name(this CommandHelpSide side) => side switch {
|
{
|
||||||
|
internal static string Name(this CommandHelpSide side) => side switch
|
||||||
|
{
|
||||||
CommandHelpSide.None => Language.CommandHelpSide_None,
|
CommandHelpSide.None => Language.CommandHelpSide_None,
|
||||||
CommandHelpSide.Left => Language.CommandHelpSide_Left,
|
CommandHelpSide.Left => Language.CommandHelpSide_Left,
|
||||||
CommandHelpSide.Right => Language.CommandHelpSide_Right,
|
CommandHelpSide.Right => Language.CommandHelpSide_Right,
|
||||||
@@ -258,19 +276,23 @@ internal static class CommandHelpSideExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal enum KeybindMode {
|
internal enum KeybindMode
|
||||||
|
{
|
||||||
Flexible,
|
Flexible,
|
||||||
Strict,
|
Strict,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class KeybindModeExt {
|
internal static class KeybindModeExt
|
||||||
internal static string Name(this KeybindMode mode) => mode switch {
|
{
|
||||||
|
internal static string Name(this KeybindMode mode) => mode switch
|
||||||
|
{
|
||||||
KeybindMode.Flexible => Language.KeybindMode_Flexible_Name,
|
KeybindMode.Flexible => Language.KeybindMode_Flexible_Name,
|
||||||
KeybindMode.Strict => Language.KeybindMode_Strict_Name,
|
KeybindMode.Strict => Language.KeybindMode_Strict_Name,
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static string? Tooltip(this KeybindMode mode) => mode switch {
|
internal static string? Tooltip(this KeybindMode mode) => mode switch
|
||||||
|
{
|
||||||
KeybindMode.Flexible => Language.KeybindMode_Flexible_Tooltip,
|
KeybindMode.Flexible => Language.KeybindMode_Flexible_Tooltip,
|
||||||
KeybindMode.Strict => Language.KeybindMode_Strict_Tooltip,
|
KeybindMode.Strict => Language.KeybindMode_Strict_Tooltip,
|
||||||
_ => null,
|
_ => null,
|
||||||
@@ -278,7 +300,8 @@ internal static class KeybindModeExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal enum LanguageOverride {
|
internal enum LanguageOverride
|
||||||
|
{
|
||||||
None,
|
None,
|
||||||
ChineseSimplified,
|
ChineseSimplified,
|
||||||
ChineseTraditional,
|
ChineseTraditional,
|
||||||
@@ -300,8 +323,10 @@ internal enum LanguageOverride {
|
|||||||
Swedish,
|
Swedish,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class LanguageOverrideExt {
|
internal static class LanguageOverrideExt
|
||||||
internal static string Name(this LanguageOverride mode) => mode switch {
|
{
|
||||||
|
internal static string Name(this LanguageOverride mode) => mode switch
|
||||||
|
{
|
||||||
LanguageOverride.None => Language.LanguageOverride_None,
|
LanguageOverride.None => Language.LanguageOverride_None,
|
||||||
LanguageOverride.ChineseSimplified => "简体中文",
|
LanguageOverride.ChineseSimplified => "简体中文",
|
||||||
LanguageOverride.ChineseTraditional => "繁體中文",
|
LanguageOverride.ChineseTraditional => "繁體中文",
|
||||||
@@ -322,7 +347,8 @@ internal static class LanguageOverrideExt {
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static string Code(this LanguageOverride mode) => mode switch {
|
internal static string Code(this LanguageOverride mode) => mode switch
|
||||||
|
{
|
||||||
LanguageOverride.None => "",
|
LanguageOverride.None => "",
|
||||||
LanguageOverride.ChineseSimplified => "zh-hans",
|
LanguageOverride.ChineseSimplified => "zh-hans",
|
||||||
LanguageOverride.ChineseTraditional => "zh-hant",
|
LanguageOverride.ChineseTraditional => "zh-hant",
|
||||||
@@ -346,7 +372,8 @@ internal static class LanguageOverrideExt {
|
|||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[Flags]
|
[Flags]
|
||||||
internal enum ExtraGlyphRanges {
|
internal enum ExtraGlyphRanges
|
||||||
|
{
|
||||||
ChineseFull = 1 << 0,
|
ChineseFull = 1 << 0,
|
||||||
ChineseSimplifiedCommon = 1 << 1,
|
ChineseSimplifiedCommon = 1 << 1,
|
||||||
Cyrillic = 1 << 2,
|
Cyrillic = 1 << 2,
|
||||||
@@ -356,8 +383,10 @@ internal enum ExtraGlyphRanges {
|
|||||||
Vietnamese = 1 << 6,
|
Vietnamese = 1 << 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class ExtraGlyphRangesExt {
|
internal static class ExtraGlyphRangesExt
|
||||||
internal static string Name(this ExtraGlyphRanges ranges) => ranges switch {
|
{
|
||||||
|
internal static string Name(this ExtraGlyphRanges ranges) => ranges switch
|
||||||
|
{
|
||||||
ExtraGlyphRanges.ChineseFull => Language.ExtraGlyphRanges_ChineseFull_Name,
|
ExtraGlyphRanges.ChineseFull => Language.ExtraGlyphRanges_ChineseFull_Name,
|
||||||
ExtraGlyphRanges.ChineseSimplifiedCommon => Language.ExtraGlyphRanges_ChineseSimplifiedCommon_Name,
|
ExtraGlyphRanges.ChineseSimplifiedCommon => Language.ExtraGlyphRanges_ChineseSimplifiedCommon_Name,
|
||||||
ExtraGlyphRanges.Cyrillic => Language.ExtraGlyphRanges_Cyrillic_Name,
|
ExtraGlyphRanges.Cyrillic => Language.ExtraGlyphRanges_Cyrillic_Name,
|
||||||
@@ -368,7 +397,8 @@ internal static class ExtraGlyphRangesExt {
|
|||||||
_ => throw new ArgumentOutOfRangeException(nameof(ranges), ranges, null),
|
_ => throw new ArgumentOutOfRangeException(nameof(ranges), ranges, null),
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static IntPtr Range(this ExtraGlyphRanges ranges) => ranges switch {
|
internal static IntPtr Range(this ExtraGlyphRanges ranges) => ranges switch
|
||||||
|
{
|
||||||
ExtraGlyphRanges.ChineseFull => ImGui.GetIO().Fonts.GetGlyphRangesChineseFull(),
|
ExtraGlyphRanges.ChineseFull => ImGui.GetIO().Fonts.GetGlyphRangesChineseFull(),
|
||||||
ExtraGlyphRanges.ChineseSimplifiedCommon => ImGui.GetIO().Fonts.GetGlyphRangesChineseSimplifiedCommon(),
|
ExtraGlyphRanges.ChineseSimplifiedCommon => ImGui.GetIO().Fonts.GetGlyphRangesChineseSimplifiedCommon(),
|
||||||
ExtraGlyphRanges.Cyrillic => ImGui.GetIO().Fonts.GetGlyphRangesCyrillic(),
|
ExtraGlyphRanges.Cyrillic => ImGui.GetIO().Fonts.GetGlyphRangesCyrillic(),
|
||||||
|
|||||||
+101
-82
@@ -10,7 +10,8 @@ using Lumina.Excel.GeneratedSheets;
|
|||||||
|
|
||||||
namespace ChatTwo;
|
namespace ChatTwo;
|
||||||
|
|
||||||
internal class Store : IDisposable {
|
internal class Store : IDisposable
|
||||||
|
{
|
||||||
internal const int MessagesLimit = 10_000;
|
internal const int MessagesLimit = 10_000;
|
||||||
|
|
||||||
private Plugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
@@ -23,24 +24,29 @@ internal class Store : IDisposable {
|
|||||||
private Dictionary<ChatType, NameFormatting> Formats { get; } = new();
|
private Dictionary<ChatType, NameFormatting> Formats { get; } = new();
|
||||||
private ulong LastContentId { get; set; }
|
private ulong LastContentId { get; set; }
|
||||||
|
|
||||||
private ulong CurrentContentId {
|
private ulong CurrentContentId
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
var contentId = Plugin.ClientState.LocalContentId;
|
var contentId = Plugin.ClientState.LocalContentId;
|
||||||
return contentId == 0 ? LastContentId : contentId;
|
return contentId == 0 ? LastContentId : contentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Store(Plugin plugin) {
|
internal Store(Plugin plugin)
|
||||||
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
CheckpointTimer.Start();
|
CheckpointTimer.Start();
|
||||||
|
|
||||||
BsonMapper.Global = new BsonMapper {
|
BsonMapper.Global = new BsonMapper
|
||||||
|
{
|
||||||
IncludeNonPublic = true,
|
IncludeNonPublic = true,
|
||||||
TrimWhitespace = false,
|
TrimWhitespace = false,
|
||||||
// EnumAsInteger = true,
|
// EnumAsInteger = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Plugin.Config.DatabaseMigration == 0) {
|
if (Plugin.Config.DatabaseMigration == 0)
|
||||||
|
{
|
||||||
BsonMapper.Global.Entity<Message>()
|
BsonMapper.Global.Entity<Message>()
|
||||||
.Id(msg => msg.Id)
|
.Id(msg => msg.Id)
|
||||||
.Ctor(doc => new Message(
|
.Ctor(doc => new Message(
|
||||||
@@ -55,7 +61,9 @@ internal class Store : IDisposable {
|
|||||||
doc["ContentSource"],
|
doc["ContentSource"],
|
||||||
doc["SortCode"].AsDocument
|
doc["SortCode"].AsDocument
|
||||||
));
|
));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
BsonMapper.Global.Entity<Message>()
|
BsonMapper.Global.Entity<Message>()
|
||||||
.Id(msg => msg.Id)
|
.Id(msg => msg.Id)
|
||||||
.Ctor(doc => new Message(
|
.Ctor(doc => new Message(
|
||||||
@@ -74,8 +82,10 @@ internal class Store : IDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BsonMapper.Global.RegisterType<Payload?>(
|
BsonMapper.Global.RegisterType<Payload?>(
|
||||||
payload => {
|
payload =>
|
||||||
switch (payload) {
|
{
|
||||||
|
switch (payload)
|
||||||
|
{
|
||||||
case AchievementPayload achievement:
|
case AchievementPayload achievement:
|
||||||
return new BsonDocument(new Dictionary<string, BsonValue> {
|
return new BsonDocument(new Dictionary<string, BsonValue> {
|
||||||
["Type"] = new("Achievement"),
|
["Type"] = new("Achievement"),
|
||||||
@@ -95,13 +105,15 @@ internal class Store : IDisposable {
|
|||||||
|
|
||||||
return payload?.Encode();
|
return payload?.Encode();
|
||||||
},
|
},
|
||||||
bson => {
|
bson =>
|
||||||
if (bson.IsNull) {
|
{
|
||||||
|
if (bson.IsNull)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
if (bson.IsDocument) {
|
if (bson.IsDocument)
|
||||||
return bson["Type"].AsString switch {
|
{
|
||||||
|
return bson["Type"].AsString switch
|
||||||
|
{
|
||||||
"Achievement" => new AchievementPayload((uint) bson["Id"].AsInt64),
|
"Achievement" => new AchievementPayload((uint) bson["Id"].AsInt64),
|
||||||
"PartyFinder" => new PartyFinderPayload((uint) bson["Id"].AsInt64),
|
"PartyFinder" => new PartyFinderPayload((uint) bson["Id"].AsInt64),
|
||||||
"URI" => new URIPayload(new Uri(bson["Uri"].AsString)),
|
"URI" => new URIPayload(new Uri(bson["Uri"].AsString)),
|
||||||
@@ -115,10 +127,10 @@ internal class Store : IDisposable {
|
|||||||
seString => seString == null
|
seString => seString == null
|
||||||
? null
|
? null
|
||||||
: new BsonArray(seString.Payloads.Select(payload => new BsonValue(payload.Encode()))),
|
: new BsonArray(seString.Payloads.Select(payload => new BsonValue(payload.Encode()))),
|
||||||
bson => {
|
bson =>
|
||||||
if (bson.IsNull) {
|
{
|
||||||
|
if (bson.IsNull)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
var array = bson.IsArray ? bson.AsArray : bson["Payloads"].AsArray;
|
var array = bson.IsArray ? bson.AsArray : bson["Payloads"].AsArray;
|
||||||
var payloads = array
|
var payloads = array
|
||||||
@@ -167,7 +179,8 @@ internal class Store : IDisposable {
|
|||||||
var dbPath = DatabasePath();
|
var dbPath = DatabasePath();
|
||||||
var connection = Plugin.Config.SharedMode ? "shared" : "direct";
|
var connection = Plugin.Config.SharedMode ? "shared" : "direct";
|
||||||
var connString = $"Filename='{dbPath}';Connection={connection}";
|
var connString = $"Filename='{dbPath}';Connection={connection}";
|
||||||
var conn = new LiteDatabase(connString, BsonMapper.Global) {
|
var conn = new LiteDatabase(connString, BsonMapper.Global)
|
||||||
|
{
|
||||||
CheckpointSize = 1_000,
|
CheckpointSize = 1_000,
|
||||||
Timeout = TimeSpan.FromSeconds(1),
|
Timeout = TimeSpan.FromSeconds(1),
|
||||||
};
|
};
|
||||||
@@ -178,7 +191,8 @@ internal class Store : IDisposable {
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Reconnect() {
|
internal void Reconnect()
|
||||||
|
{
|
||||||
Database.Dispose();
|
Database.Dispose();
|
||||||
Database = Connect();
|
Database = Connect();
|
||||||
}
|
}
|
||||||
@@ -203,168 +217,173 @@ internal class Store : IDisposable {
|
|||||||
|
|
||||||
internal int MessageCount() => Messages.Count();
|
internal int MessageCount() => Messages.Count();
|
||||||
|
|
||||||
private void Logout() {
|
private void Logout()
|
||||||
|
{
|
||||||
LastContentId = 0;
|
LastContentId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateReceiver(IFramework framework) {
|
private void UpdateReceiver(IFramework framework)
|
||||||
|
{
|
||||||
var contentId = Plugin.ClientState.LocalContentId;
|
var contentId = Plugin.ClientState.LocalContentId;
|
||||||
if (contentId != 0) {
|
if (contentId != 0)
|
||||||
LastContentId = contentId;
|
LastContentId = contentId;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void GetMessageInfo(IFramework framework) {
|
private void GetMessageInfo(IFramework framework)
|
||||||
if (CheckpointTimer.Elapsed > TimeSpan.FromMinutes(5)) {
|
{
|
||||||
|
if (CheckpointTimer.Elapsed > TimeSpan.FromMinutes(5))
|
||||||
|
{
|
||||||
CheckpointTimer.Restart();
|
CheckpointTimer.Restart();
|
||||||
new Thread(() => Database.Checkpoint()).Start();
|
new Thread(() => Database.Checkpoint()).Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Pending.TryDequeue(out var entry)) {
|
if (!Pending.TryDequeue(out var entry))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
var contentId = Plugin.Functions.Chat.GetContentIdForEntry(entry.Item1);
|
var contentId = Plugin.Functions.Chat.GetContentIdForEntry(entry.Item1);
|
||||||
entry.Item2.ContentId = contentId ?? 0;
|
entry.Item2.ContentId = contentId ?? 0;
|
||||||
if (Plugin.Config.DatabaseBattleMessages || !entry.Item2.Code.IsBattle()) {
|
if (Plugin.Config.DatabaseBattleMessages || !entry.Item2.Code.IsBattle())
|
||||||
Messages.Update(entry.Item2);
|
Messages.Update(entry.Item2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void AddMessage(Message message, Tab? currentTab) {
|
internal void AddMessage(Message message, Tab? currentTab)
|
||||||
if (Plugin.Config.DatabaseBattleMessages || !message.Code.IsBattle()) {
|
{
|
||||||
|
if (Plugin.Config.DatabaseBattleMessages || !message.Code.IsBattle())
|
||||||
Messages.Insert(message);
|
Messages.Insert(message);
|
||||||
}
|
|
||||||
|
|
||||||
var currentMatches = currentTab?.Matches(message) ?? false;
|
var currentMatches = currentTab?.Matches(message) ?? false;
|
||||||
|
|
||||||
foreach (var tab in Plugin.Config.Tabs) {
|
foreach (var tab in Plugin.Config.Tabs)
|
||||||
|
{
|
||||||
var unread = !(tab.UnreadMode == UnreadMode.Unseen && currentTab != tab && currentMatches);
|
var unread = !(tab.UnreadMode == UnreadMode.Unseen && currentTab != tab && currentMatches);
|
||||||
|
|
||||||
if (tab.Matches(message)) {
|
if (tab.Matches(message))
|
||||||
tab.AddMessage(message, unread);
|
tab.AddMessage(message, unread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void FilterAllTabs(bool unread = true) {
|
internal void FilterAllTabs(bool unread = true)
|
||||||
foreach (var tab in Plugin.Config.Tabs) {
|
{
|
||||||
|
foreach (var tab in Plugin.Config.Tabs)
|
||||||
FilterTab(tab, unread);
|
FilterTab(tab, unread);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void FilterTab(Tab tab, bool unread) {
|
internal void FilterTab(Tab tab, bool unread)
|
||||||
|
{
|
||||||
var sortCodes = new List<SortCode>();
|
var sortCodes = new List<SortCode>();
|
||||||
foreach (var (type, sources) in tab.ChatCodes) {
|
foreach (var (type, sources) in tab.ChatCodes)
|
||||||
|
{
|
||||||
sortCodes.Add(new SortCode(type, 0));
|
sortCodes.Add(new SortCode(type, 0));
|
||||||
sortCodes.Add(new SortCode(type, (ChatSource) 1));
|
sortCodes.Add(new SortCode(type, (ChatSource) 1));
|
||||||
|
|
||||||
if (type.HasSource()) {
|
if (!type.HasSource())
|
||||||
foreach (var source in Enum.GetValues<ChatSource>()) {
|
continue;
|
||||||
if (sources.HasFlag(source)) {
|
|
||||||
|
foreach (var source in Enum.GetValues<ChatSource>())
|
||||||
|
if (sources.HasFlag(source))
|
||||||
sortCodes.Add(new SortCode(type, source));
|
sortCodes.Add(new SortCode(type, source));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var query = Messages
|
var query = Messages
|
||||||
.Query()
|
.Query()
|
||||||
.OrderByDescending(msg => msg.Date)
|
.OrderByDescending(msg => msg.Date)
|
||||||
.Where(msg => sortCodes.Contains(msg.SortCode) || msg.ExtraChatChannel != Guid.Empty)
|
.Where(msg => sortCodes.Contains(msg.SortCode) || msg.ExtraChatChannel != Guid.Empty)
|
||||||
.Where(msg => msg.Receiver == CurrentContentId);
|
.Where(msg => msg.Receiver == CurrentContentId);
|
||||||
if (!Plugin.Config.FilterIncludePreviousSessions) {
|
|
||||||
query = query.Where(msg => msg.Date >= Plugin.GameStarted);
|
|
||||||
}
|
|
||||||
|
|
||||||
var messages = query
|
if (!Plugin.Config.FilterIncludePreviousSessions)
|
||||||
.Limit(MessagesLimit)
|
query = query.Where(msg => msg.Date >= Plugin.GameStarted);
|
||||||
.ToEnumerable()
|
|
||||||
.Reverse();
|
var messages = query.Limit(MessagesLimit).ToEnumerable().Reverse();
|
||||||
foreach (var message in messages) {
|
|
||||||
|
foreach (var message in messages)
|
||||||
|
{
|
||||||
|
// check primarily for startup double posting messages
|
||||||
|
if (tab.Contains(message))
|
||||||
|
continue;
|
||||||
|
|
||||||
// redundant matches check for extrachat
|
// redundant matches check for extrachat
|
||||||
if (tab.Matches(message)) {
|
if (tab.Matches(message))
|
||||||
tab.AddMessage(message, unread);
|
tab.AddMessage(message, unread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public (SeString? Sender, SeString? Message) LastMessage = (null, null);
|
public (SeString? Sender, SeString? Message) LastMessage = (null, null);
|
||||||
private void ChatMessage(XivChatType type, uint senderId, SeString sender, SeString message) {
|
private void ChatMessage(XivChatType type, uint senderId, SeString sender, SeString message)
|
||||||
|
{
|
||||||
var chatCode = new ChatCode((ushort) type);
|
var chatCode = new ChatCode((ushort) type);
|
||||||
|
|
||||||
NameFormatting? formatting = null;
|
NameFormatting? formatting = null;
|
||||||
if (sender.Payloads.Count > 0) {
|
if (sender.Payloads.Count > 0)
|
||||||
formatting = FormatFor(chatCode.Type);
|
formatting = FormatFor(chatCode.Type);
|
||||||
}
|
|
||||||
|
|
||||||
LastMessage = (sender, message);
|
LastMessage = (sender, message);
|
||||||
var senderChunks = new List<Chunk>();
|
var senderChunks = new List<Chunk>();
|
||||||
if (formatting is { IsPresent: true }) {
|
if (formatting is { IsPresent: true })
|
||||||
senderChunks.Add(new TextChunk(ChunkSource.None, null, formatting.Before) {
|
{
|
||||||
|
senderChunks.Add(new TextChunk(ChunkSource.None, null, formatting.Before)
|
||||||
|
{
|
||||||
FallbackColour = chatCode.Type,
|
FallbackColour = chatCode.Type,
|
||||||
});
|
});
|
||||||
senderChunks.AddRange(ChunkUtil.ToChunks(sender, ChunkSource.Sender, chatCode.Type));
|
senderChunks.AddRange(ChunkUtil.ToChunks(sender, ChunkSource.Sender, chatCode.Type));
|
||||||
senderChunks.Add(new TextChunk(ChunkSource.None, null, formatting.After) {
|
senderChunks.Add(new TextChunk(ChunkSource.None, null, formatting.After)
|
||||||
|
{
|
||||||
FallbackColour = chatCode.Type,
|
FallbackColour = chatCode.Type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var messageChunks = ChunkUtil.ToChunks(message, ChunkSource.Content, chatCode.Type).ToList();
|
var messageChunks = ChunkUtil.ToChunks(message, ChunkSource.Content, chatCode.Type).ToList();
|
||||||
|
|
||||||
|
Plugin.Log.Information($"Adding Message with code {chatCode} timestamp {senderId} content {message.TextValue}");
|
||||||
var msg = new Message(CurrentContentId, chatCode, senderChunks, messageChunks, sender, message);
|
var msg = new Message(CurrentContentId, chatCode, senderChunks, messageChunks, sender, message);
|
||||||
AddMessage(msg, Plugin.ChatLogWindow.CurrentTab ?? null);
|
AddMessage(msg, Plugin.ChatLogWindow.CurrentTab ?? null);
|
||||||
|
|
||||||
var idx = Plugin.Functions.GetCurrentChatLogEntryIndex();
|
var idx = Plugin.Functions.GetCurrentChatLogEntryIndex();
|
||||||
if (idx != null) {
|
if (idx != null)
|
||||||
Pending.Enqueue((idx.Value - 1, msg));
|
Pending.Enqueue((idx.Value - 1, msg));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal class NameFormatting {
|
internal class NameFormatting
|
||||||
|
{
|
||||||
internal string Before { get; private set; } = string.Empty;
|
internal string Before { get; private set; } = string.Empty;
|
||||||
internal string After { get; private set; } = string.Empty;
|
internal string After { get; private set; } = string.Empty;
|
||||||
internal bool IsPresent { get; private set; } = true;
|
internal bool IsPresent { get; private set; } = true;
|
||||||
|
|
||||||
internal static NameFormatting Empty() {
|
internal static NameFormatting Empty()
|
||||||
return new() {
|
{
|
||||||
IsPresent = false,
|
return new NameFormatting { IsPresent = false, };
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static NameFormatting Of(string before, string after) {
|
internal static NameFormatting Of(string before, string after)
|
||||||
return new() {
|
{
|
||||||
|
return new NameFormatting
|
||||||
|
{
|
||||||
Before = before,
|
Before = before,
|
||||||
After = after,
|
After = after,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NameFormatting? FormatFor(ChatType type) {
|
private NameFormatting? FormatFor(ChatType type)
|
||||||
if (Formats.TryGetValue(type, out var cached)) {
|
{
|
||||||
|
if (Formats.TryGetValue(type, out var cached))
|
||||||
return cached;
|
return cached;
|
||||||
}
|
|
||||||
|
|
||||||
var logKind = Plugin.DataManager.GetExcelSheet<LogKind>()!.GetRow((ushort) type);
|
var logKind = Plugin.DataManager.GetExcelSheet<LogKind>()!.GetRow((ushort) type);
|
||||||
|
if (logKind == null)
|
||||||
if (logKind == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
var format = (SeString) logKind.Format;
|
var format = (SeString) logKind.Format;
|
||||||
|
static bool IsStringParam(Payload payload, byte num)
|
||||||
static bool IsStringParam(Payload payload, byte num) {
|
{
|
||||||
var data = payload.Encode();
|
var data = payload.Encode();
|
||||||
|
|
||||||
return data.Length >= 5 && data[1] == 0x29 && data[4] == num + 1;
|
return data.Length >= 5 && data[1] == 0x29 && data[4] == num + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstStringParam = format.Payloads.FindIndex(payload => IsStringParam(payload, 1));
|
var firstStringParam = format.Payloads.FindIndex(payload => IsStringParam(payload, 1));
|
||||||
var secondStringParam = format.Payloads.FindIndex(payload => IsStringParam(payload, 2));
|
var secondStringParam = format.Payloads.FindIndex(payload => IsStringParam(payload, 2));
|
||||||
|
|
||||||
if (firstStringParam == -1 || secondStringParam == -1) {
|
if (firstStringParam == -1 || secondStringParam == -1)
|
||||||
return NameFormatting.Empty();
|
return NameFormatting.Empty();
|
||||||
}
|
|
||||||
|
|
||||||
var before = format.Payloads
|
var before = format.Payloads
|
||||||
.GetRange(0, firstStringParam)
|
.GetRange(0, firstStringParam)
|
||||||
|
|||||||
Reference in New Issue
Block a user