From 94c592f2131d26fbe573e513012a73ff2cb754d6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 28 Sep 2019 10:16:29 +0200 Subject: [PATCH] leave/join on bookmark modifactions --- .../conversations/parser/MessageParser.java | 5 +- .../services/XmppConnectionService.java | 52 ++++++++++++------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 9f686bad2..2a63b68e6 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -239,9 +239,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (item != null) { final Bookmark bookmark = Bookmark.parseFromItem(item, account); if (bookmark != null) { - //TODO find conversation - account.putBookmark(bookmark); - //TODO handle autojoin + mXmppConnectionService.processModifiedBookmark(bookmark); } } if (retract != null) { @@ -249,6 +247,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (id != null) { account.removeBookmark(id); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": deleted bookmark for "+id); + mXmppConnectionService.processDeletedBookmark(account, id); } } } else { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 931b2d317..f3a1bf626 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1592,34 +1592,48 @@ public class XmppConnectionService extends Service { final boolean synchronizeWithBookmarks = synchronizeWithBookmarks(); for (Bookmark bookmark : bookmarks.values()) { previousBookmarks.remove(bookmark.getJid().asBareJid()); - Conversation conversation = find(bookmark); - if (conversation != null) { - if (conversation.getMode() != Conversation.MODE_MULTI) { - continue; - } - bookmark.setConversation(conversation); - if (pep && synchronizeWithBookmarks && !bookmark.autojoin()) { - Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving conference ("+conversation.getJid()+") after receiving pep"); - archiveConversation(conversation, false); - } - } else if (synchronizeWithBookmarks && bookmark.autojoin()) { - conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false); - bookmark.setConversation(conversation); - } + processModifiedBookmark(bookmark, pep, synchronizeWithBookmarks); } if (pep && synchronizeWithBookmarks) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + previousBookmarks.size() + " bookmarks have been removed"); for (Jid jid : previousBookmarks) { - final Conversation conversation = find(account, jid); - if (conversation != null && conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { - Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving destroyed conference ("+conversation.getJid()+") after receiving pep"); - archiveConversation(conversation, false); - } + processDeletedBookmark(account, jid); } } account.setBookmarks(bookmarks); } + public void processDeletedBookmark(Account account, Jid jid) { + final Conversation conversation = find(account, jid); + if (conversation != null && conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving destroyed conference ("+conversation.getJid()+") after receiving pep"); + archiveConversation(conversation, false); + } + } + + private void processModifiedBookmark(Bookmark bookmark, final boolean pep, final boolean synchronizeWithBookmarks) { + final Account account = bookmark.getAccount(); + Conversation conversation = find(bookmark); + if (conversation != null) { + if (conversation.getMode() != Conversation.MODE_MULTI) { + return; + } + bookmark.setConversation(conversation); + if (pep && synchronizeWithBookmarks && !bookmark.autojoin()) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": archiving conference ("+conversation.getJid()+") after receiving pep"); + archiveConversation(conversation, false); + } + } else if (synchronizeWithBookmarks && bookmark.autojoin()) { + conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false); + bookmark.setConversation(conversation); + } + } + + public void processModifiedBookmark(Bookmark bookmark) { + final boolean synchronizeWithBookmarks = synchronizeWithBookmarks(); + processModifiedBookmark(bookmark, true, synchronizeWithBookmarks); + } + public void createBookmark(final Account account, final Bookmark bookmark) { account.putBookmark(bookmark); final XmppConnection connection = account.getXmppConnection();