bool QXmppCarbonManager::handleStanza(const QDomElement &element) { if(element.tagName() != "message") return false; bool sent = true; QDomElement carbon = element.firstChildElement("sent"); if(carbon.isNull()) { carbon = element.firstChildElement("received"); sent = false; } if(carbon.isNull() || carbon.namespaceURI() != ns_carbons) return false; // Neither sent nor received -> no carbon message QDomElement forwarded = carbon.firstChildElement("forwarded"); if(forwarded.isNull()) return false; QDomElement messageelement = forwarded.firstChildElement("message"); if(messageelement.isNull()) return false; QXmppMessage message; message.parse(messageelement); if(sent) emit messageSent(message); else emit messageReceived(message); return true; }
void RoomHandler::requestVoice () { QList<QXmppDataForm::Field> fields; QXmppDataForm::Field typeField (QXmppDataForm::Field::HiddenField); typeField.setKey ("FORM_TYPE"); typeField.setValue ("http://jabber.org/protocol/muc#request"); fields << typeField; QXmppDataForm::Field reqField (QXmppDataForm::Field::TextSingleField); reqField.setLabel ("Requested role"); reqField.setKey ("muc#role"); reqField.setValue ("participant"); fields << reqField; QXmppDataForm form; form.setType (QXmppDataForm::Submit); form.setFields (fields); QXmppMessage msg ("", Room_->jid ()); msg.setType (QXmppMessage::Normal); msg.setExtensions (XooxUtil::Form2XmppElem (form)); Account_->GetClientConnection ()->GetClient ()->sendPacket (msg); }
void tst_QXmppMessage::testProcessingHints() { const QByteArray xml("<message " "to=\"[email protected]/laptop\" " "from=\"[email protected]/laptop\" " "type=\"chat\">" "<body>V unir avtug'f pybnx gb uvqr zr sebz gurve fvtug</body>" "<no-copy xmlns=\"urn:xmpp:hints\"/>" "<no-store xmlns=\"urn:xmpp:hints\"/>" "<allow-permanent-storage xmlns=\"urn:xmpp:hints\"/>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.hasHint(QXmppMessage::NoCopies), true); QCOMPARE(message.hasHint(QXmppMessage::NoStorage), true); QCOMPARE(message.hasHint(QXmppMessage::AllowPermantStorage), true); QXmppMessage message2; message2.setType(QXmppMessage::Chat); message2.setFrom(QString("[email protected]/laptop")); message2.setTo(QString("[email protected]/laptop")); message2.setBody(QString("V unir avtug'f pybnx gb uvqr zr sebz gurve fvtug")); message2.addHint(QXmppMessage::NoCopies); message2.addHint(QXmppMessage::NoStorage); message2.addHint(QXmppMessage::AllowPermantStorage); serializePacket(message2, xml); }
void CFrmGroupChat::slotMessageReceived(const QXmppMessage &message) { LOG_MODEL_DEBUG("Group chat", "CFrmGroupChat::slotMessageReceived:type:%d;state:%d;from:%s;to:%s;body:%s", message.type(), message.state(), //消息的状态 0:消息内容,其它值表示这个消息的状态 qPrintable(message.from()), qPrintable(message.to()), qPrintable(message.body()) ); if(QXmppUtils::jidToBareJid(message.from()) != QXmppUtils::jidToBareJid(m_pRoom->jid())) { LOG_MODEL_DEBUG("Group chat", "the room is %s, from %s received", m_pRoom->jid().toStdString().c_str(), message.from().toStdString().c_str()); return; } if(message.body().isEmpty()) return; QString nick; nick = QXmppUtils::jidToResource(message.from()); if(nick.isEmpty()) nick = tr("System"); AppendMessageToList(message.body(), nick); }
bool Conversation::sendMessage(const QString &body) { if (body.isEmpty() || m_jid.isEmpty() || !m_client || !m_client->isConnected()) return false; // send message QXmppMessage message; message.setTo(m_jid); message.setBody(body); message.setState(QXmppMessage::Active); if (!m_client->sendPacket(message)) return false; // update state if (m_localState != QXmppMessage::Active) { m_localState = QXmppMessage::Active; emit localStateChanged(m_localState); } // add message to history if (m_historyModel) { HistoryMessage message; message.body = body; message.date = m_client->serverTime(); message.jid = m_client->configuration().jidBare(); message.received = false; m_historyModel->addMessage(message); } return true; }
QXmppMessage Forwarded2Message (const QXmppElement& wrapper) { const auto& forwardedElem = wrapper.tagName () == "forwarded" ? wrapper : wrapper.firstChildElement ("forwarded"); if (forwardedElem.isNull ()) return {}; const auto& messageElem = forwardedElem.firstChildElement ("message"); if (messageElem.isNull ()) return {}; QXmppMessage original; #if QXMPP_VERSION >= 0x000800 original.parse (messageElem.sourceDomElement ()); #else #warning "You won't have good forwarded messages, Message Archive Management and Message Carbons will look like crap." original.parse (XmppElem2DomElem (messageElem)); #endif auto delayElem = forwardedElem.firstChildElement ("delay"); if (!delayElem.isNull ()) { const auto& sourceDT = QXmppUtils::datetimeFromString (delayElem.attribute ("stamp")); original.setStamp (sourceDT.toLocalTime ()); } return original; }
static void saveMessage(const QXmppMessage &message, const QDateTime &now, bool received) { const QString localJid = QXmppUtils::jidToBareJid(received ? message.to() : message.from()); const QString remoteJid = QXmppUtils::jidToBareJid(received ? message.from() : message.to()); // get or create collection int chatId; QDjangoQuerySet<ArchiveMessage> qs; qs = qs.filter(QDjangoWhere("chat__jid", QDjangoWhere::Equals, localJid)); qs = qs.filter(QDjangoWhere("chat__with", QDjangoWhere::Equals, remoteJid)); qs = qs.orderBy(QStringList() << "-date").limit(0, 1); ArchiveMessage tmp; if (qs.size() > 0 && qs.at(0, &tmp) && tmp.date().secsTo(now) < 3600) { chatId = tmp.property("chat_id").toInt(); } else { ArchiveChat chat; chat.setJid(localJid); chat.setWith(remoteJid); chat.setStart(now); chat.save(); chatId = chat.pk().toInt(); } // save outgoing message ArchiveMessage msg; msg.setProperty("chat_id", chatId); msg.setBody(message.body()); msg.setDate(now); msg.setReceived(received); msg.save(); }
void Client::messageReceived(const QXmppMessage &message) { qDebug() << message.body(); QString from = message.from(); QString msg = message.body(); m_client->sendPacket(QXmppMessage("", from, "Your message: " + msg)); }
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { if (sender == ui->messagePlainTextEdit) { if (event->type() != QEvent::KeyPress) { return false; } QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) && (keyEvent->modifiers() & Qt::ShiftModifier) == 0) { QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed(); if (!messageText.isEmpty()) { #ifdef HAVE_QXMPP const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom(); QXmppMessage message; message.setTo(publicChatRoom->jid()); message.setType(QXmppMessage::GroupChat); message.setBody(messageText); XmppClient::getInstance().getXMPPClient().sendPacket(message); #endif // HAVE_QXMPP QTextCursor cursor = ui->messagePlainTextEdit->textCursor(); cursor.select(QTextCursor::Document); cursor.removeSelectedText(); } return true; } } else if (event->type() == QEvent::MouseButtonRelease) { QVariant userVar = sender->property("user"); if (userVar.isValid()) { AddressManager::getInstance().goToUser(userVar.toString()); return true; } } return QWidget::eventFilter(sender, event); }
void JabberChatStateService::extractReceivedChatState(const QXmppMessage &message) { auto jid = Jid::parse(message.from()); auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd); contact.addProperty("jabber:received-chat-state", static_cast<int>(message.state()), CustomProperties::NonStorable); emit peerStateChanged(contact, xmppStateToState(message.state())); }
void EntryBase::HandleAttentionMessage (const QXmppMessage& msg) { QString jid; QString resource; ClientConnection::Split (msg.from (), &jid, &resource); emit attentionDrawn (msg.body (), resource); }
QXmppMessage JabberChatStateService::withSentChatState(QXmppMessage message) { auto jid = Jid::parse(message.to()); auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd); message.setState(QXmppMessage::State::Active); contact.addProperty("jabber:sent-chat-state", static_cast<int>(QXmppMessage::State::Active), CustomProperties::NonStorable); return message; }
void QxmppPeer::messageReceived(const QXmppMessage& message) { QString from = message.from(); QString msg = message.body(); //sendPacket( QXmppMessage("", from, "Your message: " + msg) ); if ( !m_messageHandler.empty() ) m_messageHandler( from.toStdString(), msg.toStdString() ); }
void tst_QXmppMessage::testDelay() { QFETCH(QByteArray, xml); QFETCH(QDateTime, stamp); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.stamp(), stamp); serializePacket(message, xml); }
void tst_QXmppMessage::testState() { QFETCH(QByteArray, xml); QFETCH(int, state); QXmppMessage message; parsePacket(message, xml); QCOMPARE(int(message.state()), state); serializePacket(message, xml); }
void tst_QXmppMessage::testReplaceWithEmptyMessage() { const QByteArray replaceXml( "<message to='[email protected]/balcony' id='good1'>" "<body/>" "<replace id='bad1' xmlns='urn:xmpp:message-correct:0'/>" "</message>"); QXmppMessage replaceMessage; parsePacket(replaceMessage, replaceXml); QCOMPARE(replaceMessage.isReplace(), true); QCOMPARE(replaceMessage.replaceId(), QString("bad1")); QCOMPARE(replaceMessage.body(), QString("")); const QByteArray replaceSerialisation( "<message id=\"good1\" to=\"[email protected]/balcony\" type=\"chat\">" "<body/>" "<replace id=\"bad1\" xmlns=\"urn:xmpp:message-correct:0\"/>" "</message>"); QXmppMessage serialisationMessage; serialisationMessage.setTo("[email protected]/balcony"); serialisationMessage.setId("good1"); serialisationMessage.setBody(""); serialisationMessage.setReplace("bad1"); serializePacket(serialisationMessage, replaceSerialisation); }
void TestPackets::testMessage() { const QByteArray xml( "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\"/>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.to(), QString("[email protected]/QXmpp")); QCOMPARE(message.from(), QString("[email protected]/QXmpp")); serializePacket(message, xml); }
void TestPackets::testMessageLegacyDelay() { const QByteArray xml( "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">" "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC)); serializePacket(message, xml); }
void EntryBase::DrawAttention (const QString& text, const QString& variant) { const QString& to = variant.isEmpty () ? GetJID () : GetJID () + '/' + variant; QXmppMessage msg; msg.setBody (text); msg.setTo (to); msg.setType (QXmppMessage::Headline); msg.setAttentionRequested (true); Account_->GetClientConnection ()->GetClient ()->sendPacket (msg); }
void Xmpp_client::messageReceived(const QXmppMessage& message) { qDebug() << "Xmpp_client::messageReceived !!!"; QString from = message.from(); QByteArray msg = QByteArray::fromBase64(message.body().toUtf8()); qDebug() << "RECEIVE from : " << from << " MESSAGE : " << msg; }
bool QXmppSimpleArchiveManager::handleStanza(const QDomElement &element) { bool isIq = (element.tagName() == "iq"); if (!isIq && (element.tagName() != "message")) { return false; } // XEP-0313: Message Archiving if(isIq && !QXmppSimpleArchiveQueryIq::isSimpleArchiveQueryIq(element)) { return false; } if (isIq && (element.attribute("type") == "result")) { QString id = element.attribute("id"); if (m_pendingQueries.contains(id)) { PendingQuery pendingQuery = m_pendingQueries.value(id); m_pendingQueries.remove(id); QXmppSimpleArchiveQueryIq packet; packet.parse(element); emit archiveMessagesReceived(pendingQuery.jid, pendingQuery.messages, packet.resultSetReply()); return true; } } else if (isIq && (element.attribute("type") == "error")) { QDomElement queryElement = element.firstChildElement("query"); if (!queryElement.isNull()) { QString queryId = queryElement.attribute("queryid"); if (m_pendingQueries.contains(queryId)) { PendingQuery pendingQuery = m_pendingQueries.value(queryId); m_pendingQueries.remove(queryId); emit archiveMessagesReceived(pendingQuery.jid, pendingQuery.messages, QXmppResultSetReply()); return true; } } } else { // message, check for result UUID + query ID QDomElement resultElement = element.firstChildElement("result"); if (!resultElement.isNull()) { QString queryId = resultElement.attribute("queryid"); if (m_pendingQueries.contains(queryId)) { QXmppMessage msg; msg.parse(element); m_pendingQueries[queryId].messages.append(msg.mamMessage()); return true; } else { qWarning() << "SimpleArchiveManager: unknown query ID:" << queryId; } } } return false; }
void MainWindow::messageReceived(const QXmppMessage &msg) { // qDebug() << msg.body(); if (msg.body().isEmpty()) return; UserChatDialog *dialog = userChatDialog(QXmppUtils::jidToBareJid(msg.from())); if (dialog) { dialog->show(); dialog->messageReceived(msg.body()); } }
void ChatExtension::HandleMessageReceived(const QXmppMessage &message) { if(message.type() == QXmppMessage::GroupChat) return; QString sender_jid = jidToBareJid(message.from()); QString msg = message.body(); LogInfo("XMPPModule: Received message. From: " + sender_jid.toStdString() + " Body: " + msg.toStdString()); emit MessageReceived(sender_jid, msg); }
void QXmppDeliveryReceiptsManager::sendReceipt(const QString &jid, const QString &id) { QXmppMessage msg; msg.setTo(jid); QXmppElement elem; elem.setTagName("received"); elem.setAttribute("xmlns", ns_message_receipts); elem.setAttribute("id", id); msg.setExtensions(QXmppElementList(elem)); client()->sendPacket(msg); }
void tst_QXmppMessage::testForwarding() { const QByteArray xml("<message type=\"normal\">" "<body>hi!</body>" "<forwarded xmlns=\"urn:xmpp:forward:0\">" "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06Z\"/>" "<message xmlns=\"jabber:client\" " "type=\"chat\" " "from=\"[email protected]/QXmpp\" " "to=\"[email protected]/QXmpp\">" "<body>ABC</body>" "</message>" "</forwarded>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.hasForwarded(), true); QXmppMessage fwd = message.forwarded(); QCOMPARE(fwd.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC)); QCOMPARE(fwd.body(), QString("ABC")); QCOMPARE(fwd.to(), QString("[email protected]/QXmpp")); QCOMPARE(fwd.from(), QString("[email protected]/QXmpp")); }
void tst_QXmppMessage::testMucInvitation() { QByteArray xml( "<message to=\"[email protected]\" from=\"[email protected]/desktop\" type=\"normal\">" "<x xmlns=\"jabber:x:conference\" jid=\"[email protected]\" password=\"cauldronburn\" reason=\"Hey Hecate, this is the place for all good witches!\"/>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.mucInvitationJid(), QLatin1String("*****@*****.**")); QCOMPARE(message.mucInvitationPassword(), QLatin1String("cauldronburn")); QCOMPARE(message.mucInvitationReason(), QLatin1String("Hey Hecate, this is the place for all good witches!")); serializePacket(message, xml); }
void Conversation::setLocalState(int state) { if (state != m_localState) { m_localState = static_cast<QXmppMessage::State>(state); // notify state change if (m_client) { QXmppMessage message; message.setTo(m_jid); message.setState(m_localState); m_client->sendPacket(message); } emit localStateChanged(m_localState); } }
void tst_QXmppMessage::testAmp() { const QByteArray xml("<message type=\"normal\">" "<body>hi!</body>" "<amp status=\"notify\" xmlns=\"http://jabber.org/protocol/amp' to='13323@u1\">" "<rule action=\"notify\" condition=\"deliver\" value=\"stored\"/>" "<rule action=\"notify\" condition=\"deliver\" value=\"none\"/>" "</amp>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.isAmp(), true); // QCOMPARE(message.xhtml(), QLatin1String("<p style=\"font-weight:bold\">hi!</p>")); serializePacket(message, xml); }
void tst_QXmppMessage::testXhtml() { const QByteArray xml("<message type=\"normal\">" "<body>hi!</body>" "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" "<body xmlns=\"http://www.w3.org/1999/xhtml\">" "<p style=\"font-weight:bold\">hi!</p>" "</body>" "</html>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.xhtml(), QLatin1String("<p style=\"font-weight:bold\">hi!</p>")); serializePacket(message, xml); }
void UnreadMessageModel::add(const QXmppMessage &message) { m_messageStore[QXmppUtils::jidToBareJid(message.from())] << message; //modification to reset() function, to match qt5, I don't know what really reset() does, to improve QTextStream newclass; newclass.reset(); ////////// }