如何使用smack在android中获取发送到PUBSUB节点的消息的消息传递收据

时间:2018-02-06 12:10:45

标签: android xmpp ejabberd openfire smack

我正在使用smack库使用Openfire / Ejabberd XMPP服务器开发android聊天应用程序。我正在研究PUBSUB,能够创建PUBSUB节点,向节点发送消息,接收消息等。

现在,我希望收到已发送邮件的邮件传递收据。 我搜索了它,我得到的是:

Chat chat;
if (StringUtils.isNullOrEmpty(threadId)) {
chat = getChatManager().createChat(to);
Log.d(TAG, "sendMessage: no thread id so created Chat with id: " + chat.getThreadID());
} else {
chat = getChatManager().getThreadChat(threadId);
Log.d(TAG, "sendMessage: thread id was used to continue this chat");
}

Message message = new Message(to);
message.addBody("EN", messageText);
String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
chat.sendMessage(message);

并收到送货单:

DeliveryReceiptManager.getInstanceFor(mConnection).addReceiptReceivedListener(new ReceiptReceivedListener() {
    @Override
    public void onReceiptReceived(String fromJid, String toJid, String deliveryReceiptId, Stanza stanza) {
        Log.d(TAG, "onReceiptReceived: from: " + fromJid + " to: " + toJid + " deliveryReceiptId: " + deliveryReceiptId + " stanza: " + stanza);
    }
}); 

但这是使用org.jivesoftware.smack.packet.Message对象发送消息的代码,该对象用于在MUC聊天中发送消息。通过PUBSUB节点发送消息的方式是不同的,即this链接中给出的有效负载对象:

// Create a pubsub manager using an existing XMPPConnection
PubSubManager mgr = PubSubManager.getInstanceFor(con);

// Get the node
LeafNode node = mgr.getNode("testNode");

// Publish an Item with payload
node.send(new PayloadItem("test" + System.currentTimeMillis(),
new SimplePayload("book", "pubsub:test:book", "Two Towers")));

所以问题是,如何使用上面的代码获取发送到PUBSUB节点的消息的消息传递收据。

提前致谢!

0 个答案:

没有答案