fixed race condition that prevented bookmark nick to be used
This commit is contained in:
parent
21b4f2476c
commit
dfb0139a6c
5 changed files with 36 additions and 12 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Reference in a new issue