QString MyXmppClient::getPropertyByJid( QString bareJid, QString property ) { RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid ); if (item != 0) { if (property == "name") return item->name(); else if (property == "presence") return item->presence(); else if (property == "resource") return item->resource(); else if (property == "statusText") return item->statusText(); else if (property == "unreadMsg") return QString::number(item->unreadMsg()); } else return "(unknown)"; }
void MyXmppClient::messageReceivedSlot( const QXmppMessage &xmppMsg ) { QString bareJid_from = MyXmppClient::getBareJidByJid( xmppMsg.from() ); QString bareJid_to = MyXmppClient::getBareJidByJid( xmppMsg.to() ); if( xmppMsg.state() == QXmppMessage::Active ) qDebug() << "Msg state is QXmppMessage::Active"; else if( xmppMsg.state() == QXmppMessage::Inactive ) qDebug() << "Msg state is QXmppMessage::Inactive"; else if( xmppMsg.state() == QXmppMessage::Gone ) qDebug() << "Msg state is QXmppMessage::Gone"; else if( xmppMsg.state() == QXmppMessage::Composing ) { if (bareJid_from != "") { m_flTyping = true; emit typingChanged(m_accountId,bareJid_from, true); qDebug() << bareJid_from << " is composing."; } } else if( xmppMsg.state() == QXmppMessage::Paused ) { if (bareJid_from != "") { m_flTyping = false; emit typingChanged(m_accountId,bareJid_from, false); qDebug() << bareJid_from << " paused."; } } else { if( xmppMsg.isAttentionRequested() ) { //qDebug() << "ZZZ: attentionRequest !!! from:" <<xmppMsg.from(); //msgWrapper->attention( bareJid_from, false ); } qDebug() << "MessageWrapper::messageReceived(): xmppMsg.state():" << xmppMsg.state(); } if ( !( xmppMsg.body().isEmpty() || xmppMsg.body().isNull() || bareJid_from == m_myjid ) ) { m_bareJidLastMessage = getBareJidByJid(xmppMsg.from()); m_resourceLastMessage = getResourceByJid(xmppMsg.from()); this->openChat( bareJid_from ); RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid_from ); if( item != 0 ) { int cnt = item->unreadMsg(); item->setUnreadMsg( ++cnt ); } else { RosterItemModel *itemModel = new RosterItemModel( ); itemModel->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) ); itemModel->setContactName( bareJid_from ); itemModel->setJid( bareJid_from ); itemModel->setUnreadMsg( 1 ); itemModel->setStatusText( ""); cachedRoster->append(itemModel); itemModel = 0; delete itemModel; } item = 0; delete item; emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.from()),xmppMsg.body(),QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),0); } }