From e72b866fceb3a43ac36d33c476bf260607cc97c5 Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 29 Oct 2024 17:28:33 +0700 Subject: [PATCH] allow to start secret chat on roster page --- .../ui/StartConversationActivity.java | 20 +++++++++++++++++++ src/main/res/menu/contact_context.xml | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 076956815..b18de5822 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -1310,6 +1310,21 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } } + protected void startOtrChat() { + int position = contact_context_id; + Contact contact = (Contact) contacts.get(position); + + Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), null, false, false, false, null); + + selectPresence(conversation, + () -> { + Conversation c = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), null, false, false, false, conversation.getNextCounterpart()); + conversation.setNextCounterpart(null); + if (c != null) { + switchToConversation(c); + } + }); + } private void setRefreshing(boolean refreshing) { MyListFragment fragment = (MyListFragment) mListPagerAdapter.getItem(0); @@ -1451,9 +1466,12 @@ public class StartConversationActivity extends XmppActivity implements XmppConne final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock); final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details); final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact); + final MenuItem startSecrectChat = menu.findItem(R.id.context_contact_start_secrect_chat); if (contact.isSelf()) { showContactDetailsItem.setVisible(false); + startSecrectChat.setVisible(false); } + deleteContactMenuItem.setVisible(contact.showInRoster() && !contact.getOption(Contact.Options.SYNCED_VIA_OTHER)); final XmppConnection xmpp = contact.getAccount().getXmppConnection(); if (xmpp != null && xmpp.getFeatures().blocking() && !contact.isSelf()) { @@ -1492,6 +1510,8 @@ public class StartConversationActivity extends XmppActivity implements XmppConne break; case R.id.context_delete_conference: activity.deleteConference(); + case R.id.context_contact_start_secrect_chat: + activity.startOtrChat(); } return true; } diff --git a/src/main/res/menu/contact_context.xml b/src/main/res/menu/contact_context.xml index e6da36f45..87ab17a8c 100644 --- a/src/main/res/menu/contact_context.xml +++ b/src/main/res/menu/contact_context.xml @@ -4,6 +4,11 @@ + + +