bool MyXmppClient::sendMyMessage(QString bareJid, QString resource, QString msgBody) //Q_INVOKABLE { if (msgBody == "" || m_stateConnect != Connected) return false; // if message is empty or user not connected - BREAK QXmppMessage xmppMsg; QString jid_from = bareJid; if( resource == "" ) jid_from += "/resource"; else jid_from += "/" + resource; xmppMsg.setTo( jid_from ); QString jid_to = m_myjid + "/" + xmppClient->configuration().resource(); xmppMsg.setFrom( jid_to ); xmppMsg.setBody( msgBody ); xmppMsg.setState( QXmppMessage::Active ); xmppClient->sendPacket( xmppMsg ); this->messageReceivedSlot( xmppMsg ); emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.to()),msgBody,QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),1); return true; }
/* it sends information about typing : typing is stoped */ void MyXmppClient::typingStop(QString bareJid, QString resource) { qDebug() << bareJid << " " << "stop typing..."; QXmppMessage xmppMsg; QString jid_to = bareJid; if( resource == "" ) jid_to += "/resource"; else jid_to += "/" + resource; xmppMsg.setTo( jid_to ); QString jid_from = m_myjid + "/" + xmppClient->configuration().resource(); xmppMsg.setFrom( jid_from ); xmppMsg.setReceiptRequested( false ); QDateTime currTime = QDateTime::currentDateTime(); xmppMsg.setStamp( currTime ); xmppMsg.setState( QXmppMessage::Paused ); xmppClient->sendPacket( xmppMsg ); }
void MyXmppClient::attentionSend( QString bareJid, QString resource ) { qDebug() << "MyXmppClient::attentionSend(" << bareJid << ";" << resource << ")"; QXmppMessage xmppMsg; QString jid_to = bareJid; if( resource == "" ) { jid_to += "/resource"; } else { jid_to += "/" + resource; } xmppMsg.setTo( jid_to ); QString jid_from = m_myjid + "/" + xmppClient->configuration().resource(); xmppMsg.setFrom( jid_from ); xmppMsg.setReceiptRequested( false ); xmppMsg.setState( QXmppMessage::None ); xmppMsg.setType( QXmppMessage::Headline ); xmppMsg.setAttentionRequested( true ); xmppClient->sendPacket( xmppMsg ); }
void tst_QXmppMessage::testChatMarkers() { const QByteArray markableXml( "<message " "from='[email protected]/westminster' " "id='message-1' " "to='[email protected]/throne'>" "<thread>sleeping</thread>" "<body>My lord, dispatch; read o'er these articles.</body>" "<markable xmlns='urn:xmpp:chat-markers:0'/>" "</message>"); QXmppMessage markableMessage; parsePacket(markableMessage, markableXml); QCOMPARE(markableMessage.isMarkable(), true); QCOMPARE(markableMessage.marker(), QXmppMessage::NoMarker); QCOMPARE(markableMessage.id(), QString("message-1")); QCOMPARE(markableMessage.markedId(), QString()); QCOMPARE(markableMessage.thread(), QString("sleeping")); QCOMPARE(markableMessage.markedThread(), QString()); const QByteArray receivedXml( "<message " "from='[email protected]/throne' " "id='message-2' " "to='[email protected]/westminster'>" "<received xmlns='urn:xmpp:chat-markers:0' " "id='message-1' " "thread='sleeping'/>" "</message>"); QXmppMessage receivedMessage; parsePacket(receivedMessage, receivedXml); QCOMPARE(receivedMessage.isMarkable(), false); QCOMPARE(receivedMessage.marker(), QXmppMessage::Received); QCOMPARE(receivedMessage.id(), QString("message-2")); QCOMPARE(receivedMessage.markedId(), QString("message-1")); QCOMPARE(receivedMessage.thread(), QString()); QCOMPARE(receivedMessage.markedThread(), QString("sleeping")); const QByteArray displayedXml( "<message " "from='[email protected]/throne' " "id='message-2' " "to='[email protected]/westminster'>" "<displayed xmlns='urn:xmpp:chat-markers:0' " "id='message-1' " "thread='sleeping'/>" "</message>"); QXmppMessage displayedMessage; parsePacket(displayedMessage, displayedXml); QCOMPARE(displayedMessage.isMarkable(), false); QCOMPARE(displayedMessage.marker(), QXmppMessage::Displayed); QCOMPARE(displayedMessage.id(), QString("message-2")); QCOMPARE(displayedMessage.markedId(), QString("message-1")); QCOMPARE(displayedMessage.thread(), QString()); QCOMPARE(displayedMessage.markedThread(), QString("sleeping")); const QByteArray acknowledgedXml( "<message " "from='[email protected]/throne' " "id='message-2' " "to='[email protected]/westminster'>" "<acknowledged xmlns='urn:xmpp:chat-markers:0' " "id='message-1' " "thread='sleeping'/>" "</message>"); QXmppMessage acknowledgedMessage; parsePacket(acknowledgedMessage, acknowledgedXml); QCOMPARE(acknowledgedMessage.isMarkable(), false); QCOMPARE(acknowledgedMessage.marker(), QXmppMessage::Acknowledged); QCOMPARE(acknowledgedMessage.id(), QString("message-2")); QCOMPARE(acknowledgedMessage.markedId(), QString("message-1")); QCOMPARE(acknowledgedMessage.thread(), QString()); QCOMPARE(acknowledgedMessage.markedThread(), QString("sleeping")); const QByteArray emptyThreadXml( "<message " "from='[email protected]/throne' " "id='message-2' " "to='[email protected]/westminster'>" "<received xmlns='urn:xmpp:chat-markers:0' " "id='message-1'/>" "</message>"); QXmppMessage emptyThreadMessage; parsePacket(emptyThreadMessage, emptyThreadXml); QCOMPARE(emptyThreadMessage.isMarkable(), false); QCOMPARE(emptyThreadMessage.marker(), QXmppMessage::Received); QCOMPARE(emptyThreadMessage.id(), QString("message-2")); QCOMPARE(emptyThreadMessage.markedId(), QString("message-1")); QCOMPARE(emptyThreadMessage.thread(), QString()); QCOMPARE(emptyThreadMessage.markedThread(), QString()); const QByteArray notMarkableSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\"/>"); QXmppMessage serialisationMessage; serialisationMessage.setFrom("[email protected]/throne"); serialisationMessage.setTo("[email protected]/westminster"); serialisationMessage.setId("message-3"); serialisationMessage.setMarkable(false); serializePacket(serialisationMessage, notMarkableSerialisation); const QByteArray markableSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\">" "<markable xmlns=\"urn:xmpp:chat-markers:0\"/>" "</message>"); serialisationMessage.setMarkable(true); serializePacket(serialisationMessage, markableSerialisation); const QByteArray receivedSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\">" "<received xmlns=\"urn:xmpp:chat-markers:0\" " "id=\"message-2\"/>" "</message>"); serialisationMessage.setMarkable(false); serialisationMessage.setMarker(QXmppMessage::Received, "message-2"); serializePacket(serialisationMessage, receivedSerialisation); const QByteArray receivedThreadSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\">" "<received xmlns=\"urn:xmpp:chat-markers:0\" " "id=\"message-2\" " "thread=\"sleeping\"/>" "</message>"); serialisationMessage.setMarker(QXmppMessage::Received, "message-2", "sleeping"); serializePacket(serialisationMessage, receivedThreadSerialisation); const QByteArray displayedThreadSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\">" "<displayed xmlns=\"urn:xmpp:chat-markers:0\" " "id=\"message-2\" " "thread=\"sleeping\"/>" "</message>"); serialisationMessage.setMarker(QXmppMessage::Displayed, "message-2", "sleeping"); serializePacket(serialisationMessage, displayedThreadSerialisation); const QByteArray acknowledgedThreadSerialisation( "<message " "id=\"message-3\" " "to=\"[email protected]/westminster\" " "from=\"[email protected]/throne\" " "type=\"chat\">" "<acknowledged xmlns=\"urn:xmpp:chat-markers:0\" " "id=\"message-2\" " "thread=\"sleeping\"/>" "</message>"); serialisationMessage.setMarker(QXmppMessage::Acknowledged, "message-2", "sleeping"); serializePacket(serialisationMessage, acknowledgedThreadSerialisation); }