bool QXmppMessageReceiptManager::handleStanza(const QDomElement &stanza)
{
    if (stanza.tagName() != "message")
        return false;

    QXmppMessage message;
    message.parse(stanza);

    // Handle receipts and cancel any further processing.
    if (!message.receiptId().isEmpty()) {
        Q_EMIT messageDelivered(message.from(), message.receiptId());
        return true;
    }

    // If requested, send a receipt.
    if (message.isReceiptRequested()
        && !message.from().isEmpty()
        && !message.id().isEmpty()) {
        QXmppMessage receipt;
        receipt.setTo(message.from());
        receipt.setReceiptId(message.id());
        client()->sendPacket(receipt);
    }

    // Continue processing.
    return false;
}
Пример #2
0
static void saveMessage(const QXmppMessage &message, const QDateTime &now, bool received)
{
    const QString localJid = QXmppUtils::jidToBareJid(received ? message.to() : message.from());
    const QString remoteJid = QXmppUtils::jidToBareJid(received ? message.from() : message.to());

    // get or create collection
    int chatId;
    QDjangoQuerySet<ArchiveMessage> qs;
    qs = qs.filter(QDjangoWhere("chat__jid", QDjangoWhere::Equals, localJid));
    qs = qs.filter(QDjangoWhere("chat__with", QDjangoWhere::Equals, remoteJid));
    qs = qs.orderBy(QStringList() << "-date").limit(0, 1);
    ArchiveMessage tmp;
    if (qs.size() > 0 && qs.at(0, &tmp) && tmp.date().secsTo(now) < 3600) {
        chatId = tmp.property("chat_id").toInt();
    } else {
        ArchiveChat chat;
        chat.setJid(localJid);
        chat.setWith(remoteJid);
        chat.setStart(now);
        chat.save();
        chatId = chat.pk().toInt();
    }

    // save outgoing message
    ArchiveMessage msg;
    msg.setProperty("chat_id", chatId);
    msg.setBody(message.body());
    msg.setDate(now);
    msg.setReceived(received);
    msg.save();
}
Пример #3
0
void CFrmGroupChat::slotMessageReceived(const QXmppMessage &message)
{
    LOG_MODEL_DEBUG("Group chat", "CFrmGroupChat::slotMessageReceived:type:%d;state:%d;from:%s;to:%s;body:%s",
           message.type(),
           message.state(), //消息的状态 0:消息内容,其它值表示这个消息的状态  
           qPrintable(message.from()),
           qPrintable(message.to()),
           qPrintable(message.body())
          );

    if(QXmppUtils::jidToBareJid(message.from()) != QXmppUtils::jidToBareJid(m_pRoom->jid()))
    {
        LOG_MODEL_DEBUG("Group chat", "the room is %s, from %s received",
                        m_pRoom->jid().toStdString().c_str(),
                        message.from().toStdString().c_str());
        return;
    }

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

    QString nick;
    nick = QXmppUtils::jidToResource(message.from());
    if(nick.isEmpty())
        nick = tr("System");
    AppendMessageToList(message.body(), nick);
}
Пример #4
0
void tst_QXmppMessage::testMessageReceipt()
{
    const QByteArray xml(
        "<message id=\"richard2-4.1.247\" to=\"[email protected]/throne\" from=\"[email protected]/westminster\" type=\"normal\">"
          "<body>My lord, dispatch; read o'er these articles.</body>"
          "<request xmlns=\"urn:xmpp:receipts\"/>"
        "</message>");

    QXmppMessage message;
    parsePacket(message, xml);
    QCOMPARE(message.id(), QString("richard2-4.1.247"));
    QCOMPARE(message.to(), QString("[email protected]/throne"));
    QCOMPARE(message.from(), QString("[email protected]/westminster"));
    QVERIFY(message.extendedAddresses().isEmpty());
    QCOMPARE(message.type(), QXmppMessage::Normal);
    QCOMPARE(message.body(), QString("My lord, dispatch; read o'er these articles."));
    QCOMPARE(message.isAttentionRequested(), false);
    QCOMPARE(message.isReceiptRequested(), true);
    QCOMPARE(message.receiptId(), QString());
    serializePacket(message, xml);

    const QByteArray receiptXml(
        "<message id=\"bi29sg183b4v\" to=\"[email protected]/westminster\" from=\"[email protected]/throne\" type=\"normal\">"
          "<received xmlns=\"urn:xmpp:receipts\" id=\"richard2-4.1.247\"/>"
        "</message>");

    QXmppMessage receipt;
    parsePacket(receipt, receiptXml);
    QCOMPARE(receipt.id(), QString("bi29sg183b4v"));
    QCOMPARE(receipt.to(), QString("[email protected]/westminster"));
    QCOMPARE(receipt.from(), QString("[email protected]/throne"));
    QVERIFY(receipt.extendedAddresses().isEmpty());
    QCOMPARE(receipt.type(), QXmppMessage::Normal);
    QCOMPARE(receipt.body(), QString());
    QCOMPARE(receipt.isAttentionRequested(), false);
    QCOMPARE(receipt.isReceiptRequested(), false);
    QCOMPARE(receipt.receiptId(), QString("richard2-4.1.247"));
    serializePacket(receipt, receiptXml);

    const QByteArray oldXml(
        "<message id=\"richard2-4.1.247\" to=\"[email protected]/westminster\" from=\"[email protected]/throne\" type=\"normal\">"
          "<received xmlns=\"urn:xmpp:receipts\"/>"
        "</message>");

    QXmppMessage old;
    parsePacket(old, oldXml);
    QCOMPARE(old.id(), QString("richard2-4.1.247"));
    QCOMPARE(old.to(), QString("[email protected]/westminster"));
    QCOMPARE(old.from(), QString("[email protected]/throne"));
    QVERIFY(old.extendedAddresses().isEmpty());
    QCOMPARE(old.type(), QXmppMessage::Normal);
    QCOMPARE(old.body(), QString());
    QCOMPARE(old.isAttentionRequested(), false);
    QCOMPARE(old.isReceiptRequested(), false);
    QCOMPARE(old.receiptId(), QString("richard2-4.1.247"));
}
Пример #5
0
void MyXmppClient::messageReceivedSlot( const QXmppMessage &xmppMsg )
{
    QString bareJid_from = MyXmppClient::getBareJidByJid( xmppMsg.from() );
    QString bareJid_to = MyXmppClient::getBareJidByJid( xmppMsg.to() );

    if( xmppMsg.state() == QXmppMessage::Active ) qDebug() << "Msg state is QXmppMessage::Active";
    else if( xmppMsg.state() == QXmppMessage::Inactive ) qDebug() << "Msg state is QXmppMessage::Inactive";
    else if( xmppMsg.state() == QXmppMessage::Gone ) qDebug() << "Msg state is QXmppMessage::Gone";
    else if( xmppMsg.state() == QXmppMessage::Composing ) {
        if (bareJid_from != "") {
            m_flTyping = true;
            emit typingChanged(m_accountId,bareJid_from, true);
            qDebug() << bareJid_from << " is composing.";
        }
    }
    else if( xmppMsg.state() == QXmppMessage::Paused ) {
        if (bareJid_from != "") {
            m_flTyping = false;
            emit typingChanged(m_accountId,bareJid_from, false);
            qDebug() << bareJid_from << " paused.";
        }
    } else {
        if( xmppMsg.isAttentionRequested() )
        {
            //qDebug() << "ZZZ: attentionRequest !!! from:" <<xmppMsg.from();
            //msgWrapper->attention( bareJid_from, false );
        }
        qDebug() << "MessageWrapper::messageReceived(): xmppMsg.state():" << xmppMsg.state();
    }
    if ( !( xmppMsg.body().isEmpty() || xmppMsg.body().isNull() || bareJid_from == m_myjid ) ) {
        m_bareJidLastMessage = getBareJidByJid(xmppMsg.from());
        m_resourceLastMessage = getResourceByJid(xmppMsg.from());

        this->openChat( bareJid_from );

        RosterItemModel *item = (RosterItemModel*)cachedRoster->find( bareJid_from );
        if( item != 0 ) { int cnt = item->unreadMsg(); item->setUnreadMsg( ++cnt ); } else {
          RosterItemModel *itemModel = new RosterItemModel( );
          itemModel->setPresence( this->getPicPresence( QXmppPresence::Unavailable ) );
          itemModel->setContactName( bareJid_from );
          itemModel->setJid( bareJid_from );
          itemModel->setUnreadMsg( 1 );
          itemModel->setStatusText( "");
          cachedRoster->append(itemModel);
          itemModel = 0;
          delete itemModel;
        }
        item = 0; delete item;

        emit insertMessage(m_accountId,this->getBareJidByJid(xmppMsg.from()),xmppMsg.body(),QDateTime::currentDateTime().toString("dd-MM-yy hh:mm"),0);
    }
}
Пример #6
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"));
}
Пример #7
0
void Client::messageReceived(const QXmppMessage &message)
{
    qDebug() << message.body();
    QString from = message.from();
    QString msg = message.body();
    m_client->sendPacket(QXmppMessage("", from, "Your message: " + msg));
}
Пример #8
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);
}
Пример #9
0
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);
}
Пример #10
0
void JabberChatStateService::extractReceivedChatState(const QXmppMessage &message)
{
	auto jid = Jid::parse(message.from());
	auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd);

	contact.addProperty("jabber:received-chat-state", static_cast<int>(message.state()), CustomProperties::NonStorable);
	emit peerStateChanged(contact, xmppStateToState(message.state()));
}
Пример #11
0
void UnreadMessageModel::add(const QXmppMessage &message)
{
    m_messageStore[QXmppUtils::jidToBareJid(message.from())] << message;
    //modification to reset() function, to match qt5, I don't know what really reset() does, to improve
    QTextStream newclass;
    newclass.reset();
//////////
}
Пример #12
0
	void EntryBase::HandleAttentionMessage (const QXmppMessage& msg)
	{
		QString jid;
		QString resource;
		ClientConnection::Split (msg.from (), &jid, &resource);

		emit attentionDrawn (msg.body (), resource);
	}
