void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick) { const bool existed = Nick2Entry_.contains (nick); RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false); if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ()) { if (msg.state ()) entry->UpdateChatState (msg.state (), QString ()); if (!msg.body ().isEmpty ()) { GlooxMessage *message = new GlooxMessage (msg, Account_->GetClientConnection ().get ()); entry->HandleMessage (message); } } else { RoomPublicMessage *message = 0; if (msg.type () == QXmppMessage::GroupChat && !msg.subject ().isEmpty ()) { Subject_ = msg.subject (); CLEntry_->HandleSubjectChanged (Subject_); const QString& string = nick.isEmpty () ? msg.subject () : tr ("%1 changed subject to %2") .arg (nick) .arg (msg.subject ()); message = new RoomPublicMessage (string, IMessage::DIn, CLEntry_, IMessage::MTEventMessage, IMessage::MSTOther); } else if (!nick.isEmpty ()) { if (!msg.body ().isEmpty ()) message = new RoomPublicMessage (msg, CLEntry_, entry); } else message = new RoomPublicMessage (msg.body (), IMessage::DIn, CLEntry_, IMessage::MTEventMessage, IMessage::MSTOther); if (message) CLEntry_->HandleMessage (message); if (!existed) Nick2Entry_.remove (nick); } }
void tst_QXmppMessage::testBasic() { QFETCH(QByteArray, xml); QFETCH(int, type); QFETCH(QString, body); QFETCH(QString, subject); QFETCH(QString, thread); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.to(), QString("[email protected]/QXmpp")); QCOMPARE(message.from(), QString("[email protected]/QXmpp")); QVERIFY(message.extendedAddresses().isEmpty()); QCOMPARE(int(message.type()), type); QCOMPARE(message.body(), body); QCOMPARE(message.subject(), subject); QCOMPARE(message.thread(), thread); QCOMPARE(message.state(), QXmppMessage::None); QCOMPARE(message.isAttentionRequested(), false); QCOMPARE(message.isReceiptRequested(), false); QCOMPARE(message.hasForwarded(), false); QCOMPARE(message.receiptId(), QString()); QCOMPARE(message.xhtml(), QString()); serializePacket(message, xml); }
void TestPackets::testMessageFull() { const QByteArray xml( "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">" "<subject>test subject</subject>" "<body>test body & stuff</body>" "<thread>test thread</thread>" "<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>" "</message>"); QXmppMessage message; parsePacket(message, xml); QCOMPARE(message.to(), QString("[email protected]/QXmpp")); QCOMPARE(message.from(), QString("[email protected]/QXmpp")); QCOMPARE(message.type(), QXmppMessage::Normal); QCOMPARE(message.body(), QString("test body & stuff")); QCOMPARE(message.subject(), QString("test subject")); QCOMPARE(message.thread(), QString("test thread")); QCOMPARE(message.state(), QXmppMessage::Composing); serializePacket(message, xml); }
void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick) { Q_FOREACH (const QXmppElement& elem, msg.extensions ()) { const QString& xmlns = elem.attribute ("xmlns"); if (xmlns == ns_data) { QXmppDataForm *df = new QXmppDataForm (); df->parse (XooxUtil::XmppElem2DomElem (elem)); if (df->isNull ()) { qWarning () << Q_FUNC_INFO << "unable to parse form from" << msg.from (); delete df; } else emit gotPendingForm (df, msg.from ()); } else qWarning () << Q_FUNC_INFO << "unhandled <x> element" << xmlns; } const bool existed = Nick2Entry_.contains (nick); RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false); if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ()) { if (msg.isAttentionRequested ()) entry->HandleAttentionMessage (msg); if (msg.state ()) entry->UpdateChatState (msg.state (), QString ()); if (!msg.body ().isEmpty ()) { GlooxMessage *message = new GlooxMessage (msg, Account_->GetClientConnection ().get ()); entry->HandleMessage (message); } } else { RoomPublicMessage *message = 0; if (msg.type () == QXmppMessage::GroupChat && !msg.subject ().isEmpty ()) { Subject_ = msg.subject (); CLEntry_->HandleSubjectChanged (Subject_); const QString& string = nick.isEmpty () ? msg.subject () : tr ("%1 changed subject to %2") .arg (nick) .arg (msg.subject ()); message = new RoomPublicMessage (string, IMessage::DIn, CLEntry_, IMessage::MTEventMessage, IMessage::MSTOther); } else if (!nick.isEmpty ()) { if (!msg.body ().isEmpty ()) message = new RoomPublicMessage (msg, CLEntry_, entry); } else if (!msg.body ().isEmpty ()) message = new RoomPublicMessage (msg.body (), IMessage::DIn, CLEntry_, IMessage::MTEventMessage, IMessage::MSTOther); if (message) CLEntry_->HandleMessage (message); if (!existed) Nick2Entry_.remove (nick); } }