trigger registration dialog on roster;ibr=y only if no accounts are configured

fixes #4065
This commit is contained in:
Daniel Gultsch 2021-04-30 11:32:02 +02:00
parent 53908dd56e
commit c5e90199c3
4 changed files with 24 additions and 7 deletions

View file

@ -25,12 +25,19 @@ public class PresenceGenerator extends AbstractGenerator {
return packet; 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); PresencePacket packet = subscription("subscribe", contact);
String displayName = contact.getAccount().getDisplayName(); String displayName = contact.getAccount().getDisplayName();
if (!TextUtils.isEmpty(displayName)) { if (!TextUtils.isEmpty(displayName)) {
packet.addChild("nick", Namespace.NICK).setContent(displayName); packet.addChild("nick", Namespace.NICK).setContent(displayName);
} }
if (preAuth != null) {
packet.addChild("preauth", Namespace.PARS).setAttribute("token", preAuth);
}
return packet; return packet;
} }

View file

@ -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) { if (autoGrant) {
contact.setOption(Contact.Options.PREEMPTIVE_GRANT); contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
contact.setOption(Contact.Options.ASKING); contact.setOption(Contact.Options.ASKING);
} }
pushContactToServer(contact); pushContactToServer(contact, preAuth);
} }
public void pushContactToServer(final Contact contact) { 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.resetOption(Contact.Options.DIRTY_DELETE);
contact.setOption(Contact.Options.DIRTY_PUSH); contact.setOption(Contact.Options.DIRTY_PUSH);
final Account account = contact.getAccount(); final Account account = contact.getAccount();
@ -3472,7 +3480,7 @@ public class XmppConnectionService extends Service {
sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact)); sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
} }
if (ask) { if (ask) {
sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact)); sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact, preAuth));
} }
} else { } else {
syncRoster(contact.getAccount()); syncRoster(contact.getAccount());

View file

@ -526,7 +526,8 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
} else if (contact.showInRoster()) { } else if (contact.showInRoster()) {
throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
} else { } 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()) { if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
} }

View file

@ -95,7 +95,8 @@ public class UriHandlerActivity extends AppCompatActivity {
} }
@Override @Override
public void onNewIntent(Intent intent) { public void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
handleIntent(intent); handleIntent(intent);
} }
@ -120,7 +121,7 @@ public class UriHandlerActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
return; 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 = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth);
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString()); intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
startActivity(intent); startActivity(intent);