示例#1
0
//-----------------------------------------------------------------------------
//VOXOX - CJC - 2009.05.07 Add session form AskImVoxOxCom
bool PurpleIMChat::createChatToEmailSessionCbk(void * dataIn)
{
	#if (defined OS_WINDOWS)
		Mutex::ScopedLock lock(PurpleIMChat::_mutex);
	#endif

	PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn;

	PurpleIMChat*  imChat		= cbData->getPurpleIMChat();
	IMContactSet*  imContactSet	= cbData->getIMContactSet();
	PurpleAccount* gAccount		= getPurpleAccount( imChat->getIMAccount() );
	
	IMContactSet::const_iterator askImContact;

	if (imContactSet->empty())
	{
		LOG_FATAL("imContactSet is empty");
	}
	else if (imContactSet->size() == 1)
	{
		askImContact = imContactSet->begin();
		std::string askId = (*askImContact).getContactId();

		PurpleConversation *gConv = NULL;

		if ((gConv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, askId.c_str(), gAccount)))
		{
			mConvInfo_t *mConv = (mConvInfo_t *)gConv->ui_data;
			imChat->newIMChatToEmailSessionCreatedEvent(*imChat, *(mConv->conv_session));	//VOXOX - JRT - 2009.07.09 

			timeoutRemove( cbData );
			delete cbData;

			return FALSE;
		}

		purple_conversation_new(PURPLE_CONV_TYPE_IM, gAccount, askId.c_str());
	}

	timeoutRemove( cbData );
	delete cbData;

	return TRUE;
}
示例#2
0
void PurpleChatMngr::CreateConversationCbk(PurpleConversation *conv, bool userCreated)
{
	PurpleAccount*			gAccount = purple_conversation_get_account(conv);
	PurpleConversationType	chatType = purple_conversation_get_type(conv);
	const char*				gPrclId  = purple_account_get_protocol_id(gAccount);
	IMAccount*				account  = _accountMngr->FindIMAccount(purple_account_get_username(gAccount), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));

	//VOXOX - JRT - 2009.07.20 - We seem to get a lot of crashes through here, via skype_find_chat.  I suspect account is not being found.
	if ( account == NULL )
	{
		std::string username = purple_account_get_username(gAccount);
		LOG_ERROR(" account == NULL for " + username + "\n");
	}

	PurpleIMChat*			mChat	 = FindIMChat(*account);
	mConvInfo_t*			mConv	 = NULL;

	if (chatType == PURPLE_CONV_TYPE_IM)
	{
		IMChatSession *chatSession = NULL;

		// Check if it's a jabber contact, remove the resource
		std::string contactId = cleanContactId(std::string(purple_conversation_get_name(conv)), PurpleIMPrcl::GetEnumIMProtocol(gPrclId));

		IMContact imContact(*account, contactId);

		mConv = mChat->CreateChatSession(userCreated, *mChat);
		mConv->purple_conv_session = conv;
 		conv->ui_data = mConv;

//		chatSession = (IMChatSession *) mConv->conv_session;
		chatSession = mConv->conv_session;	//VOXOX - JRT - 2009.07.09 - changed def from void* to IMChatSession*

		((IMContactSet &) chatSession->getIMContactSet()).insert(imContact);

		//VOXOX CHANGE CJC - validate if message don't have to be sent automatically
		if(userCreated)
		{
			if(mChat->getAutoMessage() != "")
			{
				mChat->newIMChatAndSendMessageSessionCreatedEvent(*mChat, *((IMChatSession *)(mConv->conv_session)),mChat->getAutoMessage(),true);
			}
			else 
			{
				switch( mChat->getIMChatType() )
				{
				case IMChat::ChatToEmail:
					mChat->newIMChatToEmailSessionCreatedEvent(*mChat, *(mConv->conv_session));	//VOXOX - JRT - 2009.07.09 
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				case IMChat::ChatToSMS:
					mChat->newIMChatToSMSSessionCreatedEvent(*mChat, *(mConv->conv_session));	//VOXOX - JRT - 2009.07.09 
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				case IMChat::Chat:
				case IMChat::ChatGroup:		//VOXOX - JRT - 2009.06.15 - we don't really expect this type.
					mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);
					mChat->contactAddedEvent(*mChat, *chatSession, imContact);
					break;

				default:
					assert(false);		//New IMChatType?
				}
			}	
		}
		else
		{
			mChat->newIMChatSessionCreatedEvent(*mChat, *chatSession);
			mChat->contactAddedEvent(*mChat, *chatSession, imContact);
		}

	}
	else if (chatType == PURPLE_CONV_TYPE_CHAT)
	{
//		int id = GetPurpleConversationId(purple_conversation_get_name(conv));	//VOXOX - JRT - 2009.06.16 - This does not work because it relies on CR name having ID as part of name.
//		int id = mChat->getGroupChatInfo().getId();

//		if ((mConv = mChat->FindChatStructById(id)) == NULL)
		if ((mConv = mChat->FindChatStructByName( conv->name )) == NULL)
		{
			mConv = mChat->CreateChatSession(userCreated, *mChat);

			IMChatSession* chatSession = mConv->conv_session;	//VOXOX - JRT - 2009.07.09 
			
			if ( chatSession )
			{
				chatSession->setIMChatType( IMChat::ChatGroup );

//				GroupChatInfo& gcInfo = chatSession->getIMChat().getGroupChatInfo();
				GroupChatInfo& gcInfo = chatSession->getGroupChatInfo();

				gcInfo.setId      ( mConv->conv_id );
				gcInfo.setChatRoom( conv->name     );
			}
		}

		if (mConv->purple_conv_session)
			purple_conversation_destroy(mConv->purple_conv_session);	//VOXOX - JRT - 2009.07.09 

		mConv->purple_conv_session = conv;
		conv->ui_data = mConv;
	}
}