ToggleLocationSharing returns bool

This commit is contained in:
Tsubasahane
2025-12-29 15:35:54 +08:00
parent c3e87eb7df
commit 53e089a65b
2 changed files with 20 additions and 9 deletions

View File

@@ -1322,16 +1322,27 @@ public partial class LightlessHub
[Authorize(Policy = "Identified")]
public async Task ToggleLocationSharing(LocationSharingToggleDto dto)
public async Task<bool> ToggleLocationSharing(LocationSharingToggleDto dto)
{
_logger.LogCallInfo(LightlessHubLogger.Args(UserUID,dto));
await DbContext.Permissions.Where(x => x.UserUID == UserUID && dto.users.Contains(x.OtherUserUID))
.ExecuteUpdateAsync(setter =>
setter.SetProperty(x => x.ShareLocationUntil, dto.duration.ToUniversalTime()), cancellationToken: RequestAbortedToken).ConfigureAwait(false);
try
{
await DbContext.Permissions.Where(x => x.UserUID == UserUID && dto.users.Contains(x.OtherUserUID))
.ExecuteUpdateAsync(setter =>
setter.SetProperty(x => x.ShareLocationUntil, dto.duration.ToUniversalTime()),
cancellationToken: RequestAbortedToken).ConfigureAwait(false);
//update user's location for target users
var currentLocation = await _redis.GetAsync<LocationDto>($"Location:{UserUID}").ConfigureAwait(false);
await Clients.Users(dto.users).Client_SendLocationToClient(currentLocation, dto.duration.ToUniversalTime()).ConfigureAwait(false);
//update user's location for target users
var currentLocation = await _redis.GetAsync<LocationDto>($"Location:{UserUID}").ConfigureAwait(false);
await Clients.Users(dto.users).Client_SendLocationToClient(currentLocation, dto.duration.ToUniversalTime())
.ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "ToggleLocationSharing error:");
return false;
}
return true;
}
[GeneratedRegex(@"^([a-z0-9_ '+&,\.\-\{\}]+\/)+([a-z0-9_ '+&,\.\-\{\}]+\.[a-z]{3,4})$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ECMAScript)]