1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Improve Privacy List code

notably add a cache for the active and default privacy list to avoid
IQ get/response round-trips.

Also add a few methods to PrivacyListManager to get the privacy list
names. The already existing methods always returned the whole list
together with the name, which caused two round-trips.

Simplified some code.

Properly escape Privacy XML.
This commit is contained in:
Florian Schmaus 2015-01-07 19:35:11 +01:00
parent 67c0a7089b
commit 3dd1365a5a
8 changed files with 299 additions and 18 deletions

View file

@ -1371,6 +1371,27 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout);
}
@Override
public void addOneTimeSyncCallback(final PacketListener callback, final PacketFilter packetFilter) {
final PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(Packet packet) throws NotConnectedException {
try {
callback.processPacket(packet);
} finally {
removeSyncPacketListener(this);
}
}
};
addSyncPacketListener(packetListener, packetFilter);
removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
removeSyncPacketListener(packetListener);
}
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
}
private long lastStanzaReceived;
public long getLastStanzaReceived() {

View file

@ -556,6 +556,15 @@ public interface XMPPConnection {
final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException;
/**
* Add a callback that is called exactly once and synchronously with the incoming stanza that matches the given
* packet filter.
*
* @param callback the callback invoked once the packet filter matches a stanza.
* @param packetFilter the filter to match stanzas or null to match all.
*/
public void addOneTimeSyncCallback(PacketListener callback, PacketFilter packetFilter);
/**
* Returns the timestamp in milliseconds when the last stanza was received.
*

View file

@ -0,0 +1,41 @@
/**
*
* Copyright 2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
/**
*
*/
public class IQResultReplyFilter extends IQReplyFilter {
public IQResultReplyFilter(IQ iqPacket, XMPPConnection conn) {
super(iqPacket, conn);
}
@Override
public boolean accept(Packet packet) {
if (!super.accept(packet)) {
return false;
}
return IQTypeFilter.RESULT.accept(packet);
}
}