mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Use WeakReference in MUC NodeInformationProvider
MultiUserChat's NodeInformationProvider must not hold a strong reference to the Connection instance. Fixes SMACK-540.
This commit is contained in:
parent
1df3841a41
commit
68a570b4fe
1 changed files with 5 additions and 0 deletions
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue