From c5e90199c3ba2f8c074e5d6ebf9490bd1533559b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 30 Apr 2021 11:32:02 +0200 Subject: [PATCH] trigger registration dialog on roster;ibr=y only if no accounts are configured fixes #4065 --- .../conversations/generator/PresenceGenerator.java | 9 ++++++++- .../services/XmppConnectionService.java | 14 +++++++++++--- .../ui/StartConversationActivity.java | 3 ++- .../siacs/conversations/ui/UriHandlerActivity.java | 5 +++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java index 0701afcfe..1485385bc 100644 --- a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java @@ -25,12 +25,19 @@ public class PresenceGenerator extends AbstractGenerator { return packet; } - public PresencePacket requestPresenceUpdatesFrom(Contact contact) { + public PresencePacket requestPresenceUpdatesFrom(final Contact contact) { + return requestPresenceUpdatesFrom(contact, null); + } + + public PresencePacket requestPresenceUpdatesFrom(final Contact contact, final String preAuth) { PresencePacket packet = subscription("subscribe", contact); String displayName = contact.getAccount().getDisplayName(); if (!TextUtils.isEmpty(displayName)) { packet.addChild("nick", Namespace.NICK).setContent(displayName); } + if (preAuth != null) { + packet.addChild("preauth", Namespace.PARS).setAttribute("token", preAuth); + } return packet; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b570330d0..759a0d727 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3448,15 +3448,23 @@ public class XmppConnectionService extends Service { } } - public void createContact(Contact contact, boolean autoGrant) { + public void createContact(final Contact contact, final boolean autoGrant) { + createContact(contact, autoGrant, null); + } + + public void createContact(final Contact contact, final boolean autoGrant, final String preAuth) { if (autoGrant) { contact.setOption(Contact.Options.PREEMPTIVE_GRANT); contact.setOption(Contact.Options.ASKING); } - pushContactToServer(contact); + pushContactToServer(contact, preAuth); } public void pushContactToServer(final Contact contact) { + pushContactToServer(contact, null); + } + + private void pushContactToServer(final Contact contact, final String preAuth) { contact.resetOption(Contact.Options.DIRTY_DELETE); contact.setOption(Contact.Options.DIRTY_PUSH); final Account account = contact.getAccount(); @@ -3472,7 +3480,7 @@ public class XmppConnectionService extends Service { sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact)); } if (ask) { - sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact)); + sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact, preAuth)); } } else { syncRoster(contact.getAccount()); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 139c55665..e6d3ebf6e 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -526,7 +526,8 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } else if (contact.showInRoster()) { throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); } else { - xmppConnectionService.createContact(contact, true); + final String preAuth = invite == null ? null : invite.getParameter(XmppUri.PARAMETER_PRE_AUTH); + xmppConnectionService.createContact(contact, true, preAuth); if (invite != null && invite.hasFingerprints()) { xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); } diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index f868e3337..57e1aadcb 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -95,7 +95,8 @@ public class UriHandlerActivity extends AppCompatActivity { } @Override - public void onNewIntent(Intent intent) { + public void onNewIntent(final Intent intent) { + super.onNewIntent(intent); handleIntent(intent); } @@ -120,7 +121,7 @@ public class UriHandlerActivity extends AppCompatActivity { startActivity(intent); return; } - if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter(XmppUri.PARAMETER_IBR))) { + if (accounts.size() == 0 && xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter(XmppUri.PARAMETER_IBR))) { intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth); intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString()); startActivity(intent);