|
|
|
@ -68,7 +68,8 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
|
|
|
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
|
|
|
|
|
|
|
|
|
|
|
if (userHadConnections) {
|
|
|
|
if (userHadConnections)
|
|
|
|
|
|
|
|
{
|
|
|
|
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
|
|
|
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
|
|
|
ccx.Connected = true;
|
|
|
|
ccx.Connected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -90,7 +91,8 @@ namespace Yavsc
|
|
|
|
throw new NotSupportedException();
|
|
|
|
throw new NotSupportedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
// TODO var uname = Context.Request.QueryString[Constants.KeyParamChatUserName] ?? "anon";
|
|
|
|
// TODO var uname = Context.Request.QueryString[Constants.KeyParamChatUserName] ?? "anon";
|
|
|
|
|
|
|
|
|
|
|
|
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
|
|
|
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
|
|
|
@ -159,7 +161,8 @@ namespace Yavsc
|
|
|
|
var userId = user.Id;
|
|
|
|
var userId = user.Id;
|
|
|
|
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
|
|
|
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
|
|
|
|
|
|
|
|
|
|
|
if (userHadConnections) {
|
|
|
|
if (userHadConnections)
|
|
|
|
|
|
|
|
{
|
|
|
|
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
|
|
|
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
|
|
|
ccx.Connected = true;
|
|
|
|
ccx.Connected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -179,7 +182,8 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
|
|
static ConcurrentDictionary<string, ChatRoomInfo> Channels = new ConcurrentDictionary<string, ChatRoomInfo>();
|
|
|
|
static ConcurrentDictionary<string, ChatRoomInfo> Channels = new ConcurrentDictionary<string, ChatRoomInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
public class ChatRoomInfo {
|
|
|
|
public class ChatRoomInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
public string Name;
|
|
|
|
public string Name;
|
|
|
|
public Dictionary<string, string> Users = new Dictionary<string, string>();
|
|
|
|
public Dictionary<string, string> Users = new Dictionary<string, string>();
|
|
|
|
public string Topic;
|
|
|
|
public string Topic;
|
|
|
|
@ -195,22 +199,25 @@ namespace Yavsc
|
|
|
|
ChatRoomInfo chanInfo;
|
|
|
|
ChatRoomInfo chanInfo;
|
|
|
|
if (Channels.ContainsKey(roomName))
|
|
|
|
if (Channels.ContainsKey(roomName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Channels.TryGetValue(roomName, out chanInfo)) {
|
|
|
|
if (Channels.TryGetValue(roomName, out chanInfo))
|
|
|
|
|
|
|
|
{
|
|
|
|
_logger.LogInformation("room is avaible.");
|
|
|
|
_logger.LogInformation("room is avaible.");
|
|
|
|
if (chanInfo.Users.ContainsKey(Context.ConnectionId))
|
|
|
|
if (chanInfo.Users.ContainsKey(Context.ConnectionId))
|
|
|
|
_logger.LogWarning("user already joined.");
|
|
|
|
_logger.LogWarning("user already joint.");
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
chanInfo.Users.Add(Context.ConnectionId, userName);
|
|
|
|
chanInfo.Users.Add(Context.ConnectionId, userName);
|
|
|
|
|
|
|
|
|
|
|
|
Groups.Add(Context.ConnectionId, roomGroupName);
|
|
|
|
Groups.Add(Context.ConnectionId, roomGroupName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Clients.Caller.onJoined(chanInfo);
|
|
|
|
Clients.Caller.joint(chanInfo);
|
|
|
|
Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName);
|
|
|
|
Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName);
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("exiting ok.");
|
|
|
|
_logger.LogInformation("exiting ok.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
_logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
|
|
|
|
_logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -230,7 +237,8 @@ namespace Yavsc
|
|
|
|
chanInfo.Topic = room.Topic;
|
|
|
|
chanInfo.Topic = room.Topic;
|
|
|
|
chanInfo.Name = room.Name;
|
|
|
|
chanInfo.Name = room.Name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // a first join, we create it.
|
|
|
|
else
|
|
|
|
|
|
|
|
{ // a first join, we create it.
|
|
|
|
_logger.LogInformation("room creation.");
|
|
|
|
_logger.LogInformation("room creation.");
|
|
|
|
chanInfo.Name = roomName;
|
|
|
|
chanInfo.Name = roomName;
|
|
|
|
chanInfo.Topic = "<just created>";
|
|
|
|
chanInfo.Topic = "<just created>";
|
|
|
|
@ -248,7 +256,8 @@ namespace Yavsc
|
|
|
|
public void Register(string room)
|
|
|
|
public void Register(string room)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var existent = _dbContext.ChatRoom.Any(r => r.Name == room);
|
|
|
|
var existent = _dbContext.ChatRoom.Any(r => r.Name == room);
|
|
|
|
if (existent) {
|
|
|
|
if (existent)
|
|
|
|
|
|
|
|
{
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "already registered.");
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "already registered.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -297,7 +306,8 @@ namespace Yavsc
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "not joint");
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, "not joint");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -309,7 +319,8 @@ namespace Yavsc
|
|
|
|
ChatRoomInfo chanInfo;
|
|
|
|
ChatRoomInfo chanInfo;
|
|
|
|
if (Channels.TryGetValue(roomName, out chanInfo))
|
|
|
|
if (Channels.TryGetValue(roomName, out chanInfo))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!chanInfo.Users.ContainsKey(Context.ConnectionId)){
|
|
|
|
if (!chanInfo.Users.ContainsKey(Context.ConnectionId))
|
|
|
|
|
|
|
|
{
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, $"could not join channel ({roomName})");
|
|
|
|
Clients.Caller.notify(NotificationTypes.Error, $"could not join channel ({roomName})");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -357,7 +368,8 @@ namespace Yavsc
|
|
|
|
public void Abort()
|
|
|
|
public void Abort()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
|
|
|
|
{
|
|
|
|
_dbContext.ChatConnection.Remove(cx);
|
|
|
|
_dbContext.ChatConnection.Remove(cx);
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
_dbContext.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|