本文整理汇总了Java中org.jivesoftware.smackx.offline.packet.OfflineMessageRequest类的典型用法代码示例。如果您正苦于以下问题:Java OfflineMessageRequest类的具体用法?Java OfflineMessageRequest怎么用?Java OfflineMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OfflineMessageRequest类属于org.jivesoftware.smackx.offline.packet包,在下文中一共展示了OfflineMessageRequest类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessages
import org.jivesoftware.smackx.offline.packet.OfflineMessageRequest; //导入依赖的package包/类
/**
* Returns a List of the offline <tt>Messages</tt> whose stamp matches the specified
* request. The request will include the list of stamps that uniquely identifies
* the offline messages to retrieve. The returned offline messages will not be deleted
* from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages.
*
* @param nodes the list of stamps that uniquely identifies offline message.
* @return a List with the offline <tt>Messages</tt> that were received as part of
* this request.
* @throws XMPPErrorException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException {
List<Message> messages = new ArrayList<Message>();
OfflineMessageRequest request = new OfflineMessageRequest();
for (String node : nodes) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
item.setAction("view");
request.addItem(item);
}
// Filter offline messages that were requested by this request
StanzaFilter messageFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() {
public boolean accept(Stanza packet) {
OfflineMessageInfo info = (OfflineMessageInfo) packet.getExtension("offline",
namespace);
return nodes.contains(info.getNode());
}
});
PacketCollector messageCollector = connection.createPacketCollector(messageFilter);
try {
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
// Collect the received offline messages
Message message = messageCollector.nextResult();
while (message != null) {
messages.add(message);
message = messageCollector.nextResult();
}
}
finally {
// Stop queuing offline messages
messageCollector.cancel();
}
return messages;
}
示例2: deleteMessages
import org.jivesoftware.smackx.offline.packet.OfflineMessageRequest; //导入依赖的package包/类
/**
* Deletes the specified list of offline messages. The request will include the list of
* stamps that uniquely identifies the offline messages to delete.
*
* @param nodes the list of stamps that uniquely identifies offline message.
* @throws XMPPErrorException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public void deleteMessages(List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException {
OfflineMessageRequest request = new OfflineMessageRequest();
for (String node : nodes) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
item.setAction("remove");
request.addItem(item);
}
connection.createPacketCollectorAndSend(request).nextResultOrThrow();
}