mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 13:11:08 +01:00
Merge branch '3.4'
Conflicts: build/build.xml
This commit is contained in:
commit
5f5805cd1c
10 changed files with 145 additions and 102 deletions
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
|
@ -116,12 +117,16 @@ public class MultiUserChat {
|
|||
// Chat protocol. This information will be used when another client tries to
|
||||
// discover whether this client supports MUC or not.
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);
|
||||
|
||||
// Set the NodeInformationProvider that will provide information about the
|
||||
// joined rooms whenever a disco request is received
|
||||
final WeakReference<Connection> weakRefConnection = new WeakReference<Connection>(connection);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
||||
discoNode,
|
||||
new NodeInformationProvider() {
|
||||
public List<DiscoverItems.Item> getNodeItems() {
|
||||
Connection connection = weakRefConnection.get();
|
||||
if (connection == null) return new LinkedList<DiscoverItems.Item>();
|
||||
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
||||
Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection);
|
||||
while (rooms.hasNext()) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.jivesoftware.smackx.ping;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
|
@ -65,7 +66,7 @@ public class PingManager {
|
|||
});
|
||||
}
|
||||
|
||||
private Connection connection;
|
||||
private WeakReference<Connection> weakRefConnection;
|
||||
|
||||
/**
|
||||
* Retrieves a {@link PingManager} for the specified {@link Connection}, creating one if it doesn't already
|
||||
|
|
@ -84,8 +85,8 @@ public class PingManager {
|
|||
return pingManager;
|
||||
}
|
||||
|
||||
private PingManager(Connection con) {
|
||||
this.connection = con;
|
||||
private PingManager(Connection connection) {
|
||||
weakRefConnection = new WeakReference<Connection>(connection);
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
// The ServiceDiscoveryManager was not pre-initialized
|
||||
|
|
@ -101,6 +102,7 @@ public class PingManager {
|
|||
* Sends a Pong for every Ping
|
||||
*/
|
||||
public void processPacket(Packet packet) {
|
||||
Connection connection = weakRefConnection.get();
|
||||
IQ pong = IQ.createResultIQ((Ping) packet);
|
||||
connection.sendPacket(pong);
|
||||
}
|
||||
|
|
@ -121,7 +123,7 @@ public class PingManager {
|
|||
*/
|
||||
public boolean ping(String jid, long pingTimeout) {
|
||||
Ping ping = new Ping(jid);
|
||||
|
||||
Connection connection = weakRefConnection.get();
|
||||
try {
|
||||
SyncPacketSend.getReply(connection, ping);
|
||||
}
|
||||
|
|
@ -151,6 +153,7 @@ public class PingManager {
|
|||
* @throws XMPPException An XMPP related error occurred during the request
|
||||
*/
|
||||
public boolean isPingSupported(String jid) throws XMPPException {
|
||||
Connection connection = weakRefConnection.get();
|
||||
DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid);
|
||||
return result.containsFeature(Ping.NAMESPACE);
|
||||
}
|
||||
|
|
@ -165,6 +168,7 @@ public class PingManager {
|
|||
* @return true if a reply was received from the server, false otherwise.
|
||||
*/
|
||||
public boolean pingMyServer() {
|
||||
Connection connection = weakRefConnection.get();
|
||||
return ping(connection.getServiceName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.jivesoftware.smackx.receipts;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
|
@ -52,7 +53,7 @@ public class DeliveryReceiptManager implements PacketListener {
|
|||
});
|
||||
}
|
||||
|
||||
private Connection connection;
|
||||
private WeakReference<Connection> weakRefConnection;
|
||||
private boolean auto_receipts_enabled = false;
|
||||
private Set<ReceiptReceivedListener> receiptReceivedListeners = Collections
|
||||
.synchronizedSet(new HashSet<ReceiptReceivedListener>());
|
||||
|
|
@ -60,7 +61,7 @@ public class DeliveryReceiptManager implements PacketListener {
|
|||
private DeliveryReceiptManager(Connection connection) {
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(DeliveryReceipt.NAMESPACE);
|
||||
this.connection = connection;
|
||||
weakRefConnection = new WeakReference<Connection>(connection);
|
||||
instances.put(connection, this);
|
||||
|
||||
// register listener for delivery receipts and requests
|
||||
|
|
@ -91,6 +92,7 @@ public class DeliveryReceiptManager implements PacketListener {
|
|||
* @return true if supported
|
||||
*/
|
||||
public boolean isSupported(String jid) {
|
||||
Connection connection = weakRefConnection.get();
|
||||
try {
|
||||
DiscoverInfo result =
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid);
|
||||
|
|
@ -119,6 +121,7 @@ public class DeliveryReceiptManager implements PacketListener {
|
|||
DeliveryReceiptRequest drr = (DeliveryReceiptRequest)packet.getExtension(
|
||||
DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE);
|
||||
if (drr != null) {
|
||||
Connection connection = weakRefConnection.get();
|
||||
Message ack = new Message(packet.getFrom(), Message.Type.normal);
|
||||
ack.addExtension(new DeliveryReceipt(packet.getPacketID()));
|
||||
connection.sendPacket(ack);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue