[reorg]
This commit is contained in:
parent
c6c4652815
commit
093129b28c
2 changed files with 109 additions and 97 deletions
|
|
@ -68,7 +68,8 @@ namespace Yavsc
|
|||
|
||||
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
||||
|
||||
if (userHadConnections) {
|
||||
if (userHadConnections)
|
||||
{
|
||||
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
||||
ccx.Connected = true;
|
||||
}
|
||||
|
|
@ -90,7 +91,8 @@ namespace Yavsc
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// TODO var uname = Context.Request.QueryString[Constants.KeyParamChatUserName] ?? "anon";
|
||||
|
||||
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
||||
|
|
@ -159,7 +161,8 @@ namespace Yavsc
|
|||
var userId = user.Id;
|
||||
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
|
||||
|
||||
if (userHadConnections) {
|
||||
if (userHadConnections)
|
||||
{
|
||||
var ccx = _dbContext.ChatConnection.First(c => c.ConnectionId == Context.ConnectionId);
|
||||
ccx.Connected = true;
|
||||
}
|
||||
|
|
@ -179,7 +182,8 @@ namespace Yavsc
|
|||
|
||||
static ConcurrentDictionary<string, ChatRoomInfo> Channels = new ConcurrentDictionary<string, ChatRoomInfo>();
|
||||
|
||||
public class ChatRoomInfo {
|
||||
public class ChatRoomInfo
|
||||
{
|
||||
public string Name;
|
||||
public Dictionary<string, string> Users = new Dictionary<string, string>();
|
||||
public string Topic;
|
||||
|
|
@ -195,22 +199,25 @@ namespace Yavsc
|
|||
ChatRoomInfo chanInfo;
|
||||
if (Channels.ContainsKey(roomName))
|
||||
{
|
||||
if (Channels.TryGetValue(roomName, out chanInfo)) {
|
||||
if (Channels.TryGetValue(roomName, out chanInfo))
|
||||
{
|
||||
_logger.LogInformation("room is avaible.");
|
||||
if (chanInfo.Users.ContainsKey(Context.ConnectionId))
|
||||
_logger.LogWarning("user already joined.");
|
||||
else {
|
||||
_logger.LogWarning("user already joint.");
|
||||
else
|
||||
{
|
||||
chanInfo.Users.Add(Context.ConnectionId, userName);
|
||||
|
||||
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);
|
||||
|
||||
_logger.LogInformation("exiting ok.");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
|
||||
Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
|
||||
return;
|
||||
|
|
@ -230,7 +237,8 @@ namespace Yavsc
|
|||
chanInfo.Topic = room.Topic;
|
||||
chanInfo.Name = room.Name;
|
||||
}
|
||||
else { // a first join, we create it.
|
||||
else
|
||||
{ // a first join, we create it.
|
||||
_logger.LogInformation("room creation.");
|
||||
chanInfo.Name = roomName;
|
||||
chanInfo.Topic = "<just created>";
|
||||
|
|
@ -248,7 +256,8 @@ namespace Yavsc
|
|||
public void Register(string room)
|
||||
{
|
||||
var existent = _dbContext.ChatRoom.Any(r => r.Name == room);
|
||||
if (existent) {
|
||||
if (existent)
|
||||
{
|
||||
Clients.Caller.notify(NotificationTypes.Error, "already registered.");
|
||||
return;
|
||||
}
|
||||
|
|
@ -297,7 +306,8 @@ namespace Yavsc
|
|||
_dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Clients.Caller.notify(NotificationTypes.Error, "not joint");
|
||||
}
|
||||
}
|
||||
|
|
@ -309,7 +319,8 @@ namespace Yavsc
|
|||
ChatRoomInfo 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})");
|
||||
return;
|
||||
}
|
||||
|
|
@ -357,7 +368,8 @@ namespace Yavsc
|
|||
public void Abort()
|
||||
{
|
||||
var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
|
||||
if (cx!=null) {
|
||||
if (cx != null)
|
||||
{
|
||||
_dbContext.ChatConnection.Remove(cx);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
chat.client.onJoined = function (rinfo)
|
||||
chat.client.joint = function (rinfo)
|
||||
{
|
||||
console.log(rinfo);
|
||||
setActiveRoom(rinfo.Name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue