/// <inheritdoc /> public override Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) { if (connectionId == null) { throw new ArgumentNullException(nameof(connectionId)); } if (groupName == null) { throw new ArgumentNullException(nameof(groupName)); } var connection = _connections[connectionId]; if (connection == null) { return(Task.CompletedTask); } if (_groups.Remove(connectionId, groupName)) { //empty group return(_localDirectory.PerformAction(DirectoryAction.RemoveGroup(_hubName, groupName))); } return(Task.CompletedTask); }
/// <inheritdoc /> public override Task OnDisconnectedAsync(HubConnectionContext connection) { _connections.Remove(connection); var emptyGroups = _groups.RemoveDisconnectedConnection(connection.ConnectionId); var actions = new List <DirectoryAction>(); actions.Add(DirectoryAction.RemoveConnection(_hubName, connection.ConnectionId)); if (!string.IsNullOrEmpty(connection.UserIdentifier)) { actions.Add(DirectoryAction.RemoveUser(_hubName, connection.UserIdentifier)); } actions.AddRange(emptyGroups.Select(g => DirectoryAction.RemoveGroup(_hubName, g))); return(_localDirectory.PerformActions(actions)); }