Locationshare fix

This commit is contained in:
Tsubasahane
2025-12-29 15:42:55 +08:00
parent 9f5cc9e0d1
commit 18fa0a47b1
4 changed files with 26 additions and 15 deletions

View File

@@ -126,6 +126,13 @@ namespace LightlessSync.Services
throw;
}
}
public void UpdateSharingStatus(List<string> users, DateTimeOffset expireAt)
{
foreach (var user in users)
{
AddStatus(user, expireAt);
}
}
}
}

View File

@@ -251,9 +251,13 @@ public class DrawUserPair
}
}
private Task ToggleLocationSharing(List<string> users, DateTimeOffset expireAt)
private async Task ToggleLocationSharing(List<string> 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

View File

@@ -211,10 +211,10 @@ public partial class ApiController
if (!IsConnected) return ([],[]);
return await _lightlessHub!.InvokeAsync<(List<LocationWithTimeDto>, List<SharingStatusDto>)>(nameof(RequestAllLocationInfo)).ConfigureAwait(false);
}
public async Task ToggleLocationSharing(LocationSharingToggleDto dto)
public async Task<bool> ToggleLocationSharing(LocationSharingToggleDto dto)
{
if (!IsConnected) return;
await _lightlessHub!.SendAsync(nameof(ToggleLocationSharing), dto).ConfigureAwait(false);
if (!IsConnected) return false;
return await _lightlessHub!.InvokeAsync<bool>(nameof(ToggleLocationSharing), dto).ConfigureAwait(false);
}
}
#pragma warning restore MA0040