check for alias on addition

This commit is contained in:
Stanley Dimant
2022-08-25 01:05:31 +02:00
parent 4e98a494e0
commit d656513f47

View File

@@ -177,11 +177,11 @@ namespace MareSynchronosServer.Hubs
var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false); var user = await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId).ConfigureAwait(false);
var otherUser = await _dbContext.Users var otherUser = await _dbContext.Users
.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false); .SingleOrDefaultAsync(u => u.UID == uid || u.Alias == uid).ConfigureAwait(false);
var existingEntry = var existingEntry =
await _dbContext.ClientPairs.AsNoTracking() await _dbContext.ClientPairs.AsNoTracking()
.FirstOrDefaultAsync(p => .FirstOrDefaultAsync(p =>
p.User.UID == AuthenticatedUserId && p.OtherUser.UID == uid).ConfigureAwait(false); p.User.UID == AuthenticatedUserId && p.OtherUser.UID == otherUser.UID).ConfigureAwait(false);
if (otherUser == null || existingEntry != null) return; if (otherUser == null || existingEntry != null) return;
_logger.LogInformation("User {AuthenticatedUserId} adding {uid} to whitelist", AuthenticatedUserId, uid); _logger.LogInformation("User {AuthenticatedUserId} adding {uid} to whitelist", AuthenticatedUserId, uid);
ClientPair wl = new ClientPair() ClientPair wl = new ClientPair()
@@ -192,10 +192,11 @@ namespace MareSynchronosServer.Hubs
}; };
await _dbContext.ClientPairs.AddAsync(wl).ConfigureAwait(false); await _dbContext.ClientPairs.AddAsync(wl).ConfigureAwait(false);
await _dbContext.SaveChangesAsync().ConfigureAwait(false); await _dbContext.SaveChangesAsync().ConfigureAwait(false);
var otherEntry = OppositeEntry(uid); var otherEntry = OppositeEntry(otherUser.UID);
await Clients.User(user.UID) await Clients.User(user.UID)
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto() .SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
{ {
VanityUID = otherUser.Alias,
OtherUID = otherUser.UID, OtherUID = otherUser.UID,
IsPaused = false, IsPaused = false,
IsPausedFromOthers = otherEntry?.IsPaused ?? false, IsPausedFromOthers = otherEntry?.IsPaused ?? false,
@@ -203,9 +204,10 @@ namespace MareSynchronosServer.Hubs
}, string.Empty).ConfigureAwait(false); }, string.Empty).ConfigureAwait(false);
if (otherEntry != null) if (otherEntry != null)
{ {
await Clients.User(uid).SendAsync(Api.OnUserUpdateClientPairs, await Clients.User(otherUser.UID).SendAsync(Api.OnUserUpdateClientPairs,
new ClientPairDto() new ClientPairDto()
{ {
VanityUID = user.Alias,
OtherUID = user.UID, OtherUID = user.UID,
IsPaused = otherEntry.IsPaused, IsPaused = otherEntry.IsPaused,
IsPausedFromOthers = false, IsPausedFromOthers = false,