add bookmark when clicking on channel search result

This commit is contained in:
Daniel Gultsch 2019-04-26 12:26:49 +02:00
parent 76fb17c972
commit dc70b7e28a

View file

@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityChannelDiscoveryBinding; import eu.siacs.conversations.databinding.ActivityChannelDiscoveryBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.http.services.MuclumbusService; import eu.siacs.conversations.http.services.MuclumbusService;
import eu.siacs.conversations.services.ChannelDiscoveryService; import eu.siacs.conversations.services.ChannelDiscoveryService;
@ -198,8 +199,20 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O
} }
public void joinChannelSearchResult(String accountJid, MuclumbusService.Room result) { public void joinChannelSearchResult(String accountJid, MuclumbusService.Room result) {
final boolean syncAutojoin = getBooleanPreference("autojoin", R.bool.autojoin);
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid)); Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, result.getRoom(), true, true, true); 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); switchToConversation(conversation);
} }
} }