code format
This commit is contained in:
parent
5e4515df58
commit
88ce2f674d
1 changed files with 18 additions and 13 deletions
|
|
@ -48,7 +48,7 @@ namespace Yavsc
|
||||||
|
|
||||||
_dbContext = scope.ServiceProvider.GetService<ApplicationDbContext>();
|
_dbContext = scope.ServiceProvider.GetService<ApplicationDbContext>();
|
||||||
var loggerFactory = scope.ServiceProvider.GetService<ILoggerFactory>();
|
var loggerFactory = scope.ServiceProvider.GetService<ILoggerFactory>();
|
||||||
|
|
||||||
var stringLocFactory = scope.ServiceProvider.GetService<IStringLocalizerFactory>();
|
var stringLocFactory = scope.ServiceProvider.GetService<IStringLocalizerFactory>();
|
||||||
_localizer = stringLocFactory.Create(typeof(ChatHub));
|
_localizer = stringLocFactory.Create(typeof(ChatHub));
|
||||||
_logger = loggerFactory.CreateLogger<ChatHub>();
|
_logger = loggerFactory.CreateLogger<ChatHub>();
|
||||||
|
|
@ -88,11 +88,11 @@ namespace Yavsc
|
||||||
Connected = true
|
Connected = true
|
||||||
});
|
});
|
||||||
_dbContext.SaveChanges();
|
_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))
|
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
|
else
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Yavsc
|
||||||
{
|
{
|
||||||
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
||||||
}
|
}
|
||||||
await base.OnConnected();
|
await base.OnConnected();
|
||||||
}
|
}
|
||||||
string setUserName()
|
string setUserName()
|
||||||
{
|
{
|
||||||
|
|
@ -129,10 +129,11 @@ namespace Yavsc
|
||||||
public override Task OnDisconnected(bool stopCalled)
|
public override Task OnDisconnected(bool stopCalled)
|
||||||
{
|
{
|
||||||
string userName = Context.User?.Identity.Name;
|
string userName = Context.User?.Identity.Name;
|
||||||
if (userName!=null) {
|
if (userName != null)
|
||||||
|
{
|
||||||
var user = _dbContext.Users.FirstOrDefault(u => u.UserName == userName);
|
var user = _dbContext.Users.FirstOrDefault(u => u.UserName == userName);
|
||||||
var userId = user.Id;
|
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);
|
var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
|
||||||
if (cx != null)
|
if (cx != null)
|
||||||
|
|
@ -140,9 +141,9 @@ namespace Yavsc
|
||||||
_dbContext.ChatConnection.Remove(cx);
|
_dbContext.ChatConnection.Remove(cx);
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_logger.LogError($"Could not remove user cx {Context.ConnectionId}");
|
_logger.LogError($"Could not remove user cx {Context.ConnectionId}");
|
||||||
}
|
}
|
||||||
Abort();
|
Abort();
|
||||||
return base.OnDisconnected(stopCalled);
|
return base.OnDisconnected(stopCalled);
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +344,11 @@ namespace Yavsc
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public void SendPV(string userName, string message)
|
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 (userName[0] != '?')
|
||||||
if (!Context.User.IsInRole(Constants.AdminGroupName))
|
if (!Context.User.IsInRole(Constants.AdminGroupName))
|
||||||
|
|
@ -380,10 +385,10 @@ namespace Yavsc
|
||||||
|
|
||||||
void Abort()
|
void Abort()
|
||||||
{
|
{
|
||||||
string cxId;
|
string cxId;
|
||||||
if (!ChatUserNames.TryRemove(Context.ConnectionId, out cxId ))
|
if (!ChatUserNames.TryRemove(Context.ConnectionId, out cxId))
|
||||||
_logger.LogError($"Could not remove user cx {Context.ConnectionId}");
|
_logger.LogError($"Could not remove user cx {Context.ConnectionId}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue