From 76b78be2f2024d76fd8a7dc0b35a23de28e5b8e8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 15 Dec 2018 17:44:23 +0100 Subject: [PATCH] synchronize join/leaves with bookmarks --- .../conversations/parser/MessageParser.java | 2 +- .../services/XmppConnectionService.java | 36 +++++++++++++++---- src/main/res/values/strings.xml | 4 +-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 0f62af0e1..ddab3b778 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -218,7 +218,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (account.getXmppConnection().getFeatures().bookmarksConversion()) { final Element i = items.findChild("item"); final Element storage = i == null ? null : i.findChild("storage", Namespace.BOOKMARKS); - mXmppConnectionService.processBookmarks(account, storage); + mXmppConnectionService.processBookmarks(account, storage, true); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": processing bookmark PEP event"); } else { Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ignoring bookmark PEP event because bookmark conversion was not detected"); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index fd5126b06..48044766a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1401,7 +1401,7 @@ public class XmppConnectionService extends Service { if (response.getType() == IqPacket.TYPE.RESULT) { final Element query1 = response.query(); final Element storage = query1.findChild("storage", "storage:bookmarks"); - processBookmarks(a, storage); + processBookmarks(a, storage, false); } else { Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": could not fetch bookmarks"); } @@ -1409,9 +1409,9 @@ public class XmppConnectionService extends Service { sendIqPacket(account, iqPacket, callback); } - public void processBookmarks(Account account, Element storage) { + public void processBookmarks(Account account, Element storage, final boolean pep) { final HashMap bookmarks = new HashMap<>(); - final boolean autojoin = respectAutojoin(); + final boolean synchronizeWithBookmarks = synchronizeWithBookmarks(); if (storage != null) { for (final Element item : storage.getChildren()) { if (item.getName().equals("conference")) { @@ -1420,10 +1420,20 @@ public class XmppConnectionService extends Service { if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) { bookmark.setBookmarkName(old.getBookmarkName()); } + if (bookmark.getJid() == null) { + continue; + } Conversation conversation = find(bookmark); if (conversation != null) { + if (conversation.getMode() != Conversation.MODE_MULTI) { + continue; + } bookmark.setConversation(conversation); - } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) { + 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); } @@ -1831,6 +1841,10 @@ public class XmppConnectionService extends Service { } public void archiveConversation(Conversation conversation) { + archiveConversation(conversation, true); + } + + private void archiveConversation(Conversation conversation, final boolean maySyncronizeWithBookmarks) { getNotificationService().clear(conversation); conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setNextMessage(null); @@ -1839,7 +1853,7 @@ public class XmppConnectionService extends Service { if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getAccount().getStatus() == Account.State.ONLINE) { Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && bookmark.autojoin() && respectAutojoin()) { + if (maySyncronizeWithBookmarks && bookmark != null && bookmark.autojoin() && synchronizeWithBookmarks()) { bookmark.setAutojoin(false); pushBookmarks(bookmark.getAccount()); } @@ -2342,11 +2356,19 @@ public class XmppConnectionService extends Service { @Override public void onConferenceConfigurationFetched(Conversation conversation) { + if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": conversation ("+conversation.getJid()+") got archived before IQ result"); + return; + } join(conversation); } @Override public void onFetchFailed(final Conversation conversation, Element error) { + if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": conversation ("+conversation.getJid()+") got archived before IQ result"); + return; + } if (error != null && "remote-server-not-found".equals(error.getName())) { conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND); updateConversationUi(); @@ -2434,7 +2456,7 @@ public class XmppConnectionService extends Service { if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.getMucOptions().setPassword(password); if (conversation.getBookmark() != null) { - if (respectAutojoin()) { + if (synchronizeWithBookmarks()) { conversation.getBookmark().setAutojoin(true); } pushBookmarks(conversation.getAccount()); @@ -3411,7 +3433,7 @@ public class XmppConnectionService extends Service { return getBooleanPreference("chat_states", R.bool.chat_states); } - private boolean respectAutojoin() { + private boolean synchronizeWithBookmarks() { return getBooleanPreference("autojoin", R.bool.autojoin); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index e7d2513a7..dd616212f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -279,8 +279,8 @@ Received messages will be marked with a green tick if supported Colorize send button to indicate contact status Other - Automatically join group chats - Respect the autojoin flag in group chat bookmarks + Synchronize with bookmarks + Join and leave group chats according to auto-join flag in your bookmarks. OMEMO fingerprint copied to clipboard! You are banned from this group chat This group chat is members only