From 2eb2513615448f2ab25eee82032a37c200011b6e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 10 Feb 2018 16:24:55 +0100 Subject: [PATCH] always persist current nick (in bookmark and database) --- .../conversations/parser/PresenceParser.java | 4 ++++ .../services/XmppConnectionService.java | 23 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index ea555baac..2d1db79bf 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -11,6 +11,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -74,6 +75,9 @@ public class PresenceParser extends AbstractParser implements mXmppConnectionService.getAvatarService().clear(mucOptions); } mucOptions.setSelf(user); + + mXmppConnectionService.persistSelfNick(user); + invokeRenameListener(mucOptions, true); } boolean isNew = mucOptions.updateUser(user); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b6d4f14f9..85cce6cfa 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2405,6 +2405,22 @@ public class XmppConnectionService extends Service { return false; } + public void persistSelfNick(MucOptions.User self) { + final Conversation conversation = self.getConversation(); + 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.getResourcepart().equals(bookmark.getNick())) { + bookmark.setNick(full.getResourcepart()); + pushBookmarks(bookmark.getAccount()); + } + } + public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback callback) { final MucOptions options = conversation.getMucOptions(); final Jid joinJid = options.createJoinJid(nick); @@ -2417,13 +2433,6 @@ public class XmppConnectionService extends Service { @Override public void onSuccess() { - conversation.setContactJid(joinJid); - databaseBackend.updateConversation(conversation); - Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null) { - bookmark.setNick(nick); - pushBookmarks(bookmark.getAccount()); - } callback.success(conversation); }