From d32b0884970e966c55310423e93ccc40bebb892c Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 12 Jun 2019 11:17:07 +0100 Subject: [PATCH] code format --- src/Yavsc/Hubs/ChatHub.cs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Yavsc/Hubs/ChatHub.cs b/src/Yavsc/Hubs/ChatHub.cs index fdf39d29..e6b81e2a 100644 --- a/src/Yavsc/Hubs/ChatHub.cs +++ b/src/Yavsc/Hubs/ChatHub.cs @@ -48,7 +48,7 @@ namespace Yavsc _dbContext = scope.ServiceProvider.GetService(); var loggerFactory = scope.ServiceProvider.GetService(); - + var stringLocFactory = scope.ServiceProvider.GetService(); _localizer = stringLocFactory.Create(typeof(ChatHub)); _logger = loggerFactory.CreateLogger(); @@ -88,11 +88,11 @@ namespace Yavsc Connected = true }); _dbContext.SaveChanges(); - Clients.Group(Constants.HubGroupFollowingPrefix+userId).notifyuser(NotificationTypes.Connected, userName, null); - + Clients.Group(Constants.HubGroupFollowingPrefix + userId).notifyuser(NotificationTypes.Connected, userName, null); + foreach (var uid in _dbContext.CircleMembers.Select(m => m.MemberId)) { - await Groups.Add(Context.ConnectionId, Constants.HubGroupFollowingPrefix+uid); + await Groups.Add(Context.ConnectionId, Constants.HubGroupFollowingPrefix + uid); } } else @@ -105,7 +105,7 @@ namespace Yavsc { await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous); } - await base.OnConnected(); + await base.OnConnected(); } string setUserName() { @@ -129,10 +129,11 @@ namespace Yavsc public override Task OnDisconnected(bool stopCalled) { string userName = Context.User?.Identity.Name; - if (userName!=null) { + if (userName != null) + { var user = _dbContext.Users.FirstOrDefault(u => u.UserName == userName); var userId = user.Id; - Clients.Group(Constants.HubGroupFollowingPrefix+userId).notifyuser(NotificationTypes.DisConnected, userName, null); + Clients.Group(Constants.HubGroupFollowingPrefix + userId).notifyuser(NotificationTypes.DisConnected, userName, null); var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId); if (cx != null) @@ -140,9 +141,9 @@ namespace Yavsc _dbContext.ChatConnection.Remove(cx); _dbContext.SaveChanges(); } - else + else _logger.LogError($"Could not remove user cx {Context.ConnectionId}"); - } + } Abort(); return base.OnDisconnected(stopCalled); } @@ -343,7 +344,11 @@ namespace Yavsc [Authorize] public void SendPV(string userName, string message) { - if (string.IsNullOrWhiteSpace(userName)) return; + if (string.IsNullOrWhiteSpace(userName)) + { + Clients.Caller.notifyUser(NotificationTypes.Error, "none!", "specify an user."); + return; + } if (userName[0] != '?') if (!Context.User.IsInRole(Constants.AdminGroupName)) @@ -380,10 +385,10 @@ namespace Yavsc void Abort() { - string cxId; - if (!ChatUserNames.TryRemove(Context.ConnectionId, out cxId )) + string cxId; + if (!ChatUserNames.TryRemove(Context.ConnectionId, out cxId)) _logger.LogError($"Could not remove user cx {Context.ConnectionId}"); - + } } }