hopefully it's fine now?
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using LightlessSync.API.Dto.Chat;
|
||||
using LightlessSync.API.Data.Extensions;
|
||||
using LightlessSync.Services.ActorTracking;
|
||||
using LightlessSync.Services.Mediator;
|
||||
using LightlessSync.WebAPI;
|
||||
@@ -36,6 +37,8 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
private readonly Dictionary<string, bool> _lastPresenceStates = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, string> _selfTokens = new(StringComparer.Ordinal);
|
||||
private readonly List<PendingSelfMessage> _pendingSelfMessages = new();
|
||||
private List<ChatChannelSnapshot>? _cachedChannelSnapshots;
|
||||
private bool _channelsSnapshotDirty = true;
|
||||
|
||||
private bool _isLoggedIn;
|
||||
private bool _isConnected;
|
||||
@@ -69,6 +72,11 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
{
|
||||
using (_sync.EnterScope())
|
||||
{
|
||||
if (!_channelsSnapshotDirty && _cachedChannelSnapshots is not null)
|
||||
{
|
||||
return _cachedChannelSnapshots;
|
||||
}
|
||||
|
||||
var snapshots = new List<ChatChannelSnapshot>(_channelOrder.Count);
|
||||
foreach (var key in _channelOrder)
|
||||
{
|
||||
@@ -98,6 +106,8 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
state.Messages.ToList()));
|
||||
}
|
||||
|
||||
_cachedChannelSnapshots = snapshots;
|
||||
_channelsSnapshotDirty = false;
|
||||
return snapshots;
|
||||
}
|
||||
}
|
||||
@@ -135,6 +145,8 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
state.UnreadCount = 0;
|
||||
_lastReadCounts[key] = state.Messages.Count;
|
||||
}
|
||||
|
||||
MarkChannelsSnapshotDirtyLocked();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +198,7 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
if (!wasEnabled)
|
||||
{
|
||||
_chatEnabled = true;
|
||||
MarkChannelsSnapshotDirtyLocked();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,6 +244,8 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
state.IsAvailable = false;
|
||||
state.StatusText = "Chat services disabled";
|
||||
}
|
||||
|
||||
MarkChannelsSnapshotDirtyLocked();
|
||||
}
|
||||
|
||||
UnregisterChatHandler();
|
||||
@@ -717,7 +732,7 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
_zoneDefinitions[key] = new ZoneChannelDefinition(key, info.DisplayName ?? key, descriptor, territories);
|
||||
}
|
||||
|
||||
var territoryData = _dalamudUtilService.TerritoryData.Value;
|
||||
var territoryData = _dalamudUtilService.TerritoryDataEnglish.Value;
|
||||
foreach (var kvp in territoryData)
|
||||
{
|
||||
foreach (var variant in EnumerateTerritoryKeys(kvp.Value))
|
||||
@@ -853,6 +868,12 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
var infos = new List<GroupChatChannelInfoDto>(groups.Count);
|
||||
foreach (var group in groups)
|
||||
{
|
||||
// basically prune the channel if it's disabled
|
||||
if (group.GroupPermissions.IsDisableChat())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var descriptor = new ChatChannelDescriptor
|
||||
{
|
||||
Type = ChatChannelType.Group,
|
||||
@@ -1023,6 +1044,8 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
state.UnreadCount = Math.Min(Math.Max(unreadFromHistory, incrementalUnread), MaxUnreadCount);
|
||||
state.HasUnread = state.UnreadCount > 0;
|
||||
}
|
||||
|
||||
MarkChannelsSnapshotDirtyLocked();
|
||||
}
|
||||
|
||||
Mediator.Publish(new ChatChannelMessageAdded(key, message));
|
||||
@@ -1204,9 +1227,25 @@ public sealed class ZoneChatService : DisposableMediatorSubscriberBase, IHostedS
|
||||
{
|
||||
_activeChannelKey = _channelOrder.Count > 0 ? _channelOrder[0] : null;
|
||||
}
|
||||
|
||||
MarkChannelsSnapshotDirtyLocked();
|
||||
}
|
||||
|
||||
private void PublishChannelListChanged() => Mediator.Publish(new ChatChannelsUpdated());
|
||||
private void MarkChannelsSnapshotDirty()
|
||||
{
|
||||
using (_sync.EnterScope())
|
||||
{
|
||||
_channelsSnapshotDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void MarkChannelsSnapshotDirtyLocked() => _channelsSnapshotDirty = true;
|
||||
|
||||
private void PublishChannelListChanged()
|
||||
{
|
||||
MarkChannelsSnapshotDirty();
|
||||
Mediator.Publish(new ChatChannelsUpdated());
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateTerritoryKeys(string? value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user