Fix LINQ Expressions In `UpdateContactStatus and DeleteContact`

This commit is contained in:
Alan Moon 2025-06-28 10:45:07 -07:00
parent 52f02a6c8c
commit acc11d536f
2 changed files with 23 additions and 5 deletions

View File

@ -24,7 +24,7 @@ namespace qtc_api.Hubs
if (connection != null)
{
var user = OnlineUsers.FirstOrDefault(x => x.Id == connection!.ConnectedUser!.Id);
var user = OnlineUsers.FirstOrDefault(x => x.Id == connection.ConnectedUser!.Id);
if (user != null)
{
@ -33,10 +33,27 @@ namespace qtc_api.Hubs
}
}
public async override Task OnConnectedAsync()
{
Log("Client Connected To Hub.");
var connection = ConnectedUsers.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId);
if(connection != null)
{
var onlineUser = OnlineUsers.FirstOrDefault(x => x.Id == connection.ConnectedUser!.Id);
if (onlineUser != null)
{
// if the user is reconnecting, ensure their status is set to Online
await _userService.UpdateStatus(new UserStatusDto { Id = connection.ConnectedUser!.Id, Status = 1 });
}
}
}
[HubMethodName("LoginHub")]
public async Task LoginAsync(User user)
{
await Clients.All.SendAsync("rm", $"[SERVER] User {user.Username} Is Now Online");
Log($"User {user.Username} Has Logged In");
var statusDto = new UserStatusDto { Id = user.Id, Status = 1 };

View File

@ -35,7 +35,8 @@
public async Task<ServiceResponse<bool>> UpdateContactStatus(string ownerId, string userId, Contact.ContactStatus ownerStatus, Contact.ContactStatus userStatus)
{
var serviceResponse = new ServiceResponse<bool>();
var contact = await _dataContext.Contacts.FirstOrDefaultAsync(e => (e.OwnerId == ownerId || e.UserId == userId) || (e.OwnerId == userId || e.UserId == ownerId));
var contact = await _dataContext.Contacts.FirstOrDefaultAsync(e => (e.OwnerId == ownerId && e.UserId == userId) || (e.OwnerId == userId && e.UserId == ownerId));
if (contact != null)
{
@ -53,7 +54,7 @@
public async Task<ServiceResponse<Contact>> DeleteContact(string ownerId, string userId)
{
var serviceResponse = new ServiceResponse<Contact>();
var contact = await _dataContext.Contacts.FirstOrDefaultAsync(x => (x.OwnerId == ownerId || x.UserId == userId) || (x.OwnerId == userId || x.UserId == ownerId));
var contact = await _dataContext.Contacts.FirstOrDefaultAsync(e => (e.OwnerId == ownerId && e.UserId == userId) || (e.OwnerId == userId && e.UserId == ownerId));
if (contact != null)
{