From f5daf84f441e0760d935b5519d0dc2d5fa269a9c Mon Sep 17 00:00:00 2001 From: Arne Date: Thu, 10 Oct 2024 05:23:07 +0200 Subject: [PATCH] Fix up empty OTR verification window --- .../services/XmppConnectionService.java | 32 +++++++++++++++++++ .../ui/ConversationsActivity.java | 1 + .../conversations/ui/VerifyOTRActivity.java | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 269dfe55e1..eb70f29377 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -827,6 +827,10 @@ public class XmppConnectionService extends Service { return find(getConversations(), account, jid); } + public Conversation find(final Account account, final Jid jid, final Jid counterpart) { + return find(getConversations(), account, jid, counterpart); + } + public boolean isMuc(final Account account, final Jid jid) { final Conversation c = find(account, jid); return c != null && c.getMode() == Conversational.MODE_MULTI; @@ -2856,6 +2860,34 @@ public class XmppConnectionService extends Service { return null; } + private Conversation find(final Iterable haystack, final Account account, final Jid jid, final Jid counterpart) { + if (jid == null) { + return null; + } + + if (counterpart != null) { + for (final Conversation conversation : haystack) { + if ((account == null || conversation.getAccount() == account) + && (conversation.getJid().asBareJid().equals(jid.asBareJid())) + && Objects.equal(conversation.getNextCounterpart(), counterpart) + ) { + return conversation; + } + } + } else { + for (final Conversation conversation : haystack) { + if ((account == null || conversation.getAccount() == account) + && (conversation.getJid().asBareJid().equals(jid.asBareJid())) + && conversation.getNextCounterpart() == null + ) { + return conversation; + } + } + } + + return null; + } + public boolean isConversationsListEmpty(final Conversation ignore) { synchronized (this.conversations) { final int size = this.conversations.size(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index cba72faca0..c9218e115a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -1535,6 +1535,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio Intent intent = new Intent(ConversationsActivity.this, VerifyOTRActivity.class); intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); intent.putExtra("contact", conversation.getContact().getJid().asBareJid().toString()); + intent.putExtra("counterpart", conversation.getNextCounterpart().toString()); intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString()); switch (menuItem.getItemId()) { case R.id.ask_question: diff --git a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java index f9a66b9166..dd9ec29dfe 100644 --- a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java @@ -200,7 +200,7 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer return false; } try { - this.mConversation = this.xmppConnectionService.find(this.mAccount, Jid.of(intent.getStringExtra("contact"))); + this.mConversation = this.xmppConnectionService.find(this.mAccount, Jid.of(intent.getExtras().getString("contact")), Jid.of(intent.getExtras().getString("counterpart"))); if (this.mConversation == null) { return false; }