avoid useless notifications
This commit is contained in:
parent
f0e47e7ec6
commit
bafc68dae0
1 changed files with 23 additions and 22 deletions
|
|
@ -83,22 +83,20 @@ namespace Yavsc
|
||||||
Connected = true
|
Connected = true
|
||||||
});
|
});
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
// TODO ChatHubConnectioinFlags
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME is this line reached ?
|
// this line isn't reached: Context.User != null <=> Context.User.Identity.IsAuthenticated
|
||||||
_logger.LogInformation("Anonymous chat user (first use case)");
|
_logger.LogInformation("Anonymous chat user (first use case)");
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
|
||||||
}
|
}
|
||||||
// TODO only notify followers
|
// TODO only notify followers
|
||||||
Clients.Group(Constants.HubGroupAuthenticated).notify(NotificationTypes.Connected, userName);
|
Clients.Group(Constants.HubGroupAuthenticated).notifyuser(NotificationTypes.Connected, userName, "");
|
||||||
await base.OnConnected();
|
await base.OnConnected();
|
||||||
}
|
}
|
||||||
string setUserName()
|
string setUserName()
|
||||||
|
|
@ -125,7 +123,7 @@ 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;
|
||||||
Clients.Group("authenticated").notify(NotificationTypes.DisConnected, userName);
|
Clients.Group("authenticated").notifyUser(NotificationTypes.DisConnected, userName);
|
||||||
if (userName != null)
|
if (userName != null)
|
||||||
{
|
{
|
||||||
var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
|
var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
|
||||||
|
|
@ -172,7 +170,7 @@ namespace Yavsc
|
||||||
Connected = true
|
Connected = true
|
||||||
});
|
});
|
||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
Clients.Group("authenticated").notify(NotificationTypes.Reconnected, userName);
|
Clients.Group("authenticated").notifyUser(NotificationTypes.Reconnected, userName);
|
||||||
}
|
}
|
||||||
return base.OnReconnected();
|
return base.OnReconnected();
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +189,7 @@ namespace Yavsc
|
||||||
var candidate = "?" + nickName;
|
var candidate = "?" + nickName;
|
||||||
if (ChatUserNames.Any(u => u.Value == candidate))
|
if (ChatUserNames.Any(u => u.Value == candidate))
|
||||||
{
|
{
|
||||||
Clients.Caller.notify(NotificationTypes.ExistingUserName, nickName);
|
Clients.Caller.notifyUser(NotificationTypes.ExistingUserName, nickName, "aborting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChatUserNames[Context.ConnectionId] = "?" + nickName;
|
ChatUserNames[Context.ConnectionId] = "?" + nickName;
|
||||||
|
|
@ -221,19 +219,17 @@ namespace Yavsc
|
||||||
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.joint(chanInfo);
|
||||||
|
Clients.Group("room_" + roomName).notifyRoom(NotificationTypes.UserJoin, roomName, userName);
|
||||||
|
return chanInfo;
|
||||||
}
|
}
|
||||||
Clients.Caller.joint(chanInfo);
|
return null;
|
||||||
Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, userName);
|
|
||||||
|
|
||||||
_logger.LogInformation("exiting ok.");
|
|
||||||
return chanInfo;
|
|
||||||
}
|
}
|
||||||
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.notifyRoom(NotificationTypes.Error, roomName, "join get chan failed ...");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -273,7 +269,7 @@ namespace Yavsc
|
||||||
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.notifyUser(NotificationTypes.Error, room, "already registered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string userName = Context.User.Identity.Name;
|
string userName = Context.User.Identity.Name;
|
||||||
|
|
@ -306,10 +302,15 @@ namespace Yavsc
|
||||||
if (Channels.TryGetValue(roomName, out chanInfo))
|
if (Channels.TryGetValue(roomName, out chanInfo))
|
||||||
{
|
{
|
||||||
var roomGroupName = "room_" + roomName;
|
var roomGroupName = "room_" + roomName;
|
||||||
|
if (!chanInfo.Users.ContainsKey(Context.ConnectionId))
|
||||||
|
{
|
||||||
|
NotifyRoomError(roomName, "you didn't join.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Groups.Remove(Context.ConnectionId, roomGroupName);
|
Groups.Remove(Context.ConnectionId, roomGroupName);
|
||||||
var group = Clients.Group(roomGroupName);
|
var group = Clients.Group(roomGroupName);
|
||||||
var username = ChatUserNames[Context.ConnectionId];
|
var username = ChatUserNames[Context.ConnectionId];
|
||||||
group.notify(NotificationTypes.UserPart, $"{roomName} {username} ({reason})");
|
group.notifyRoom(NotificationTypes.UserPart, roomName, $"{username}: {reason}");
|
||||||
|
|
||||||
chanInfo.Users.Remove(Context.ConnectionId);
|
chanInfo.Users.Remove(Context.ConnectionId);
|
||||||
ChatRoomInfo deadchanInfo;
|
ChatRoomInfo deadchanInfo;
|
||||||
|
|
@ -323,13 +324,13 @@ namespace Yavsc
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NotifyNotJoint(roomName, "no such room");
|
NotifyRoomError(roomName, $"could not join: no such room");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyNotJoint(string room, string reason)
|
void NotifyRoomError(string room, string reason)
|
||||||
{
|
{
|
||||||
Clients.Caller.notify(NotificationTypes.Error, $"{room} not joint: {reason}");
|
Clients.Caller.notifyUser(NotificationTypes.Error, room, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -342,7 +343,7 @@ namespace Yavsc
|
||||||
if (!chanInfo.Users.ContainsKey(Context.ConnectionId))
|
if (!chanInfo.Users.ContainsKey(Context.ConnectionId))
|
||||||
{
|
{
|
||||||
var notSentMsg = $"could not send to channel ({roomName}) (not joint)";
|
var notSentMsg = $"could not send to channel ({roomName}) (not joint)";
|
||||||
Clients.Caller.notify(NotificationTypes.Error, notSentMsg);
|
Clients.Caller.notifyUser(NotificationTypes.Error, roomName, notSentMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string uname = ChatUserNames[Context.ConnectionId];
|
string uname = ChatUserNames[Context.ConnectionId];
|
||||||
|
|
@ -352,7 +353,7 @@ namespace Yavsc
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var noChanMsg = $"could not send to channel ({roomName}) (no such chan)";
|
var noChanMsg = $"could not send to channel ({roomName}) (no such chan)";
|
||||||
Clients.Caller.notify(NotificationTypes.Error, noChanMsg);
|
Clients.Caller.notifyUser(NotificationTypes.Error, roomName, noChanMsg);
|
||||||
_logger.LogWarning(noChanMsg);
|
_logger.LogWarning(noChanMsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -376,7 +377,7 @@ namespace Yavsc
|
||||||
|
|
||||||
if (bl.Count() > 0)
|
if (bl.Count() > 0)
|
||||||
{
|
{
|
||||||
Clients.Caller.notify(NotificationTypes.PrivateMessageDenied, userName);
|
Clients.Caller.notifyUser(NotificationTypes.PrivateMessageDenied, userName, "you are black listed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue