Rework Contacts List Refreshing
This commit is contained in:
parent
7fb10cc728
commit
14dd3273f9
@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using qtc_api.Models;
|
||||
using qtc_api.Services.ContactService;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace qtc_api.Controllers
|
||||
@ -11,10 +12,12 @@ namespace qtc_api.Controllers
|
||||
public class ContactController : ControllerBase
|
||||
{
|
||||
private IContactService _contactService;
|
||||
private IHubContext<ChatHub> _chatGwContext;
|
||||
|
||||
public ContactController(IContactService contactService)
|
||||
public ContactController(IContactService contactService, IHubContext<ChatHub> chatGwContext)
|
||||
{
|
||||
_contactService = contactService;
|
||||
_chatGwContext = chatGwContext;
|
||||
}
|
||||
|
||||
[HttpPost("add-contact")]
|
||||
@ -30,6 +33,10 @@ namespace qtc_api.Controllers
|
||||
|
||||
var result = await _contactService.CreateContact(ownerId, userId);
|
||||
|
||||
// refresh contacts list for both users
|
||||
await _chatGwContext.Clients.User(userId).SendAsync("RefreshContactsList");
|
||||
await _chatGwContext.Clients.User(ownerId).SendAsync("RefreshContactsList");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -48,6 +55,11 @@ namespace qtc_api.Controllers
|
||||
var ownerId = claims.First().Value;
|
||||
|
||||
var result = await _contactService.UpdateContactStatus(ownerId, userId, Contact.ContactStatus.Accepted, Contact.ContactStatus.Accepted);
|
||||
|
||||
// refresh contacts list for both users
|
||||
await _chatGwContext.Clients.User(userId).SendAsync("RefreshContactsList");
|
||||
await _chatGwContext.Clients.User(ownerId).SendAsync("RefreshContactsList");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -66,6 +78,11 @@ namespace qtc_api.Controllers
|
||||
var ownerId = claims.First().Value;
|
||||
|
||||
var response = await _contactService.DeleteContact(ownerId, userId);
|
||||
|
||||
// refresh contacts list for both users
|
||||
await _chatGwContext.Clients.User(userId).SendAsync("RefreshContactsList");
|
||||
await _chatGwContext.Clients.User(ownerId).SendAsync("RefreshContactsList");
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
|
@ -152,20 +152,6 @@ namespace qtc_api.Hubs
|
||||
await Clients.All.SendAsync("RefreshRoomList");
|
||||
}
|
||||
|
||||
[HubMethodName("RefreshContactsListOnUser")]
|
||||
[Authorize]
|
||||
public async Task RefreshContactsListForUser(UserInformationDto user, User execUser)
|
||||
{
|
||||
var connection = ConnectedUsers.FirstOrDefault(e => e.ConnectedUser.Id == user.Id);
|
||||
var connection2 = ConnectedUsers.FirstOrDefault(e => e.ConnectedUser.Id == execUser.Id);
|
||||
if (connection != null && connection2 != null)
|
||||
{
|
||||
await Clients.Client(connection.ConnectionId).SendAsync("RefreshContactsList");
|
||||
await Clients.Client(connection2.ConnectionId).SendAsync("RefreshContactsList");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[HubMethodName("SendMessage")]
|
||||
[Authorize]
|
||||
public async Task SendMessageAsync(User user, Message message, bool IsLobbyMsg, Room room = null!)
|
||||
|
Loading…
x
Reference in New Issue
Block a user