diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:04:55 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:04:55 +0100 |
commit | dfb0139a6ca303f23e737d513d50e6789e122573 (patch) | |
tree | 46d99895f58171ecb97f0708d11e18556a517f41 /src/main | |
parent | 21b4f2476c8879e7711571a5f1b9bfd0c56fda51 (diff) |
fixed race condition that prevented bookmark nick to be used
Diffstat (limited to 'src/main')
5 files changed, 36 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Bookmark.java b/src/main/java/de/pixart/messenger/entities/Bookmark.java index fc7725bb5..e670673dd 100644 --- a/src/main/java/de/pixart/messenger/entities/Bookmark.java +++ b/src/main/java/de/pixart/messenger/entities/Bookmark.java @@ -87,6 +87,11 @@ public class Bookmark extends Element implements ListItem { return this.jid; } + public Jid getFullJid() { + final String nick = getNick(); + return jid == null || nick == null || nick.trim().isEmpty() ? jid : jid.withResource(nick); + } + @Override public List<Tag> getTags(Context context) { ArrayList<Tag> tags = new ArrayList<>(); @@ -160,7 +165,12 @@ public class Bookmark extends Element implements ListItem { if (this.conversation != null) { this.conversation.clear(); } - this.conversation = new WeakReference<>(conversation); + if (conversation == null) { + this.conversation = null; + } else { + this.conversation = new WeakReference<>(conversation); + conversation.getMucOptions().notifyOfBookmarkNick(getNick()); + } } public String getBookmarkName() { diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index 8291188ae..a630fd0c8 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -44,6 +44,7 @@ public class MucOptions { private Error error = Error.NONE; private User self; private String password = null; + private boolean tookProposedNickFromBookmark = false; public MucOptions(Conversation conversation) { this.account = conversation.getAccount(); this.conversation = conversation; @@ -96,6 +97,16 @@ public class MucOptions { } } + public boolean isTookProposedNickFromBookmark() { + return tookProposedNickFromBookmark; + } + + void notifyOfBookmarkNick(String nick) { + if (nick != null && nick.trim().equals(getSelf().getFullJid().getResource())) { + this.tookProposedNickFromBookmark = true; + } + } + public boolean mamSupport() { return MessageArchiveService.Version.has(getFeatures()); } @@ -375,11 +386,12 @@ public class MucOptions { } } - public String getProposedNick() { - if (conversation.getBookmark() != null - && conversation.getBookmark().getNick() != null - && !conversation.getBookmark().getNick().trim().isEmpty()) { - return conversation.getBookmark().getNick().trim(); + private String getProposedNick() { + final Bookmark bookmark = this.conversation.getBookmark(); + final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); + if (bookmarkedNick != null && !bookmarkedNick.trim().isEmpty()) { + this.tookProposedNickFromBookmark = true; + return bookmarkedNick.trim(); } else if (!conversation.getJid().isBareJid()) { return conversation.getJid().getResource(); } else { diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index 3de2835b9..7e49f03c6 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -235,7 +235,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { if (bookmark.getConversation() != null) { return get(bookmark.getConversation(), size, cachedOnly); } else { - Jid jid = bookmark.getJid(); + final Jid jid = bookmark.getFullJid(); Account account = bookmark.getAccount(); Contact contact = jid == null ? null : account.getRoster().getContact(jid); if (contact != null && contact.getAvatarFilename() != null) { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index b8986bf77..d3c7279c2 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1606,7 +1606,7 @@ public class XmppConnectionService extends Service { if (conversation != null) { bookmark.setConversation(conversation); } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) { - conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false); + conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false); bookmark.setConversation(conversation); } } @@ -2702,15 +2702,17 @@ public class XmppConnectionService extends Service { public void persistSelfNick(MucOptions.User self) { final Conversation conversation = self.getConversation(); + final boolean tookProposedNickFromBookmark = conversation.getMucOptions().isTookProposedNickFromBookmark(); Jid full = self.getFullJid(); if (!full.equals(conversation.getJid())) { Log.d(Config.LOGTAG, "nick changed. updating"); conversation.setContactJid(full); databaseBackend.updateConversation(conversation); } - - Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && !full.getResource().equals(bookmark.getNick())) { + final Bookmark bookmark = conversation.getBookmark(); + final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); + if (bookmark != null && (tookProposedNickFromBookmark || TextUtils.isEmpty(bookmarkedNick)) && !full.getResource().equals(bookmarkedNick)) { + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": persist nick '" + full.getResource() + "' into bookmark for " + conversation.getJid().asBareJid()); bookmark.setNick(full.getResource()); pushBookmarks(bookmark.getAccount()); } diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index e4812528d..c073341f7 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -395,7 +395,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } protected void openConversationsForBookmark(Bookmark bookmark) { - Jid jid = bookmark.getJid(); + final Jid jid = bookmark.getFullJid(); if (jid == null) { Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show(); return; |