Commit dff3bb1b authored by Dave Cridland's avatar Dave Cridland

Merge pull request #498 from tevans/OF-821

OF-821: Prevent duplicates for MUC item query
parents 1c054a2e 23cc2a25
...@@ -42,6 +42,8 @@ public class DiscoItem implements Result { ...@@ -42,6 +42,8 @@ public class DiscoItem implements Result {
private final String node; private final String node;
private final String action; private final String action;
private final Element element; private final Element element;
private volatile String uid = null;
public DiscoItem(Element element) { public DiscoItem(Element element) {
this.element = element; this.element = element;
...@@ -169,17 +171,39 @@ public class DiscoItem implements Result { ...@@ -169,17 +171,39 @@ public class DiscoItem implements Result {
*/ */
@Override @Override
public String getUID() { public String getUID() {
final StringBuilder sb = new StringBuilder(jid.toString()); if (uid == null) {
if (name != null) { synchronized(this) {
sb.append(name); if (uid == null) {
} final StringBuilder sb = new StringBuilder(jid.toString());
if (node != null) { if (name != null) {
sb.append(node); sb.append(name);
} }
if (action != null) { if (node != null) {
sb.append(action); sb.append(node);
}
if (action != null) {
sb.append(action);
}
uid = sb.toString();
}
}
} }
return uid;
}
@Override
public int hashCode() {
return getUID().hashCode();
}
return sb.toString(); @Override
public boolean equals(Object obj) {
return obj instanceof DiscoItem && getUID().equals(((DiscoItem)obj).getUID());
}
@Override
public String toString() {
return element.asXML();
} }
} }
\ No newline at end of file
...@@ -24,12 +24,18 @@ import java.util.ArrayList; ...@@ -24,12 +24,18 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.*; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
...@@ -60,7 +66,11 @@ import org.jivesoftware.openfire.muc.cluster.GetNumberConnectedUsers; ...@@ -60,7 +66,11 @@ import org.jivesoftware.openfire.muc.cluster.GetNumberConnectedUsers;
import org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent; import org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent;
import org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent; import org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent;
import org.jivesoftware.openfire.muc.cluster.RoomRemovedEvent; import org.jivesoftware.openfire.muc.cluster.RoomRemovedEvent;
import org.jivesoftware.util.*; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.JiveProperties;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.util.XMPPDateTimeFormat;
import org.jivesoftware.util.cache.CacheFactory; import org.jivesoftware.util.cache.CacheFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -1636,7 +1646,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1636,7 +1646,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (!isServiceEnabled()) { if (!isServiceEnabled()) {
return null; return null;
} }
List<DiscoItem> answer = new ArrayList<>(); Set<DiscoItem> answer = new HashSet<>();
if (name == null && node == null) if (name == null && node == null)
{ {
// Answer all the public rooms as items // Answer all the public rooms as items
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment