From 81ed4859c3f255be8b24a8075c2224f848d7378e Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 6 Jan 2025 12:32:38 -0500 Subject: [PATCH] Basic support for adding by jid on group chat create (cherry picked from commit 0993958d56c311d7e05fd843808871c2593e97ad) --- .../ui/ChooseContactActivity.java | 35 ++++++++++++++----- .../ui/StartConversationActivity.java | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java index a439f044a..2514b6dd6 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java @@ -56,6 +56,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im private final ArrayList mActivatedAccounts = new ArrayList<>(); private final Set selected = new HashSet<>(); private Set filterContacts; + private Set extraContacts = new HashSet<>(); private boolean showEnterJid = false; private boolean startSearching = false; @@ -292,6 +293,12 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im for (final var account : xmppConnectionService.getAccounts()) { if (mActivatedAccounts.contains(account.getJid().asBareJid().toEscapedString())) accounts.add(account); } + for (final var contact : extraContacts) { + if (!filterContacts.contains(contact.getJid().asBareJid().toString()) + && contact.match(this, needle)) { + getListItems().add(contact); + } + } for (final Account account : accounts) { for (final Contact contact : account.getRoster().getContacts()) { if (contact.showInContactList() && @@ -353,14 +360,26 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im ); dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid, x, y) -> { - final Intent request = getIntent(); - final Intent data = new Intent(); - data.putExtra("contact", contactJid.toString()); - data.putExtra(EXTRA_ACCOUNT, accountJid.toEscapedString()); - data.putExtra(EXTRA_SELECT_MULTIPLE, false); - copy(request, data); - setResult(RESULT_OK, data); - finish(); + for (final Account account : xmppConnectionService.getAccounts()) { + if (account.getJid().asBareJid().equals(accountJid)) { + final var contact = account.getRoster().getContact(contactJid); + if (multiple) { + extraContacts.add(contact); + selected.add(contactJid.toString()); + if (mMenuSearchView != null) { + binding.fab.postDelayed(() -> { + mMenuSearchView.expandActionView(); + mSearchEditText.setText(""); + mSearchEditText.append(contactJid.toString()); + }, 200L); + filterContacts(contactJid.toString()); + binding.fab.setImageResource(R.drawable.ic_navigate_next_24dp); + } + } else { + onListItemClicked(contact); + } + } + } return true; }); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index d92f4ee04..881a5ec4c 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -1557,7 +1557,7 @@ public class StartConversationActivity extends XmppActivity return; } Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class); - intent.putExtra(ChooseContactActivity.EXTRA_SHOW_ENTER_JID, false); + intent.putExtra(ChooseContactActivity.EXTRA_SHOW_ENTER_JID, true); intent.putExtra(ChooseContactActivity.EXTRA_SELECT_MULTIPLE, true); intent.putExtra(ChooseContactActivity.EXTRA_GROUP_CHAT_NAME, name.trim()); intent.putExtra(