void History::updateCallDuration(int callId, int duration) { HistoryMemento * memento = _collection->getMementoByCallId(callId); if (memento) { memento->updateDuration(duration); unsigned id = _collection->getMementoId(memento); mementoUpdatedEvent(*this, id); } }
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; } }
bool History::loadChatLog(std::string chatlog, HistoryMementoCollection * hmc, std::string * userlogin, StringList * cuuidList) { // complete filename Config & config = ConfigManager::getInstance().getCurrentConfig(); std::string filename = File::convertPathSeparators( config.getConfigDir() + "chatlogs" + File::getPathSeparator() + _userProfile.getName() + File::getPathSeparator() + chatlog + ".xml" ); //// //open and read chat log FileReader file( filename ); if(!file.open()) { return false; } std::string lu = file.read(); std::stringstream ss(lu); boost::archive::xml_iarchive ia(ss); //// // contact int nbcontact = 0; ia >> BOOST_SERIALIZATION_NVP(nbcontact); for( int ic = 0; ic < nbcontact; ++ic) { std::string cuuid; ia >> BOOST_SERIALIZATION_NVP(cuuid); cuuidList->push_back(cuuid); } //user login ia >> BOOST_SERIALIZATION_NVP(*userlogin); //number of message int size = 0; ia >> BOOST_SERIALIZATION_NVP(size); //load every message std::string date, peer, data; for(int i = 0; i < size; ++i) { // // more compact serialization // //ia >> BOOST_SERIALIZATION_NVP(date); //ia >> BOOST_SERIALIZATION_NVP(peer); //ia >> BOOST_SERIALIZATION_NVP(data); //Date fdate( String(date.substr(8,2)).toInteger(), // String(date.substr(5,2)).toInteger(), // String(date.substr(0,4)).toInteger()); //Time ftime( String(date.substr(11,2)).toInteger(), // String(date.substr(14,2)).toInteger(), // String(date.substr(17,4)).toInteger()); //HistoryMemento* hm = new HistoryMemento(HistoryMemento::ChatSession, fdate, ftime, peer, -1, data); HistoryMemento* hm = new HistoryMemento(); hm->load(ia,HistoryMemento::SERIALIZATION_VERSION); /** duration -1 means it is an history message */ hm->updateDuration(-1); hmc->addMemento(hm); } return true; }