Beispiel #1
0
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;
}
Beispiel #2
0
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 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;
}
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" &&
Beispiel #5
0
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);
    }
}
Beispiel #6
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 );
}
Beispiel #7
0
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 );
}