drop useless Abort function

main
Paul Schneider 7 years ago
parent 8528e3e725
commit 4da630a8f6
3 changed files with 18 additions and 25 deletions

@ -129,25 +129,21 @@ 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 userId = user.Id;
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)
{ {
if (stopCalled) _dbContext.ChatConnection.Remove(cx);
{
var user = _dbContext.Users.Single(u => u.UserName == userName);
user.Connections.Remove(cx);
ChatUserNames[Context.ConnectionId] = null;
}
else
{
cx.Connected = false;
}
_dbContext.SaveChanges(); _dbContext.SaveChanges();
} }
} else
Clients.Group("authenticated").notifyUser(NotificationTypes.DisConnected, userName, "disconnected"); _logger.LogError($"Could not remove user cx {Context.ConnectionId}");
}
Abort();
return base.OnDisconnected(stopCalled); return base.OnDisconnected(stopCalled);
} }
@ -382,14 +378,12 @@ namespace Yavsc
cli.addStreamInfo(sender, streamId, message); cli.addStreamInfo(sender, streamId, message);
} }
public void Abort() void Abort()
{ {
var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId); string cxId;
if (cx != null) if (!ChatUserNames.TryRemove(Context.ConnectionId, out cxId ))
{ _logger.LogError($"Could not remove user cx {Context.ConnectionId}");
_dbContext.ChatConnection.Remove(cx);
_dbContext.SaveChanges();
}
} }
} }
} }

@ -263,8 +263,8 @@ window.ChatHubHandler = (function ($) {
return encodedValue; return encodedValue;
} }
// FIXME cx clean shutdown
$(window).unload(function () { chat.server.abort(); }); // $(window).unload(function () { });
}; };

@ -10,8 +10,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Yavsc.Server.Helpers;
using Yavsc.Server.Model;
namespace testOauthClient.Controllers namespace testOauthClient.Controllers
{ {
@ -36,6 +34,7 @@ namespace testOauthClient.Controllers
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken) public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken)
{ {

Loading…