Пример #13
0
void QxmppPeer::messageReceived(const QXmppMessage& message)
{
    QString from = message.from();
    QString msg  = message.body();

    //sendPacket( QXmppMessage("", from, "Your message: " + msg) );
    if ( !m_messageHandler.empty() )
        m_messageHandler( from.toStdString(), msg.toStdString() );
}
Пример #14
0
void TestPackets::testMessage()
{
    const QByteArray xml(
        "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\"/>");

    QXmppMessage message;
    parsePacket(message, xml);
    QCOMPARE(message.to(), QString("[email protected]/QXmpp"));
    QCOMPARE(message.from(), QString("[email protected]/QXmpp"));
    serializePacket(message, xml);
}
Пример #15
0
void Xmpp_client::messageReceived(const QXmppMessage& message)
{
    qDebug() << "Xmpp_client::messageReceived !!!";

    QString from = message.from();

    QByteArray msg = QByteArray::fromBase64(message.body().toUtf8());


    qDebug() << "RECEIVE from : " << from << " MESSAGE : " << msg;

}
Пример #16
0
void ChatExtension::HandleMessageReceived(const QXmppMessage &message)
{   
    if(message.type() == QXmppMessage::GroupChat)
        return;

    QString sender_jid = jidToBareJid(message.from());
    QString msg = message.body();

    LogInfo("XMPPModule: Received message. From: " + sender_jid.toStdString()
            + " Body: " + msg.toStdString());

    emit MessageReceived(sender_jid, msg);
}
Пример #17
0
void MainWindow::messageReceived(const QXmppMessage &msg)
{
//    qDebug() << msg.body();
    if (msg.body().isEmpty())
        return;

    UserChatDialog *dialog = userChatDialog(QXmppUtils::jidToBareJid(msg.from()));
    if (dialog)
    {
        dialog->show();
        dialog->messageReceived(msg.body());
    }
}
Пример #18
0
void CFrmUserList::slotClientMessageReceived(const QXmppMessage &message)
{
    LOG_MODEL_DEBUG("Roster", "CFrmUserList::slotClientMessageReceived:type:%d;state:%d;from:%s;to:%s;body:%s",
           message.type(),
           message.state(), //消息的状态 0:消息内容,其它值表示这个消息的状态  
           qPrintable(message.from()),
           qPrintable(message.to()),
           qPrintable(message.body())
          );

    m_LastUser = message.from();//保存接收到最后消息的用户  
    QMap<QString, CRoster*>::iterator it;
    it = m_Rosters.find(QXmppUtils::jidToBareJid(message.from()));
    if(m_Rosters.end() != it)
    {
        if(QXmppMessage::None == message.state())
        {
            it.value()->AppendMessage(message.body());
        }
        //TODO:消息输入状态显示  
    }
}
Пример #19
0
void MucExtension::HandleMessageReceived(const QXmppMessage &message)
{
    QXmppMucRoom *room = qobject_cast<QXmppMucRoom*>(sender());
    if(!room)
        return;

    QString message_type;

    // Parse message type into string.
    switch(message.type())
    {
        case QXmppMessage::Error:
            message_type = "error";
            break;
        case QXmppMessage::Normal:
            message_type = "normal";
            break;
        case QXmppMessage::Chat:
            message_type = "chat";
            break;
        case QXmppMessage::GroupChat:
            message_type = "groupchat";
            break;
        case QXmppMessage::Headline:
            message_type = "headline";
            break;
        default:
            message_type = "invalid type";
    }

    LogInfo("XMPPModule: Received message. From: " + message.from().toStdString()
            + " Room: " + room->jid().toStdString()
            + " Body: " + message.body().toStdString()
            + " Type: " + message_type.toStdString());

    emit MessageReceived(room->jid(), message.from(), message.body(), message_type);
}
Пример #20
0
Message JabberChatService::handleNormalReceivedMessage(const QXmppMessage &xmppMessage)
{
	auto jid = Jid::parse(xmppMessage.from());

	auto contact = ContactManager::instance()->byId(account(), jid.bare(), ActionCreateAndAdd);
	auto chat = ChatTypeContact::findChat(contact, ActionCreateAndAdd);

	contact.addProperty("jabber:chat-resource", jid.resource(), CustomProperties::NonStorable);

	auto message = Message::create();
	message.setMessageChat(chat);
	message.setMessageSender(contact);

	return message;
}
Пример #21
0
void MUCWidget::insertMessage(QXmppMessage &message) {
    if(message.body().isEmpty()) {
		return;
    }
	QString text = message.body();
	text.replace("&", "&amp;");
	text.replace("<", "&lt;");
	text.replace("<", "&gt;");
	text.replace("\"", "&quot;");
	text.replace("\n", "<br />");
	text.replace(HYPERLINK_REPLACE_ARGS);
    QStringList jid = parseJid(message.from());
    if(!jid[5].isEmpty()) {
		ui->chatview->append("<div class=\"message\"><a href=\"talkto:" + jid[5] + "\">&lt;" + jid[5] + "&gt;</a> " + text + "</div>");
    } else {
		ui->chatview->append("<div class=\"info\">" + text + "</div>");
    }
}
Пример #22
0
void tst_QXmppMessage::testMessageAttention()
{
    const QByteArray xml(
        "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">"
          "<attention xmlns=\"urn:xmpp:attention:0\"/>"
        "</message>");

    QXmppMessage message;
    parsePacket(message, xml);
    QCOMPARE(message.to(), QString("[email protected]/QXmpp"));
    QCOMPARE(message.from(), QString("[email protected]/QXmpp"));
    QVERIFY(message.extendedAddresses().isEmpty());
    QCOMPARE(message.type(), QXmppMessage::Normal);
    QCOMPARE(message.body(), QString());
    QCOMPARE(message.isAttentionRequested(), true);
    QCOMPARE(message.isReceiptRequested(), false);
    QCOMPARE(message.receiptId(), QString());
    serializePacket(message, xml);
}
Пример #23
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);
}
Пример #24
0
Message JabberRoomChatService::handleReceivedMessage(const QXmppMessage &xmppMessage) const
{
    auto jid = Jid::parse(xmppMessage.from());
    auto roomChat = getRoomChat(jid.bare());
    if (!roomChat)
        return Message::null;

    if (jid.resource() == roomChat->nick())   // message from myself
        return Message::null;

    auto contact = m_contactManager->byId(account(), jid.full(), ActionCreateAndAdd);
    auto buddy = m_buddyManager->byContact(contact, ActionCreateAndAdd);
    buddy.setDisplay(jid.resource());
    buddy.setTemporary(true);

    auto result = m_messageStorage->create();
    result.setMessageChat(roomChat->chat());
    result.setMessageSender(contact);

    return result;
}
Пример #25
0
void TestPackets::testMessageFull()
{
    const QByteArray xml(
        "<message to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\" type=\"normal\">"
        "<subject>test subject</subject>"
        "<body>test body &amp; 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);
}
Пример #26
0
bool QXmppPEPManager::handleStanza(const QDomElement &stanza)
{
    bool isIq = (stanza.tagName() == "iq");
    if (!isIq && (stanza.tagName() != "message")) {
        return false;
    }

    // XEP-0163: Personal Eventing Protocol
    QDomElement pepElement = stanza.firstChildElement("event");

    if(!pepElement.isNull() && pepElement.namespaceURI() == ns_personal_eventing_protocol)
    {
        QXmppMessage message;
        message.parse(stanza);

        QDomElement itemsElement = pepElement.firstChildElement("items");
        QString nodeType = itemsElement.attribute("node");

        // XEP-0152: Reachability Addresses
        if(nodeType == ns_reach)
        {
            QDomElement itemElement = itemsElement.firstChildElement("item");
            if(!itemElement.isNull())
            {
                QString itemId = itemElement.attribute("id");
                QDomElement reachElement = itemElement.firstChildElement("reach");

                QXmppReachAddress reachAddress;
                reachAddress.parse(reachElement);

                if(!reachAddress.isNull())
                    emit reachabilityAddressReceived(message.from(), itemId, reachAddress);

                return true;
            }
        }
    }
    return false;
}
Пример #27
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);
}
Пример #28
0
void Xmpp::messageReceived (const QXmppMessage &message)
{
    QString body = message.body();
    QString peer = users.at (jids.indexOf (QXmppUtils::jidToBareJid (message.from())));
    emit newMessage (peer, body);
}
Пример #29
0
	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);
		}
	}
Пример #30
0
void UnreadMessageModel::add(const QXmppMessage &message)
{
    m_messageStore[jidToBareJid(message.from())] << message;
    reset();
}