本文整理汇总了C++中QXmppMessage::body方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmppMessage::body方法的具体用法?C++ QXmppMessage::body怎么用?C++ QXmppMessage::body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmppMessage
的用法示例。
在下文中一共展示了QXmppMessage::body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: messageReceived
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);
}
示例2: slotMessageReceived
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);
}
示例3: messageReceived
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));
}
示例4: testMessageReceipt
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: HandleMessage
void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick)
{
const bool existed = Nick2Entry_.contains (nick);
RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false);
if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ())
{
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
message = new RoomPublicMessage (msg.body (),
IMessage::DIn,
CLEntry_,
IMessage::MTEventMessage,
IMessage::MSTOther);
if (message)
CLEntry_->HandleMessage (message);
if (!existed)
Nick2Entry_.remove (nick);
}
}
示例6: messageReceivedSlot
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);
}
}
示例7: messageReceived
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());
}
}
示例8: testForwarding
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"));
}
示例9: saveMessage
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();
}
示例10: testReplaceWithEmptyMessage
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);
}
示例11: testBasic
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);
}
示例12: HandleAttentionMessage
void EntryBase::HandleAttentionMessage (const QXmppMessage& msg)
{
QString jid;
QString resource;
ClientConnection::Split (msg.from (), &jid, &resource);
emit attentionDrawn (msg.body (), resource);
}
示例13: insertMessage
void MUCWidget::insertMessage(QXmppMessage &message) {
if(message.body().isEmpty()) {
return;
}
QString text = message.body();
text.replace("&", "&");
text.replace("<", "<");
text.replace("<", ">");
text.replace("\"", """);
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] + "\"><" + jid[5] + "></a> " + text + "</div>");
} else {
ui->chatview->append("<div class=\"info\">" + text + "</div>");
}
}
示例14: messageReceived
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() );
}
示例15: handleReceivedMessage
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);
}