正在查看: Housing v14.7.8 应用的 OfflineMessageManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Housing v14.7.8 应用的 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.PacketCollector;
import org.jivesoftware.smack.SmackException;
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() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
offlineMessageRequest.setType(IQ.Type.set);
offlineMessageRequest.setPurge(true);
this.connection.createPacketCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
}
public List<OfflineMessageHeader> getHeaders() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
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 {
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() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
OfflineMessageRequest offlineMessageRequest = new OfflineMessageRequest();
offlineMessageRequest.setFetch(true);
PacketCollector createPacketCollectorAndSend = this.connection.createPacketCollectorAndSend(offlineMessageRequest);
PacketCollector createPacketCollector = this.connection.createPacketCollector(PacketCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(createPacketCollectorAndSend));
try {
createPacketCollectorAndSend.nextResultOrThrow();
createPacketCollector.cancel();
ArrayList arrayList = new ArrayList(createPacketCollector.getCollectedCount());
while (true) {
Message message = (Message) createPacketCollector.pollResult();
if (message == null) {
return arrayList;
}
arrayList.add(message);
}
} finally {
createPacketCollector.cancel();
}
}
public boolean supportsFlexibleRetrieval() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
return ServiceDiscoveryManager.getInstanceFor(this.connection).serverSupportsFeature("http://jabber.org/protocol/offline");
}
public void deleteMessages(List<String> list) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
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(DiscoverItems.Item.REMOVE_ACTION);
offlineMessageRequest.addItem(item);
}
this.connection.createPacketCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
}
public List<Message> getMessages(final List<String> list) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException {
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);
}
PacketCollector createPacketCollector = this.connection.createPacketCollector(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());
}
}));
try {
this.connection.createPacketCollectorAndSend(offlineMessageRequest).nextResultOrThrow();
Stanza nextResult = createPacketCollector.nextResult();
while (true) {
Message message = (Message) nextResult;
if (message == null) {
return arrayList;
}
arrayList.add(message);
nextResult = createPacketCollector.nextResult();
}
} finally {
createPacketCollector.cancel();
}
}
}