From 3a627f2d3edb790a0319ff2438170a0f849dd973 Mon Sep 17 00:00:00 2001 From: CakeAndBanana Date: Wed, 1 Oct 2025 04:11:01 +0200 Subject: [PATCH] Added refetch of syncshells after comfirmation. --- LightlessSync/UI/SyncshellFinderUI.cs | 61 +++++++++++++++------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/LightlessSync/UI/SyncshellFinderUI.cs b/LightlessSync/UI/SyncshellFinderUI.cs index 4af72d5..c5dc2d2 100644 --- a/LightlessSync/UI/SyncshellFinderUI.cs +++ b/LightlessSync/UI/SyncshellFinderUI.cs @@ -103,6 +103,14 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase return; } + DrawSyncshellTable(); + + if (_joinDto != null && _joinInfo != null && _joinInfo.Success) + DrawConfirmation(); + } + + private void DrawSyncshellTable() + { if (ImGui.BeginTable("##NearbySyncshellsTable", 3, ImGuiTableFlags.Borders | ImGuiTableFlags.RowBg)) { ImGui.TableSetupColumn("Syncshell", ImGuiTableColumnFlags.WidthStretch); @@ -122,18 +130,18 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase var broadcasterName = "Unknown"; var broadcast = _broadcastScannerService.GetActiveSyncshellBroadcasts() .FirstOrDefault(b => string.Equals(b.GID, shell.Group.GID, StringComparison.Ordinal)); - + if (broadcast != null) { - var playerInfo = _dalamudUtilService.FindPlayerByNameHash(broadcast.HashedCID); - if (!string.IsNullOrEmpty(playerInfo.Name)) + var (Name, Address) = _dalamudUtilService.FindPlayerByNameHash(broadcast.HashedCID); + if (!string.IsNullOrEmpty(Name)) { - var worldName = _dalamudUtilService.GetWorldNameFromPlayerAddress(playerInfo.Address); - broadcasterName = !string.IsNullOrEmpty(worldName) ? $"{playerInfo.Name} ({worldName})" : playerInfo.Name; + var worldName = _dalamudUtilService.GetWorldNameFromPlayerAddress(Address); + broadcasterName = !string.IsNullOrEmpty(worldName) ? $"{Name} ({worldName})" : Name; } } ImGui.TextUnformatted(broadcasterName); - + ImGui.TableNextColumn(); var label = $"Join##{shell.Group.GID}"; @@ -179,7 +187,6 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase } else { - using (ImRaii.Disabled()) { ImGui.Button(label); @@ -191,9 +198,6 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase ImGui.EndTable(); } - - if (_joinDto != null && _joinInfo != null && _joinInfo.Success) - DrawConfirmation(); } private void DrawConfirmation() @@ -222,6 +226,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase _ = _apiController.GroupJoinFinalize(new GroupJoinDto(_joinDto.Group, _joinDto.Password, finalPermissions)); _joinDto = null; _joinInfo = null; + _ = RefreshSyncshellsAsync(); } } } @@ -255,7 +260,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase private async Task RefreshSyncshellsAsync() { var syncshellBroadcasts = _broadcastScannerService.GetActiveSyncshellBroadcasts(); - _currentSyncshells = _pairManager.GroupPairs.Select(g => g.Key).ToList(); + _currentSyncshells = [.. _pairManager.GroupPairs.Select(g => g.Key)]; if (syncshellBroadcasts.Count == 0) { @@ -263,7 +268,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase return; } - List updatedList = []; + List? updatedList = []; try { var groups = await _apiController.GetBroadcastedGroups(syncshellBroadcasts).ConfigureAwait(false); @@ -276,23 +281,27 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase } var currentGids = _nearbySyncshells.Select(s => s.Group.GID).ToHashSet(StringComparer.Ordinal); - var newGids = updatedList.Select(s => s.Group.GID).ToHashSet(StringComparer.Ordinal); - if (currentGids.SetEquals(newGids)) - return; - - var previousGid = GetSelectedGid(); - - _nearbySyncshells.Clear(); - _nearbySyncshells.AddRange(updatedList); - - if (previousGid != null) + if (updatedList != null) { - var newIndex = _nearbySyncshells.FindIndex(s => string.Equals(s.Group.GID, previousGid, StringComparison.Ordinal)); - if (newIndex >= 0) - { - _selectedNearbyIndex = newIndex; + var newGids = updatedList.Select(s => s.Group.GID).ToHashSet(StringComparer.Ordinal); + + if (currentGids.SetEquals(newGids)) return; + + var previousGid = GetSelectedGid(); + + _nearbySyncshells.Clear(); + _nearbySyncshells.AddRange(updatedList); + + if (previousGid != null) + { + var newIndex = _nearbySyncshells.FindIndex(s => string.Equals(s.Group.GID, previousGid, StringComparison.Ordinal)); + if (newIndex >= 0) + { + _selectedNearbyIndex = newIndex; + return; + } } }