always persist current nick (in bookmark and database)

This commit is contained in:
Daniel Gultsch 2018-02-10 16:24:55 +01:00
parent 64c956904d
commit 2eb2513615
2 changed files with 20 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
@ -74,6 +75,9 @@ public class PresenceParser extends AbstractParser implements
mXmppConnectionService.getAvatarService().clear(mucOptions); mXmppConnectionService.getAvatarService().clear(mucOptions);
} }
mucOptions.setSelf(user); mucOptions.setSelf(user);
mXmppConnectionService.persistSelfNick(user);
invokeRenameListener(mucOptions, true); invokeRenameListener(mucOptions, true);
} }
boolean isNew = mucOptions.updateUser(user); boolean isNew = mucOptions.updateUser(user);

View File

@ -2405,6 +2405,22 @@ public class XmppConnectionService extends Service {
return false; 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) { public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
final MucOptions options = conversation.getMucOptions(); final MucOptions options = conversation.getMucOptions();
final Jid joinJid = options.createJoinJid(nick); final Jid joinJid = options.createJoinJid(nick);
@ -2417,13 +2433,6 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onSuccess() { 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); callback.success(conversation);
} }