Ejemplo n.º 1
0
	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;
	}
Ejemplo n.º 2
0
bool XmppServerArchive::handleStanza(const QDomElement &element)
{
    const QString domain = server()->domain();
    const QString from = element.attribute("from");
    const QString to = element.attribute("to");

    if (element.tagName() == "message" &&
        to != domain &&
        (QXmppUtils::jidToDomain(from) == domain || QXmppUtils::jidToDomain(to) == domain) &&
        element.attribute("type") != "error" &&
        element.attribute("type") != "groupchat" &&
        element.attribute("type") != "headline" &&
        !element.firstChildElement("body").text().isEmpty())
    {
        const QDateTime now = QDateTime::currentDateTime().toUTC();
        QXmppMessage message;
        message.parse(element);

        if (QXmppUtils::jidToDomain(from) == domain)
            saveMessage(message, now, false);

        if (QXmppUtils::jidToDomain(to) == domain) {
            saveMessage(message, now, true);

            // offline messages
            bool found = false;

            XmppServerPresence *presenceExtension = XmppServerPresence::instance(server());
            Q_ASSERT(presenceExtension);
            foreach (const QXmppPresence &presence, presenceExtension->availablePresences(QXmppUtils::jidToBareJid(to))) {
                if (QXmppUtils::jidToResource(to).isEmpty() || presence.from() == to) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                message.setStamp(now);
                message.setState(QXmppMessage::None);
                message.setTo(QXmppUtils::jidToBareJid(to));

                QBuffer buffer;
                buffer.open(QIODevice::WriteOnly);
                QXmlStreamWriter writer(&buffer);
                message.toXml(&writer);

                OfflineMessage offline;
                offline.setData(QString::fromUtf8(buffer.data()));
                offline.setJid(QXmppUtils::jidToBareJid(to));
                offline.setStamp(now);
                offline.save();
                return true;
            }
        }

        return false;

    } else if (element.tagName() == "presence" &&
Ejemplo n.º 3
0
/* 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 );
}