From dc70b7e28a3b81732c5fda39ac33cdd3d973b9c4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 26 Apr 2019 12:26:49 +0200 Subject: [PATCH] add bookmark when clicking on channel search result --- .../ui/ChannelDiscoveryActivity.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java b/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java index ab29c6f86..aabd6607f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference; import eu.siacs.conversations.R; import eu.siacs.conversations.databinding.ActivityChannelDiscoveryBinding; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.http.services.MuclumbusService; import eu.siacs.conversations.services.ChannelDiscoveryService; @@ -155,7 +156,7 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O private void optIn() { SharedPreferences preferences = getPreferences(); - preferences.edit().putBoolean(CHANNEL_DISCOVERY_OPT_IN,true).apply(); + preferences.edit().putBoolean(CHANNEL_DISCOVERY_OPT_IN, true).apply(); optedIn = true; xmppConnectionService.discoverChannels(null, this); } @@ -184,8 +185,8 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O public void onChannelSearchResult(final MuclumbusService.Room result) { List accounts = AccountUtils.getEnabledAccounts(xmppConnectionService); if (accounts.size() == 1) { - joinChannelSearchResult(accounts.get(0),result); - } else if (accounts.size() > 0){ + joinChannelSearchResult(accounts.get(0), result); + } else if (accounts.size() > 0) { final AtomicReference account = new AtomicReference<>(accounts.get(0)); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.choose_account); @@ -198,8 +199,20 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O } public void joinChannelSearchResult(String accountJid, MuclumbusService.Room result) { + final boolean syncAutojoin = getBooleanPreference("autojoin", R.bool.autojoin); Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid)); final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, result.getRoom(), true, true, true); + if (conversation.getBookmark() != null) { + if (!conversation.getBookmark().autojoin() && syncAutojoin) { + conversation.getBookmark().setAutojoin(true); + xmppConnectionService.pushBookmarks(account); + } + } else { + final Bookmark bookmark = new Bookmark(account, conversation.getJid().asBareJid()); + bookmark.setAutojoin(syncAutojoin); + account.getBookmarks().add(bookmark); + xmppConnectionService.pushBookmarks(account); + } switchToConversation(conversation); } }