diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
4 files changed, 23 insertions, 35 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index bc2fe371a..c641902a3 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -612,18 +612,21 @@ public class Account extends AbstractEntity { return this.bookmarks; } - public void setBookmarks(final List<Bookmark> bookmarks) { + public void setBookmarks(final CopyOnWriteArrayList<Bookmark> bookmarks) { this.bookmarks = bookmarks; } public boolean hasBookmarkFor(final Jid conferenceJid) { + return getBookmark(conferenceJid) != null; + } + + public Bookmark getBookmark(final Jid jid) { for (final Bookmark bookmark : this.bookmarks) { - final Jid jid = bookmark.getJid(); - if (jid != null && jid.equals(conferenceJid.toBareJid())) { - return true; + if (bookmark.getJid() != null && jid.toBareJid().equals(bookmark.getJid().toBareJid())) { + return bookmark; } } - return false; + return null; } public boolean setAvatar(final String filename) { diff --git a/src/main/java/de/pixart/messenger/entities/Bookmark.java b/src/main/java/de/pixart/messenger/entities/Bookmark.java index 34dddd6d9..8074c9430 100644 --- a/src/main/java/de/pixart/messenger/entities/Bookmark.java +++ b/src/main/java/de/pixart/messenger/entities/Bookmark.java @@ -2,6 +2,7 @@ package de.pixart.messenger.entities; import android.content.Context; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -13,7 +14,7 @@ import de.pixart.messenger.xmpp.jid.Jid; public class Bookmark extends Element implements ListItem { private Account account; - private Conversation mJoinedConversation; + private WeakReference<Conversation> conversation; public Bookmark(final Account account, final Jid jid) { super("conference"); @@ -49,8 +50,9 @@ public class Bookmark extends Element implements ListItem { @Override public String getDisplayName() { - if (this.mJoinedConversation != null) { - return this.mJoinedConversation.getName(); + final Conversation c = getConversation(); + if (c != null) { + return c.getName(); } else if (getBookmarkName() != null && !getBookmarkName().trim().isEmpty()) { return getBookmarkName().trim(); @@ -146,12 +148,15 @@ public class Bookmark extends Element implements ListItem { return this.account; } - public Conversation getConversation() { - return this.mJoinedConversation; + public synchronized Conversation getConversation() { + return this.conversation != null ? this.conversation.get() : null; } - public void setConversation(Conversation conversation) { - this.mJoinedConversation = conversation; + public synchronized void setConversation(Conversation conversation) { + if (this.conversation != null) { + this.conversation.clear(); + } + this.conversation = new WeakReference<>(conversation); } public String getBookmarkName() { @@ -167,11 +172,4 @@ public class Bookmark extends Element implements ListItem { return false; } } - - public void unregisterConversation() { - if (this.mJoinedConversation != null) { - this.mJoinedConversation.deregisterWithBookmark(); - } - this.mJoinedConversation = null; - } } diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index d9a12392e..223e26dd2 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -85,8 +85,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl private byte[] symmetricKey; - private Bookmark bookmark; - private boolean messagesLeftOnServer = true; private ChatState mOutgoingChatState = Config.DEFAULT_CHATSTATE; private ChatState mIncomingChatState = Config.DEFAULT_CHATSTATE; @@ -508,6 +506,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public String getName() { if (getMode() == MODE_MULTI) { final String subject = getMucOptions().getSubject(); + Bookmark bookmark = getBookmark(); final String bookmarkName = bookmark != null ? bookmark.getBookmarkName() : null; if (subject != null && !subject.trim().isEmpty()) { @@ -826,20 +825,8 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return this.symmetricKey; } - public void setBookmark(Bookmark bookmark) { - this.bookmark = bookmark; - this.bookmark.setConversation(this); - } - - public void deregisterWithBookmark() { - if (this.bookmark != null) { - this.bookmark.setConversation(null); - } - this.bookmark = null; - } - public Bookmark getBookmark() { - return this.bookmark; + return this.account.getBookmark(this.contactJid); } public Message findDuplicateMessage(Message message) { diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index d4ba4e9f8..c1dca783c 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -54,7 +54,7 @@ public class MucOptions { } public boolean isSelf(Jid counterpart) { - return counterpart.getResourcepart().equals(getActualNick()); + return counterpart.equals(self.getFullJid()); } public void resetChatState() { |