always persist current nick (in bookmark and database)

This commit is contained in:
Christian Schneppe 2018-02-10 20:19:28 +01:00
parent 356fb36bca
commit 0325594075
2 changed files with 17 additions and 7 deletions

View file

@ -72,6 +72,7 @@ public class PresenceParser extends AbstractParser implements
mXmppConnectionService.getAvatarService().clear(mucOptions);
}
mucOptions.setSelf(user);
mXmppConnectionService.persistSelfNick(user);
invokeRenameListener(mucOptions, true);
}
boolean isNew = mucOptions.updateUser(user);

View file

@ -2591,6 +2591,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<Conversation> callback) {
final MucOptions options = conversation.getMucOptions();
final Jid joinJid = options.createJoinJid(nick);
@ -2603,13 +2619,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);
}