public void Init(ChatroomSession roomManager)
 {
     _chatroomSession = roomManager;
     listBoxMembership.ItemsSource = _chatroomSession.Membership;
     Title = roomManager.ChatroomId;
     _chatroomSession.ChatMessageReceived += ChatMessages_CollectionChanged;
 }
        public void JoinChatroom(string id, string password = null)
        {
            ChatroomSessionBase chatroomSession;
            if (_chatroomUsage.TryGetValue(id, out chatroomSession))
            {
                if (chatroomSession.State == ChatroomState.New)
                    return;// we are already joining
                else if (chatroomSession.State == ChatroomState.Connected)
                {
                    chatroomSession.ShowControl(true);// show it
                    return;
                }
                // else state == invited, so join it
            }

            if (id.StartsWith(PrefixGameLobby))
            {
                var gameId = id.Substring(PrefixGameLobby.Length);
                HomeTab.LauncherInfo gameInfo;
                if (_userData.TryGetGame(gameId, out gameInfo))
                {
                    var session = new Lobby.LobbySession(this, gameInfo);
                    session.LoadGameRoomsComplete += session_LoadGameRoomsComplete;
                    session.LoadGameRooms();
                    chatroomSession = session;
                }
            }
            else if (id.StartsWith(PrefixGameRoom))
            {
                var gameRoomId = id.Substring(PrefixGameRoom.Length);
                Lobby.LobbySession lobbySession;
                Lobby.GameRoomItem gameRoomItem;
                if (!TryGetGameRoomAndSession(gameRoomId, out lobbySession, out gameRoomItem))
                {
                    Lobby.LobbySession.LookupGameRoom(_userData, gameRoomId, JoinLobbyAndGameRoom);
                    return;
                }

                var gameRoomSession = new GameRoom.GameRoomSession(this, lobbySession, gameRoomItem);
                chatroomSession = gameRoomSession;
            }
            else
                chatroomSession = new ChatroomSession(this);

            chatroomSession.ChatroomId = id;

            _chatroomUsage[id] = chatroomSession;

            var chatroom = new Chatroom { _id = id };
            var joinChatroom = (password == null)
                ? chatroom
                : new ChatroomWithPassword { _id = id, password = password, };
            ChatroomUserJoin(joinChatroom);
            ChatroomMemberGetList(chatroom);
        }