//"#COMMAND#type=fileRequest,packId=xxx" void CMsgSessionManager::SendCmd(tstring strDestAccount, ECmdType eType, tstring& strParas) { //check if session exist; MessageSession* pDestSesion = NULL; MapAccount2Sessions::iterator itFind = m_mapAccount2Sessions.find(strDestAccount); if (itFind != m_mapAccount2Sessions.end()) { pDestSesion = itFind->second; } if (NULL == pDestSesion) { JID jid(strDestAccount); pDestSesion = new MessageSession(j, jid); if (NULL != pDestSesion) { pDestSesion->registerMessageHandler(this); m_mapAccount2Sessions.insert(make_pair(strDestAccount, pDestSesion)); } } if (NULL != pDestSesion) { pDestSesion->send(strParas.c_str()); } }
MessageSession* Core::create_session(const string bare){ MessageSession* session = new MessageSession(ptr_cpclient->get_client(),bare); //session->setThreadID("session_" + bare); ptr_cpclient->store_session(session); ptr_cpclient->register_session(session); session->registerMessageHandler(this); write_string("A new chat session is created with JID: " + session->target().full()); return session; }
void CMsgSessionManager::SendMsg(tstring strDestAccount, tstring& strMsg) { //check if session exist; MessageSession* pDestSesion = NULL; MapAccount2Sessions::iterator itFind = m_mapAccount2Sessions.find(strDestAccount); if (itFind != m_mapAccount2Sessions.end()) { pDestSesion = itFind->second; } if (NULL == pDestSesion) { JID jid(strDestAccount); pDestSesion = new MessageSession(j, jid); if (NULL != pDestSesion) { pDestSesion->registerMessageHandler(this); m_mapAccount2Sessions.insert(make_pair(strDestAccount, pDestSesion)); } } if (NULL != pDestSesion) { MapMsgEventFilters::iterator itMsgFiler = m_mapDest2MsgEventFilters.find(strDestAccount); if (itMsgFiler != m_mapDest2MsgEventFilters.end()) { MessageEventFilter*pFilter = itMsgFiler->second; if (NULL != pFilter) { pFilter->raiseMessageEvent(MessageEventComposing); } } MapChatStateFilters::iterator itStatefilter = m_mapDest2ChatStateFilters.find(strDestAccount); if (itStatefilter != m_mapDest2ChatStateFilters.end()) { ChatStateFilter* pFilter = itStatefilter->second; if (NULL != pFilter) { pFilter->setChatState(ChatStateComposing); } } tstring strOut; CChineseCode::GB2312ToUTF_8(strOut, (char*)strMsg.c_str(), strMsg.size()); pDestSesion->send(/*strMsg*/strOut, ""); } }
void MessageSessionManager::handleMessage(const Message &message) { Q_D(MessageSessionManager); QList<QPointer<MessageSession> > sessions = d->fullSessions.values(message.from()); for(int i = 0; i < sessions.size(); i++) { if(sessions[i].isNull()) { d->fullSessions.remove(message.from(), sessions[i]); continue; } if(message.thread().isEmpty() || sessions[i]->ignoreThread() || sessions[i]->thread() == message.thread()) { sessions[i]->handleMessage(message); return; } } sessions = d->bareSessions.values(message.from().bare()); for(int i = 0; i < sessions.size(); i++) { if(sessions[i].isNull()) { d->bareSessions.remove(message.from(), sessions[i]); continue; } if(message.thread().isEmpty() || sessions[i]->ignoreThread() || sessions[i]->thread() == message.thread()) { sessions[i]->handleMessage(message); return; } } MessageSessionHandler *handler = d->sessionHandlers.value(message.subtype()); if(!handler) { emit messageReceived(message); return; } MessageSession *session = new MessageSession(this, message.from(), false, message.thread()); handler->handleMessageSession(session); session->handleMessage(message); }
//following function is used for sending async-event-notification to subscribed buddy bool ADXmppProxy::SendMessageToBuddy(std::string address, const std::string & body, const std::string & subject) { //for testing async-sync event //XmppProxy.SendMessageToBuddy(cmdArg,"hellloooo","test-subjext"); //return RPC_SRV_RESULT_SUCCESS; if(iConnect==false) { if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:client disconnected, cannot send message to buddy!!!"<<endl; return false; } //check if address is in my buddy-list(doesnt make sense to send message to non-buddy - it will not be delivered) vector<std::string>::iterator it; for(it = BuddyList.begin(); it != BuddyList.end(); it++) { string str = *it; if(address==str) { Sessions::iterator it = mySessions.find(address); if (it != mySessions.end()) //check if session already exists in my list { it->second.m_messageEventFilter->raiseMessageEvent( MessageEventDisplayed ); it->second.m_messageEventFilter->raiseMessageEvent( MessageEventComposing ); it->second.m_chatStateFilter->setChatState( ChatStateComposing ); it->second.m_session->send( body, subject);//gloox::EmptyString ); if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:address="<<address<<" body="<<body<<" subject="<<subject<<endl; } else //if session doesnt exist in my list, then create new session and send the message { MessageSession* session = new MessageSession(j,JID(address)); session->send(body, subject);//todo: presence check needed before sending message? j->disposeMessageSession( session ); if(DebugLog) cout<<"ADXmppProxy::SendMessageToBuddy:address="<<address<<" body="<<body<<" subject="<<subject<<endl; } return true; } } return false;//address is not in my buddy-list }
void MessageFilter::send( Message& msg ) { m_parent->send( msg ); }