From 18fa0a47b1fff1493976fdf3007279a7af858eff Mon Sep 17 00:00:00 2001 From: Tsubasahane Date: Mon, 29 Dec 2025 15:42:55 +0800 Subject: [PATCH] Locationshare fix --- LightlessAPI | 2 +- .../Services/LocationShareService.cs | 9 ++++++- LightlessSync/UI/Components/DrawUserPair.cs | 24 +++++++++++-------- .../SignalR/ApIController.Functions.Users.cs | 6 ++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/LightlessAPI b/LightlessAPI index 852e2a0..c3caa7e 160000 --- a/LightlessAPI +++ b/LightlessAPI @@ -1 +1 @@ -Subproject commit 852e2a005f5bfdf3844e057c6ba71de6f5f84ed8 +Subproject commit c3caa7e25cf17fd52c4765bf051ec37c8fd92082 diff --git a/LightlessSync/Services/LocationShareService.cs b/LightlessSync/Services/LocationShareService.cs index 71989e5..77b5c90 100644 --- a/LightlessSync/Services/LocationShareService.cs +++ b/LightlessSync/Services/LocationShareService.cs @@ -126,6 +126,13 @@ namespace LightlessSync.Services throw; } } - + + public void UpdateSharingStatus(List users, DateTimeOffset expireAt) + { + foreach (var user in users) + { + AddStatus(user, expireAt); + } + } } } \ No newline at end of file diff --git a/LightlessSync/UI/Components/DrawUserPair.cs b/LightlessSync/UI/Components/DrawUserPair.cs index b8e58c4..3bd9fc0 100644 --- a/LightlessSync/UI/Components/DrawUserPair.cs +++ b/LightlessSync/UI/Components/DrawUserPair.cs @@ -251,9 +251,13 @@ public class DrawUserPair } } - private Task ToggleLocationSharing(List users, DateTimeOffset expireAt) + private async Task ToggleLocationSharing(List users, DateTimeOffset expireAt) { - return _apiController.ToggleLocationSharing(new LocationSharingToggleDto(users, expireAt)); + var updated = await _apiController.ToggleLocationSharing(new LocationSharingToggleDto(users, expireAt)).ConfigureAwait(false); + if (updated) + { + _locationShareService.UpdateSharingStatus(users, expireAt); + } } private void DrawIndividualMenu() @@ -617,25 +621,25 @@ public class DrawUserPair var location = _locationShareService.GetUserLocation(_pair.UserPair!.User.UID); var shareLocation = !string.IsNullOrEmpty(location); var expireAt = _locationShareService.GetSharingStatus(_pair.UserPair!.User.UID); - var shareLocationOther = expireAt > DateTimeOffset.UtcNow; + var shareLocationToOther = expireAt > DateTimeOffset.UtcNow; var shareColor = shareLocation switch { - true when shareLocationOther => UIColors.Get("LightlessGreen"), - false when shareLocationOther => UIColors.Get("LightlessBlue"), + true when shareLocationToOther => UIColors.Get("LightlessGreen"), + true when !shareLocationToOther => UIColors.Get("LightlessBlue"), _ => UIColors.Get("LightlessYellow"), }; - if (shareLocation || shareLocationOther) + if (shareLocation || shareLocationToOther) { currentRightSide -= (_uiSharedService.GetIconSize(shareLocationIcon).X + spacingX); ImGui.SameLine(currentRightSide); - using (ImRaii.PushColor(ImGuiCol.Text, shareColor, shareLocation || shareLocationOther)) + using (ImRaii.PushColor(ImGuiCol.Text, shareColor, shareLocation || shareLocationToOther)) _uiSharedService.IconText(shareLocationIcon); if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); - if (shareLocationOther) + if (shareLocation) { if (_pair.IsOnline) { @@ -661,12 +665,12 @@ public class DrawUserPair } ImGui.Separator(); - if (shareLocation) + if (shareLocationToOther) { ImGui.TextUnformatted("Sharing your location.ヾ(•ω•`)o"); if (expireAt != DateTimeOffset.MaxValue) { - ImGui.TextUnformatted("Expired at " + expireAt.ToLocalTime().ToString("g")); + ImGui.TextUnformatted("Expires at " + expireAt.ToLocalTime().ToString("g")); } } else diff --git a/LightlessSync/WebAPI/SignalR/ApIController.Functions.Users.cs b/LightlessSync/WebAPI/SignalR/ApIController.Functions.Users.cs index fca42f3..37b91f9 100644 --- a/LightlessSync/WebAPI/SignalR/ApIController.Functions.Users.cs +++ b/LightlessSync/WebAPI/SignalR/ApIController.Functions.Users.cs @@ -211,10 +211,10 @@ public partial class ApiController if (!IsConnected) return ([],[]); return await _lightlessHub!.InvokeAsync<(List, List)>(nameof(RequestAllLocationInfo)).ConfigureAwait(false); } - public async Task ToggleLocationSharing(LocationSharingToggleDto dto) + public async Task ToggleLocationSharing(LocationSharingToggleDto dto) { - if (!IsConnected) return; - await _lightlessHub!.SendAsync(nameof(ToggleLocationSharing), dto).ConfigureAwait(false); + if (!IsConnected) return false; + return await _lightlessHub!.InvokeAsync(nameof(ToggleLocationSharing), dto).ConfigureAwait(false); } } #pragma warning restore MA0040 \ No newline at end of file