diff --git a/WGShare.API/Controllers/AuthController.cs b/WGShare.API/Controllers/AuthController.cs index 25df117..f88eb2c 100644 --- a/WGShare.API/Controllers/AuthController.cs +++ b/WGShare.API/Controllers/AuthController.cs @@ -51,6 +51,27 @@ namespace WGShare.API.Controllers return await _sqlSugar.Queryable().AnyAsync(x => x.IsDelete == false && x.Account == account && x.IsAnonymous == false); } + /// + /// 检查用户是否在线 + /// + /// + /// + [HttpGet("check-online"), AllowAnonymous] + public async Task CheckUserOnline([FromQuery] string account) + { + var user = await _sqlSugar.Queryable().FirstAsync(x => x.IsDelete == false && x.Account == account && x.IsAnonymous == false); + if (user == null) + { + return false; + } + var connectId = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetOnlineUserKey(user.TenantId), user.Id); + if (!string.IsNullOrWhiteSpace(connectId)) + { + return true; + } + return false; + } + /// /// 正常账号登录 /// diff --git a/WGShare.API/Hubs/SessionManageHub.cs b/WGShare.API/Hubs/SessionManageHub.cs index a2905e0..f1f000a 100644 --- a/WGShare.API/Hubs/SessionManageHub.cs +++ b/WGShare.API/Hubs/SessionManageHub.cs @@ -84,7 +84,7 @@ namespace WGShare.API.Hubs { _logger.LogInformation($@"{DateTime.Now} account:{account} 退出以下频道:{string.Join(',', roomNum)}"); if (!string.IsNullOrEmpty(roomNum)) - { + { // 判断是否全员看他,是则移除 var script = $@"local value = redis.call('HGET', KEYS[1], ARGV[1]) if value == ARGV[2] or value == ARGV[3] then @@ -274,12 +274,18 @@ namespace WGShare.API.Hubs { var uname = Context.User?.Claims.FirstOrDefault(x => x.Type == "uname")?.Value; var uid = Context.User?.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; + var tenant = Context.Items["tenant"].ToString(); + + _logger.LogInformation($" {DateTime.Now} 发送消息 uname:{uname} roomNum:{rooNum} msg:{msg}"); - _logger.LogInformation($" {DateTime.Now}发送消息 uname:" + uname); - _logger.LogInformation($" {DateTime.Now}发送消息 roomNum:" + rooNum); - _logger.LogInformation($" {DateTime.Now}发送消息 msg:" + msg); + var userInfo = RedisHelper.Instance.HGet(RedisKeyConstant.SessionManage.GetChannelUserKey(tenant, rooNum), uid); + var userName = uname; + if (userInfo != null) + { + userName = userInfo.UserName; + } - await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, uname, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg); + await Clients.OthersInGroup(rooNum).ReceiveMessage(uid, userName, msg, DateTime.Now.GetTotalMilliseconds()); //await Clients.GroupExcept(rooNum, Context.ConnectionId).ReceiveMessage(uid, uname, msg); } /// diff --git a/WGShare.API/WGShare.API.xml b/WGShare.API/WGShare.API.xml index 78bf812..4766f06 100644 --- a/WGShare.API/WGShare.API.xml +++ b/WGShare.API/WGShare.API.xml @@ -11,6 +11,13 @@ + + + 检查用户是否在线 + + + + 正常账号登录