Esempio n. 1
0
void CUserProfile::makeContactCallThreadSafe(std::string contactId) {
	Contact * contact = _cContactList.getContact(contactId);
	
	if (contact) 
	{
		//VOXOXCHANGE CJC CALL VOXOX NUMBERS
		if(contact->getIsIMAccountVoxox())
		{
			//We don't get the number if we already have it//TODO CHANGE THIS IF NUMBERS ARE CHANGED FREQUENTLY
			if(!contact->getVoxOxPhone().empty())
			{
				EnumMakeCallError::MakeCallError error = _userProfile.makeCall(*contact);
				if (error != EnumMakeCallError::NoError) 
				{
					makeCallErrorEvent(*this, error, contact->getVoxOxPhone());//VOXOX CHANGE by Rolando - 2009.05.29 - added parameter phonenumber to check what call failed
				}
			}
			else
			{
				if(_userProfile.getWsContactNumber())
				{
					WsContactNumber & wsContactNumber = *_userProfile.getWsContactNumber();
					wsContactNumber.setContactId(contact->getKey());
					wsContactNumber.contactNumberEvent +=	boost::bind(&CUserProfile::contactNumberEventHandler, this, _1, _2, _3);
					wsContactNumber.execute();
				}
			}	

		}else if(contact->getQtIMProtocol() == QtEnumIMProtocol::IMProtocolSkype){
			_userProfile.makeCall(*contact);
		}
		else
		{
			EnumMakeCallError::MakeCallError error = _userProfile.makeCall(*contact);
			if (error != EnumMakeCallError::NoError) 
			{
				makeCallErrorEvent(*this, error, contactId);//VOXOX CHANGE by Rolando - 2009.05.29 - added parameter contactId to check what call failed
			}
		}
	}
	else
	{
		makeCallErrorEvent(*this, EnumMakeCallError::ContactNotFound, contactId);//VOXOX CHANGE by Rolando - 2009.05.29 - added parameter contactId to check what call failed
	}
}
Esempio n. 2
0
void History::removeChatMementoSession(IMChatSession * imchatSession) {
	int chatSessionID = imchatSession->getId();

	HistoryMementoCollection * collection = NULL;
	if((collection = _chatSessionsMementos[chatSessionID]) != NULL){
		//seek for history chat
		int nbhistory = 0;
		HistoryMap::iterator ithm;
		for (ithm = collection->begin(); ithm != collection->end(); ++ithm) {
			HistoryMemento* hm = ithm->second;

			// duration -1 means it is an history message
			if( hm->getDuration() != -1 ) {
				break;
			}
			++nbhistory;
		}
		////

		// don't save empty chat history
		int size = collection->size() - nbhistory;
		if(size>0) {
			//save chat log
			Date saveDate;
			Time saveTime;
			std::string peer = "";
			std::string filechat =	String::fromNumber(saveDate.getYear(), 2) + String::fromNumber(saveDate.getMonth(), 2) + 
									String::fromNumber(saveDate.getDay(), 2) + String::fromNumber(saveTime.getHour(), 2) + 
									String::fromNumber(saveTime.getMinute(), 2) + String::fromNumber(saveTime.getSecond(), 2)+
									"_" + String::fromNumber(chatSessionID);
			Config & config = ConfigManager::getInstance().getCurrentConfig();
			std::string saverep = File::convertPathSeparators( 
				config.getConfigDir() + "chatlogs" + File::getPathSeparator() 
				+ _userProfile.getName() + File::getPathSeparator() 
			);
			File::createPath(saverep);
			//save file should be unique
			while(File::exists(saverep + filechat + ".xml")) {
				filechat += "_f";
			}
			////
			FileWriter file(saverep + filechat+".xml");
			std::stringstream ss;
			bool serializedSuccessfully = false;
			try {
				boost::archive::xml_oarchive oa(ss);

				//constructs list of login per peer
				std::map<std::string, std::vector<std::string>*> aliasMap;
				IMContactSet contactSet = imchatSession->getIMContactSet();
				for (IMContactSet::const_iterator itc = contactSet.begin(); itc != contactSet.end(); ++itc) {
					Contact * thecontact = _userProfile.getContactList().findContactThatOwns(*itc);
					std::string cuuid = "unrecognized";
					if(thecontact) {
//						cuuid = thecontact->getUUID();
						cuuid = thecontact->getKey();	//VOXOX - JRT - 2009.04.28 
					}	

					if(aliasMap[cuuid] == NULL) {
						aliasMap[cuuid] = new std::vector<std::string>;
					}
//					aliasMap[cuuid]->push_back(itc->cleanContactId());	//VOXOX - JRT - 2009.04.10 
					aliasMap[cuuid]->push_back(itc->getCleanContactId());
				}
				////

				// saves number of peer in this chat
				int nbcontact = aliasMap.size();
				oa << BOOST_SERIALIZATION_NVP(nbcontact);
				////

				//links all peers to this chat
				for(std::map<std::string, std::vector<std::string>*>::const_iterator itam = aliasMap.begin();
					itam != aliasMap.end(); ++itam) {
				
					/** links peer -> chat */

					//filechat
					std::string tobewritten = "<chat>\n\t<id>"+filechat+"</id>\n";

					//different login used by this peer during this chat
					for(std::vector<std::string>::const_iterator itv = itam->second->begin(); itv != itam->second->end(); ++itv) {
						tobewritten += "\t<alias>" + (*itv) + "</alias>\n";
						
						peer += "," + (*itv);
					}
					
					////

					tobewritten += "</chat>\n";
					/////
	
					std::string cuuid = itam->first;
					FileWriter contactFile( saverep + cuuid + ".xml" );
					contactFile.setAppendMode(true);
					contactFile.write(tobewritten);

					/** links chat -> peer */
					oa << BOOST_SERIALIZATION_NVP(cuuid);
				}
				////

				// saves user login for this chat
				IMAccount * imAccount =
					_userProfile.getIMAccountManager().getIMAccount(imchatSession->getIMChat().getIMAccountId());
				std::string userlogin;
				if (imAccount) {
					userlogin = imAccount->getLogin();
					OWSAFE_DELETE(imAccount);
				} else {
					LOG_ERROR("cannot find the IMAccount");
				}
				oa << BOOST_SERIALIZATION_NVP(userlogin);
				////

				// saves size
				oa << BOOST_SERIALIZATION_NVP(size);

				// save all historymementos i.e. all message
				for (;ithm != collection->end(); ++ithm) {
					HistoryMemento* hm = ithm->second;

					//
					//	more compact serialization
					//
					//std::string date = hm->getDate().toString() + " " + hm->getTime().toString();
					//oa << BOOST_SERIALIZATION_NVP(date);
					//std::string peer = hm->getPeer();
					//oa << BOOST_SERIALIZATION_NVP(peer);
					//std::string data = hm->getData();
					//oa << BOOST_SERIALIZATION_NVP(data);

					hm->save(oa,HistoryMemento::SERIALIZATION_VERSION);

				}
				serializedSuccessfully = true;
			} catch (boost::archive::archive_exception & e) {
				LOG_DEBUG(e.what());
				file.write(String::null);
			}

			if (serializedSuccessfully) {
				// xml_oarchive write the end of the xml in its destructor.
				// This is why we do not write inside the try {} catch block
				// because we would write before the xml_oarchive object is
				// deleted.
				file.write(ss.str());
			}
			
			if (peer.size() > 1) {
				peer = peer.substr(1);
			}
			
			HistoryMemento * historyMemento = new HistoryMemento(HistoryMemento::ChatSession, saveDate, saveTime, peer, -1, filechat);
			historyMemento->updateDuration(0);
			_userProfile.getHistory().addMemento(historyMemento);
		}
		_chatSessionsMementos.erase(chatSessionID);
		delete collection;
	}
}