正在查看: bbinstant v6.24.0 应用的 OfflineMessageManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 OfflineMessageManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.jivesoftware.smackx.offline;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.offline.packet.OfflineMessageInfo;
import org.jivesoftware.smackx.offline.packet.OfflineMessageRequest;
import org.jivesoftware.smackx.xdata.Form;
public class OfflineMessageManager {
private static final StanzaFilter PACKET_FILTER = new AndFilter(new StanzaExtensionFilter(new OfflineMessageInfo()), StanzaTypeFilter.MESSAGE);
private static final String namespace = "http://jabber.org/protocol/offline";
private final XMPPConnection connection;
public OfflineMessageManager(XMPPConnection xMPPConnection) {
this.connection = xMPPConnection;
}
public void deleteMessages(List<String> list) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
offlineMessageRequest.setType(IQ.Type.set);
Iterator<String> it = list.iterator();
while (it.hasNext()) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(it.next());
item.setAction("remove");
offlineMessageRequest.addItem(item);
}
this.connection.createStanzaCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
}
public List<OfflineMessageHeader> getHeaders() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
ArrayList arrayList = new ArrayList();
Iterator<DiscoverItems.Item> it = ServiceDiscoveryManager.getInstanceFor(this.connection).discoverItems(null, "http://jabber.org/protocol/offline").getItems().iterator();
while (it.hasNext()) {
arrayList.add(new OfflineMessageHeader(it.next()));
}
return arrayList;
}
public int getMessageCount() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
Form formFrom = Form.getFormFrom(ServiceDiscoveryManager.getInstanceFor(this.connection).discoverInfo(null, "http://jabber.org/protocol/offline"));
if (formFrom != null) {
return Integer.parseInt(formFrom.getField("number_of_messages").getValues().get(0));
}
return 0;
}
public List<Message> getMessages(final List<String> list) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
ArrayList arrayList = new ArrayList();
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(it.next());
item.setAction("view");
offlineMessageRequest.addItem(item);
}
AndFilter andFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() {
@Override
public boolean accept(Stanza stanza) {
return list.contains(((OfflineMessageInfo) stanza.getExtension(OfflineMessageRequest.ELEMENT, "http://jabber.org/protocol/offline")).getNode());
}
});
int size = list.size();
StanzaCollector createStanzaCollector = this.connection.createStanzaCollector(andFilter);
try {
this.connection.createStanzaCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
for (Message message = (Message) createStanzaCollector.nextResult(); message != null && size > 0; message = (Message) createStanzaCollector.nextResult()) {
size--;
arrayList.add(message);
}
return arrayList;
} finally {
createStanzaCollector.cancel();
}
}
public boolean supportsFlexibleRetrieval() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(this.connection).serverSupportsFeature("http://jabber.org/protocol/offline");
}
public void deleteMessages() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
offlineMessageRequest.setType(IQ.Type.set);
offlineMessageRequest.setPurge(true);
this.connection.createStanzaCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
}
public List<Message> getMessages() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
offlineMessageRequest.setFetch(true);
StanzaCollector createStanzaCollectorAndSend = this.connection.createStanzaCollectorAndSend(offlineMessageRequest);
StanzaCollector createStanzaCollector = this.connection.createStanzaCollector(StanzaCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(createStanzaCollectorAndSend));
try {
createStanzaCollectorAndSend.nextResultOrThrow();
createStanzaCollector.cancel();
ArrayList arrayList = new ArrayList(createStanzaCollector.getCollectedCount());
while (true) {
Message message = (Message) createStanzaCollector.pollResult();
if (message == null) {
return arrayList;
}
arrayList.add(message);
}
} finally {
createStanzaCollector.cancel();
}
}
}