Beispiel #1
0
void Conversation::messageReceived(const QXmppMessage &msg)
{
    if (msg.type() != QXmppMessage::Chat ||
        QXmppUtils::jidToBareJid(msg.from()) != m_jid)
        return;

    // handle chat state
    if (msg.state() != m_remoteState) {
        m_remoteState = msg.state();
        emit remoteStateChanged(m_remoteState);
    }

    // handle message body
    if (msg.body().isEmpty())
        return;

    HistoryMessage message;
    message.body = msg.body();
    message.date = msg.stamp();
    if (!message.date.isValid())
        message.date = m_client->serverTime();
    message.jid = m_jid;
    message.received = true;
    if (m_historyModel)
        m_historyModel->addMessage(message);
}
Beispiel #2
0
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"));
}
Beispiel #3
0
void tst_QXmppMessage::testDelay()
{
    QFETCH(QByteArray, xml);
    QFETCH(QDateTime, stamp);

    QXmppMessage message;
    parsePacket(message, xml);
    QCOMPARE(message.stamp(), stamp);
    serializePacket(message, xml);
}
Beispiel #4
0
void tst_QXmppMessage::testDelayWithMultipleStamp()
{
    // the XEP-0203 should override XEP-0091's value since XEP-0091 was no more standard protocol
    QByteArray xml(
        "<message type=\"normal\">"
            "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06.123Z\"/>"
            "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>"
        "</message>");
    QByteArray resultXml(
        "<message type=\"normal\">"
            "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06.123Z\"/>"
        "</message>");

    QXmppMessage message;
    parsePacket(message, xml);
    qDebug() << message.stamp();
    QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6, 123), Qt::UTC));
    serializePacket(message, resultXml);
}
Beispiel #5
0
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);
}
Beispiel #6
0
void JabberChatService::handleReceivedMessage(const QXmppMessage &xmppMessage)
{
	if (!m_formattedStringFactory)
		return;

	m_chatStateService->extractReceivedChatState(xmppMessage);

	if (xmppMessage.body().isEmpty())
		return;

	if (xmppMessage.type() == QXmppMessage::Type::Error) // #1642
		return;

	auto message = xmppMessage.type() == QXmppMessage::GroupChat
		? m_roomChatService->handleReceivedMessage(xmppMessage)
		: handleNormalReceivedMessage(xmppMessage);
	if (message.isNull())
		return;

	message.setType(MessageTypeReceived);
	message.setSendDate(xmppMessage.stamp().toLocalTime());
	message.setReceiveDate(QDateTime::currentDateTime());

	auto body = xmppMessage.body();
	if (rawMessageTransformerService())
		body = QString::fromUtf8(rawMessageTransformerService()->transform(body.toUtf8(), message).rawContent());

	auto htmlBody = replacedNewLine(Qt::escape(body), QLatin1String("<br/>"));
	auto formattedString = m_formattedStringFactory.data()->fromHtml(htmlBody);
	if (!formattedString || formattedString->isEmpty())
		return;

	message.setContent(std::move(formattedString));

	auto id = xmppMessage.from();
	auto resourceIndex = id.indexOf('/');
	if (resourceIndex >= 0)
		id = id.mid(0, resourceIndex);
	m_contactMessageTypes.insert(id, xmppMessage.type());

	emit messageReceived(message);
}
Beispiel #7
0
void tst_QXmppMessage::testMessageCarbons()
{
    const QByteArray xml("<message type=\"normal\">"
        "<body>hi!</body>"
        "<sent xmlns='urn:xmpp:carbons:2'>"
        "<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>"
        "</sent>"
        "</message>");

    QXmppMessage message;
    parsePacket(message, xml);
    QCOMPARE(message.hasMessageCarbon(), true);

    QXmppMessage fwd = message.carbonMessage();
    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"));


    const QByteArray carbonXml("<iq id=\"id1\""
                               " type=\"set\">"
                                   "<enable xmlns=\"urn:xmpp:carbons:2\"/>"
                              "</iq>");

    QXmppMessageCarbonsIq carbonIq;
    carbonIq.setId("id1");
    serializePacket(carbonIq, carbonXml);
}