Пример #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;
}
Пример #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;
}
Пример #3
0
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);
}
Пример #4
0
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);
}
Пример #5
0
	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);
	}