implement editorconfig
This commit is contained in:
@@ -4,3 +4,12 @@ tab_width = 4
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
|
# JetBrains Rider custom properties for code formatting styles
|
||||||
|
resharper_csharp_brace_style=next_line
|
||||||
|
|
||||||
|
resharper_braces_for_ifelse=not_required
|
||||||
|
resharper_csharp_braces_for_foreach=not_required
|
||||||
|
resharper_csharp_braces_for_for=not_required
|
||||||
|
resharper_csharp_braces_for_using=not_required
|
||||||
|
resharper_csharp_braces_for_while=not_required
|
||||||
+51
-29
@@ -11,7 +11,8 @@ using Lumina.Excel.GeneratedSheets;
|
|||||||
|
|
||||||
namespace ChatTwo;
|
namespace ChatTwo;
|
||||||
|
|
||||||
internal class MessageManager : IDisposable {
|
internal class MessageManager : IDisposable
|
||||||
|
{
|
||||||
internal const int MessageDisplayLimit = 10_000;
|
internal const int MessageDisplayLimit = 10_000;
|
||||||
|
|
||||||
private Plugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
@@ -22,14 +23,17 @@ internal class MessageManager : 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; }
|
||||||
|
|
||||||
internal ulong CurrentContentId {
|
internal 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 MessageManager(Plugin plugin) {
|
internal MessageManager(Plugin plugin)
|
||||||
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
MaintenanceTimer.Start();
|
MaintenanceTimer.Start();
|
||||||
Store = new MessageStore(DatabasePath());
|
Store = new MessageStore(DatabasePath());
|
||||||
@@ -40,7 +44,8 @@ internal class MessageManager : IDisposable {
|
|||||||
Plugin.ClientState.Logout += Logout;
|
Plugin.ClientState.Logout += Logout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose()
|
||||||
|
{
|
||||||
Plugin.ClientState.Logout -= Logout;
|
Plugin.ClientState.Logout -= Logout;
|
||||||
Plugin.Framework.Update -= UpdateReceiver;
|
Plugin.Framework.Update -= UpdateReceiver;
|
||||||
Plugin.Framework.Update -= GetMessageInfo;
|
Plugin.Framework.Update -= GetMessageInfo;
|
||||||
@@ -49,24 +54,29 @@ internal class MessageManager : IDisposable {
|
|||||||
Store.Dispose();
|
Store.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string DatabasePath() {
|
internal static string DatabasePath()
|
||||||
|
{
|
||||||
var dir = Plugin.Interface.ConfigDirectory;
|
var dir = Plugin.Interface.ConfigDirectory;
|
||||||
dir.Create();
|
dir.Create();
|
||||||
return Path.Join(dir.FullName, "chat-sqlite.db");
|
return Path.Join(dir.FullName, "chat-sqlite.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (MaintenanceTimer.Elapsed > TimeSpan.FromMinutes(5)) {
|
{
|
||||||
|
if (MaintenanceTimer.Elapsed > TimeSpan.FromMinutes(5))
|
||||||
|
{
|
||||||
MaintenanceTimer.Restart();
|
MaintenanceTimer.Restart();
|
||||||
new Thread(() => Store.PerformMaintenance()).Start();
|
new Thread(() => Store.PerformMaintenance()).Start();
|
||||||
}
|
}
|
||||||
@@ -80,13 +90,15 @@ internal class MessageManager : IDisposable {
|
|||||||
Store.UpsertMessage(entry.Item2);
|
Store.UpsertMessage(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())
|
||||||
Store.UpsertMessage(message);
|
Store.UpsertMessage(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))
|
||||||
@@ -94,25 +106,26 @@ internal class MessageManager : IDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void FilterAllTabs(bool unread = true) {
|
internal void FilterAllTabs(bool unread = true)
|
||||||
|
{
|
||||||
DateTimeOffset? since = null;
|
DateTimeOffset? since = null;
|
||||||
if (!Plugin.Config.FilterIncludePreviousSessions)
|
if (!Plugin.Config.FilterIncludePreviousSessions)
|
||||||
since = Plugin.GameStarted;
|
since = Plugin.GameStarted;
|
||||||
|
|
||||||
var messages = Store.GetMostRecentMessages(CurrentContentId, since);
|
var messages = Store.GetMostRecentMessages(CurrentContentId, since);
|
||||||
foreach (var message in messages) {
|
foreach (var message in messages)
|
||||||
foreach (var tab in Plugin.Config.Tabs.Where(tab => tab.Matches(message))) {
|
foreach (var tab in Plugin.Config.Tabs.Where(tab => tab.Matches(message)))
|
||||||
tab.AddMessage(message, unread);
|
tab.AddMessage(message, unread);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messages.DidError)
|
if (messages.DidError)
|
||||||
WrapperUtil.AddNotification(Language.LoadMessages_Error, NotificationType.Error);
|
WrapperUtil.AddNotification(Language.LoadMessages_Error, NotificationType.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
var chatCode = new ChatCode((ushort) type);
|
private void ChatMessage(XivChatType type, uint senderId, SeString sender, SeString message)
|
||||||
|
{
|
||||||
|
var chatCode = new ChatCode((ushort)type);
|
||||||
|
|
||||||
NameFormatting? formatting = null;
|
NameFormatting? formatting = null;
|
||||||
if (sender.Payloads.Count > 0)
|
if (sender.Payloads.Count > 0)
|
||||||
@@ -120,12 +133,15 @@ internal class MessageManager : IDisposable {
|
|||||||
|
|
||||||
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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -140,16 +156,19 @@ internal class MessageManager : IDisposable {
|
|||||||
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 NameFormatting { 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 NameFormatting
|
return new NameFormatting
|
||||||
{
|
{
|
||||||
Before = before,
|
Before = before,
|
||||||
@@ -158,16 +177,19 @@ internal class MessageManager : IDisposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user