int UCMeetingProxy::RemoveParticipant(const UCSDKContact& member, const std::string& convId)
{
	DEBUG_LOG() << "--- ENTER";
	INFO_PARAM2(member.uri_, convId);

	//获取conversation
	uc::model::conversation::Conversation* pConversation = GetConversation(convId);
	if (NULL == pConversation)
	{
		ERROR_LOG() << "Get conversation failed.";
		DEBUG_LOG() << "--- LEAVE";
		return UCSDK_Fail;
	}

	//查找联系人
	Contact contact;
	int iRet = FindContact(contact, member);
	if (UCSDK_Succ != iRet)
	{
		ERROR_LOG() << "Find contact failed.";
		DEBUG_LOG() << "--- LEAVE";
		return iRet;
	}

	//删除与会人
	if (!pConversation->RemoveParticipant(contact))
	{
		ERROR_LOG() << "Remove participant failed.";
		DEBUG_LOG() << "--- LEAVE";
		return UCSDK_Fail;
	}

	DEBUG_LOG() << "--- LEAVE";
	return UCSDK_Succ;
}
void ConversationSystem::ProcessConversations() {
	// Remove the dying conversations first
	for( int i = 0; i < _dyingConversations.Num(); i++ ) {
		// Remove the dying index from the active conversations list
		_activeConversations.Remove( _dyingConversations[i] );
	}
	_dyingConversations.Clear();
	// What remains is a list of active conversations
	for( int i = 0; i < _activeConversations.Num(); i++ ) {
		ConversationPtr conv = GetConversation( _activeConversations[i] );
		assert( conv != NULL );
		// Let the conversation do its job
		if( !conv->Process() ) {
			// Job returned false, terminate this conversation
			DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Terminating conversation %s due to error.\r", conv->GetName().c_str() );
			EndConversation( _activeConversations[i] );
			continue;
		}
		// Check if the conversation is done
		if( conv->IsDone() ) {
			// Job returned false, terminate this conversation
			DM_LOG( LC_CONVERSATION, LT_INFO )LOGSTRING( "Conversation %s finished normally.\r", conv->GetName().c_str() );
			EndConversation( _activeConversations[i] );
			continue;
		}
	}
}
void ConversationSystem::EndConversation( int index ) {
	ConversationPtr conv = GetConversation( index );
	if( conv == NULL ) {
		gameLocal.Warning( "StartConversation: Can't find conversation with index %d", index );
		return;
	}
	// Let the conversation end in a controlled fashion
	conv->End();
	_dyingConversations.AddUnique( index );
}
int UCMeetingProxy::LeaveMeeting(const std::string& convId)
{
	DEBUG_LOG() << "--- ENTER";
	INFO_PARAM1(convId);

	if (convId.empty())
	{
		ERROR_LOG() << "convId is empty.";
		DEBUG_LOG() << "--- LEAVE";
		return UCSDK_InvalidParam;
	}

	//获取conversation
	uc::model::conversation::Conversation* pConversation = GetConversation(convId);
	if (NULL == pConversation)
	{
		ERROR_LOG() << "Get conversation failed.";
		DEBUG_LOG() << "--- LEAVE";
		return UCSDK_Fail;
	}

	//获取AVsession
	uc::model::conversation::AVSession* pAVSession = GetAVSession(pConversation);
	if (NULL == pAVSession)
	{
		ERROR_LOG() << "Get av session failed.";
		DEBUG_LOG() << "--- LEAVE";
		return UCSDK_Fail;
	}

	pAVSession->Disconnect();
	pConversation->RemoveSession(uc::model::InstantMessage);
	pConversation->RemoveSession(uc::model::AudioVideo);
	if (NULL != m_pConvManager)
	{
		m_pConvManager->RemoveConversation(convId);
	}

	DEBUG_LOG() << "--- LEAVE";
	return UCSDK_Succ;
}
void ConversationSystem::StartConversation( int index ) {
	ConversationPtr conv = GetConversation( index );
	if( conv == NULL ) {
		gameLocal.Warning( "StartConversation: Can't find conversation with index %d", index );
		return;
	}
	DM_LOG( LC_CONVERSATION, LT_INFO )LOGSTRING( "Trying to start conversation %s.\r", conv->GetName().c_str() );
	// Check if the conversation is already playing
	if( _activeConversations.FindIndex( index ) != -1 ) {
		DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Cannot start conversation %s, it's already playing!\r", conv->GetName().c_str() );
		return;
	}
	// Check if the conditions to start the conversations is met
	if( !conv->CheckConditions() ) {
		DM_LOG( LC_CONVERSATION, LT_DEBUG )LOGSTRING( "Cannot start conversation %s, conditions are not met.\r", conv->GetName().c_str() );
		return;
	}
	// Start the conversation
	conv->Start();
	// Register this conversation for processing
	_activeConversations.AddUnique( index );
}
uc::model::conversation::AVSession* UCMeetingProxy::GetAVSession(const std::string& convId)
{
	DEBUG_LOG() << "--- ENTER";

	uc::model::conversation::AVSession* pAVSession = NULL;

	uc::model::conversation::Conversation* pConversation = GetConversation(convId);
	if (NULL == pConversation)
	{
		ERROR_LOG() << "Get conversation failed.";
		DEBUG_LOG() << "--- LEAVE";
		return pAVSession;
	}

	pAVSession = dynamic_cast<uc::model::conversation::AVSession*>(pConversation->GetSession(uc::model::AudioVideo));
	if (NULL == pAVSession)
	{
		ERROR_LOG() << "Get av session failed.";
	}

	DEBUG_LOG() << "--- LEAVE";
	return pAVSession;
}
ConversationPtr ConversationSystem::GetConversation( const idStr &name ) {
	// Find the index and pass the call to the overload
	return GetConversation( GetConversationIndex( name ) );
}