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
......@@ -43,6 +43,8 @@ public class DiscoItem implements Result {
private final String action;
private final Element element;
private volatile String uid = null;
public DiscoItem(Element element) {
this.element = element;
jid = new JID(element.attributeValue("jid"));
......@@ -169,6 +171,9 @@ public class DiscoItem implements Result {
*/
@Override
public String getUID() {
if (uid == null) {
synchronized(this) {
if (uid == null) {
final StringBuilder sb = new StringBuilder(jid.toString());
if (name != null) {
sb.append(name);
......@@ -179,7 +184,26 @@ public class DiscoItem implements Result {
if (action != null) {
sb.append(action);
}
uid = sb.toString();
}
}
}
return uid;
}
return sb.toString();
@Override
public int hashCode() {
return getUID().hashCode();
}
@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;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
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.AtomicLong;
......@@ -60,7 +66,11 @@ import org.jivesoftware.openfire.muc.cluster.GetNumberConnectedUsers;
import org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent;
import org.jivesoftware.openfire.muc.cluster.RoomAvailableEvent;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -1636,7 +1646,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (!isServiceEnabled()) {
return null;
}
List<DiscoItem> answer = new ArrayList<>();
Set<DiscoItem> answer = new HashSet<>();
if (name == null && node == null)
{
// 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