diff --git a/qtc-net-server/Controllers/AuthController.cs b/qtc-net-server/Controllers/AuthController.cs index d792287..9bafa4b 100644 --- a/qtc-net-server/Controllers/AuthController.cs +++ b/qtc-net-server/Controllers/AuthController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Razor.TagHelpers; using qtc_api.Dtos.User; using System.Runtime.CompilerServices; using System.Text.Json; @@ -13,14 +14,16 @@ namespace qtc_api.Controllers { private readonly IUserService _userService; private readonly ITokenService _tokenService; + private readonly IHubContext _chatGWContext; private readonly ServerConfig serverConfig; private readonly DataContext dataContext; - public AuthController(IUserService userService, ITokenService tokenService, DataContext dataContext) + public AuthController(IUserService userService, ITokenService tokenService, IHubContext chatGWContext, DataContext dataContext) { _userService = userService; _tokenService = tokenService; + _chatGWContext = chatGWContext; serverConfig = JsonSerializer.Deserialize(JsonDocument.Parse(System.IO.File.ReadAllText("./ServerConfig.json"))); this.dataContext = dataContext; @@ -32,6 +35,7 @@ namespace qtc_api.Controllers if(userDto != null) { var response = await _userService.AddUser(userDto); + await _chatGWContext.Clients.All.SendAsync("RefreshUserList"); if(response.Success != false) { return Ok(response); diff --git a/qtc-net-server/Controllers/UsersController.cs b/qtc-net-server/Controllers/UsersController.cs index e994001..c8e3427 100644 --- a/qtc-net-server/Controllers/UsersController.cs +++ b/qtc-net-server/Controllers/UsersController.cs @@ -9,11 +9,13 @@ namespace qtc_api.Controllers public class UsersController : ControllerBase { private readonly IUserService _userService; - private readonly IDistributedCache cache; - public UsersController(IUserService userService, IDistributedCache distributedCache) + private readonly IDistributedCache _cache; + private readonly IHubContext _chatGWContext; + public UsersController(IUserService userService, IDistributedCache distributedCache, IHubContext chatGWContext) { _userService = userService; - cache = distributedCache; + _cache = distributedCache; + _chatGWContext = chatGWContext; } [HttpGet("all")] @@ -72,6 +74,8 @@ namespace qtc_api.Controllers { var updatedUser = await _userService.UpdateUserInfo(user); + await _chatGWContext.Clients.All.SendAsync("RefreshUserList"); + return Ok(updatedUser); } else { @@ -103,6 +107,8 @@ namespace qtc_api.Controllers var response = await _userService.UpdateUserPic(userId, file); + await _chatGWContext.Clients.All.SendAsync("RefreshContactsList"); + // always try to overwrite cache when updating pfp string recordId = $"UserPfp_{userId}_{DateTime.Now.ToString("yyyyMMdd_hhmm")}"; using(var stream = file.OpenReadStream()) @@ -110,7 +116,7 @@ namespace qtc_api.Controllers using(var ms = new MemoryStream()) { stream.CopyTo(ms); - await cache.SetImageAsync(recordId, ms.ToArray()); + await _cache.SetImageAsync(recordId, ms.ToArray()); ms.Dispose(); } stream.Dispose(); @@ -132,7 +138,7 @@ namespace qtc_api.Controllers public async Task GetUserProfilePicture(string userId) { string recordId = $"UserPfp_{userId}_{DateTime.Now.ToString("yyyyMMdd_hhmm")}"; - byte[] pfpBytes = await cache.GetImageAsync(recordId); + byte[] pfpBytes = await _cache.GetImageAsync(recordId); var result = new ServiceResponse(); if (pfpBytes == null) @@ -141,7 +147,7 @@ namespace qtc_api.Controllers if (result != null && result.Success && result.Data != null) { pfpBytes = result.Data.FileContents; - await cache.SetImageAsync(recordId, pfpBytes); + await _cache.SetImageAsync(recordId, pfpBytes); } } else @@ -171,6 +177,7 @@ namespace qtc_api.Controllers public async Task>> DeleteUserById(string id) { var result = await _userService.DeleteUser(id); + await _chatGWContext.Clients.All.SendAsync("RefreshUserList"); return Ok(result); }