private void ChatroomUserLeave(Chatroom chatroom)
 {
     _userData.PgSession.EmitLater("Chatroom.leave", chatroom);
 }
 private void ChatroomMemberGetList(Chatroom chatroom)
 {
     _userData.PgSession.EmitLater("Chatroom.Member.getList", chatroom);
 }
 private void ChatroomUserJoin(Chatroom chatroom)
 {
     _userData.PgSession.EmitLater("Chatroom.join", chatroom);
 }
        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);
        }