From c3bdec1ce9a28cadc2cacbe619801e94829118e8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 27 Dec 2015 17:29:32 +0100 Subject: dedublicate bookmarks --- .../eu/siacs/conversations/services/XmppConnectionService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 649ddacd..28d6e355 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -50,6 +50,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -992,13 +993,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void onIqPacketReceived(final Account account, final IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { final Element query = packet.query(); - final List bookmarks = new CopyOnWriteArrayList<>(); + final HashMap bookmarks = new HashMap<>(); final Element storage = query.findChild("storage", "storage:bookmarks"); if (storage != null) { for (final Element item : storage.getChildren()) { if (item.getName().equals("conference")) { final Bookmark bookmark = Bookmark.parse(item, account); - bookmarks.add(bookmark); + Bookmark old = bookmarks.put(bookmark.getJid(), bookmark); + if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) { + bookmark.setBookmarkName(old.getBookmarkName()); + } Conversation conversation = find(bookmark); if (conversation != null) { conversation.setBookmark(bookmark); @@ -1011,7 +1015,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } } } - account.setBookmarks(bookmarks); + account.setBookmarks(new ArrayList<>(bookmarks.values())); } else { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks"); } -- cgit v1.2.3