mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #4217 from deltachat/wch423/onboarding-invite-code
Allow scanning invite codes from onboarding
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Delta Chat Android Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
* Allow scanning Invitation Code when creating a new profile
|
||||
|
||||
## v2.40.0
|
||||
2026-02
|
||||
|
||||
|
||||
@@ -19,4 +19,4 @@ public enum SecurejoinSource {
|
||||
|
||||
/** The user scanned a QR code */
|
||||
Scan,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ public enum SecurejoinUiPath {
|
||||
|
||||
/** The user first clicked on the `+` button in the main screen, and then on "New Contact" */
|
||||
NewContact,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
public static final String CLEAR_NOTIFICATIONS = "clear_notifications";
|
||||
public static final String ACCOUNT_ID_EXTRA = "account_id";
|
||||
public static final String FROM_WELCOME = "from_welcome";
|
||||
public static final String FROM_WELCOME_RAW_QR = "from_welcome_raw_qr";
|
||||
private static final int REQUEST_CODE_CONFIRM_CREDENTIALS_DELETE_PROFILE = ScreenLockUtil.REQUEST_CODE_CONFIRM_CREDENTIALS+1;
|
||||
|
||||
private ConversationListFragment conversationListFragment;
|
||||
@@ -191,6 +192,13 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
if (BuildConfig.DEBUG) checkNdkArchitecture();
|
||||
|
||||
DcHelper.maybeShowMigrationError(this);
|
||||
|
||||
String rawQrString = getIntent().getStringExtra(FROM_WELCOME_RAW_QR);
|
||||
// Launch chat directly, if coming from onboarding with a join chat/group QR
|
||||
if (rawQrString != null) {
|
||||
QrCodeHandler qrCodeHandler = new QrCodeHandler(this);
|
||||
qrCodeHandler.secureJoinByQr(rawQrString, SecurejoinSource.Scan, SecurejoinUiPath.Unknown);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,6 +61,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import chat.delta.rpc.Rpc;
|
||||
import chat.delta.rpc.RpcException;
|
||||
@@ -77,6 +79,7 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
|
||||
private ImageView avatar;
|
||||
private EditText name;
|
||||
private TextView invitationText;
|
||||
private TextView privacyPolicyBtn;
|
||||
private Button signUpBtn;
|
||||
|
||||
@@ -84,7 +87,11 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
private boolean imageLoaded;
|
||||
private String providerHost;
|
||||
private String providerQrData;
|
||||
private String rawQrData;
|
||||
private DcLot parsedQrData;
|
||||
private boolean isDcLogin;
|
||||
private boolean isContactInvitation;
|
||||
private boolean isGroupInvitation;
|
||||
|
||||
private AttachmentManager attachmentManager;
|
||||
private Bitmap avatarBmp;
|
||||
@@ -94,6 +101,8 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
|
||||
private DcContext dcContext;
|
||||
|
||||
private ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
@@ -204,17 +213,31 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
|
||||
private void setProviderFromQr(String rawQr) {
|
||||
DcLot qrParsed = dcContext.checkQr(rawQr);
|
||||
boolean isDcLogin = qrParsed.getState() == DcContext.DC_QR_LOGIN;
|
||||
if (isDcLogin || qrParsed.getState() == DcContext.DC_QR_ACCOUNT) {
|
||||
this.isDcLogin = isDcLogin;
|
||||
providerHost = qrParsed.getText1();
|
||||
providerQrData = rawQr;
|
||||
updateProvider();
|
||||
} else {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.qraccount_qr_code_cannot_be_used)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
switch (qrParsed.getState()) {
|
||||
case DcContext.DC_QR_LOGIN:
|
||||
isDcLogin = true; // Intentional fall-through
|
||||
case DcContext.DC_QR_ACCOUNT:
|
||||
providerHost = qrParsed.getText1();
|
||||
providerQrData = rawQr;
|
||||
updateProvider();
|
||||
break;
|
||||
case DcContext.DC_QR_ASK_VERIFYCONTACT:
|
||||
isContactInvitation = true;
|
||||
rawQrData = rawQr;
|
||||
parsedQrData = qrParsed;
|
||||
updateProvider();
|
||||
break;
|
||||
case DcContext.DC_QR_ASK_VERIFYGROUP:
|
||||
isGroupInvitation = true;
|
||||
rawQrData = rawQr;
|
||||
parsedQrData = qrParsed;
|
||||
updateProvider();
|
||||
break;
|
||||
default:
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.qraccount_qr_code_cannot_be_used)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +281,7 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
DcHelper.getEventCenter(this).removeObservers(this);
|
||||
executor.shutdown();
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
@@ -309,6 +333,7 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
private void initializeResources() {
|
||||
this.avatar = findViewById(R.id.avatar);
|
||||
this.name = findViewById(R.id.name_text);
|
||||
this.invitationText = findViewById(R.id.invitation_label);
|
||||
this.privacyPolicyBtn = findViewById(R.id.privacy_policy_button);
|
||||
this.signUpBtn = findViewById(R.id.signup_button);
|
||||
|
||||
@@ -364,6 +389,7 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
} else {
|
||||
signUpBtn.setText(R.string.instant_onboarding_create);
|
||||
privacyPolicyBtn.setTextColor(getResources().getColor(R.color.delta_accent));
|
||||
|
||||
if (DEFAULT_CHATMAIL_HOST.equals(providerHost)) {
|
||||
privacyPolicyBtn.setText(TextUtil.markAsExternal(
|
||||
getString(R.string.instant_onboarding_agree_default2, providerHost)));
|
||||
@@ -371,6 +397,19 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
privacyPolicyBtn.setText(TextUtil.markAsExternal(
|
||||
getString(R.string.instant_onboarding_agree_instance, providerHost)));
|
||||
}
|
||||
|
||||
if (parsedQrData != null) {
|
||||
if (isContactInvitation) {
|
||||
String name = dcContext.getContact(parsedQrData.getId()).getDisplayName();
|
||||
invitationText.setText(this.getString(R.string.instant_onboarding_contact_info, name));
|
||||
invitationText.setVisibility(View.VISIBLE);
|
||||
} else if (isGroupInvitation) {
|
||||
String groupName = parsedQrData.getText1();
|
||||
invitationText.setText(this.getString(R.string.instant_onboarding_group_info, groupName));
|
||||
invitationText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,11 +471,14 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
|
||||
Intent intent = new Intent(getApplicationContext(), ConversationListActivity.class);
|
||||
intent.putExtra(ConversationListActivity.FROM_WELCOME, true);
|
||||
if (isContactInvitation || isGroupInvitation) {
|
||||
intent.putExtra(ConversationListActivity.FROM_WELCOME_RAW_QR, rawQrData);
|
||||
}
|
||||
|
||||
startActivity(intent);
|
||||
finishAffinity();
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void createProfile() {
|
||||
if (TextUtils.isEmpty(this.name.getText())) {
|
||||
Toast.makeText(this, R.string.please_enter_name, Toast.LENGTH_LONG).show();
|
||||
@@ -444,37 +486,31 @@ public class InstantOnboardingActivity extends BaseActionBarActivity implements
|
||||
}
|
||||
final String name = this.name.getText().toString();
|
||||
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
Context context = InstantOnboardingActivity.this;
|
||||
DcHelper.set(context, DcHelper.CONFIG_DISPLAY_NAME, name);
|
||||
executor.execute(() -> {
|
||||
Context context = InstantOnboardingActivity.this;
|
||||
DcHelper.set(context, DcHelper.CONFIG_DISPLAY_NAME, name);
|
||||
|
||||
if (avatarChanged) {
|
||||
try {
|
||||
AvatarHelper.setSelfAvatar(InstantOnboardingActivity.this, avatarBmp);
|
||||
Prefs.setProfileAvatarId(InstantOnboardingActivity.this, new SecureRandom().nextInt());
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
return false;
|
||||
}
|
||||
boolean result = true;
|
||||
if (avatarChanged) {
|
||||
try {
|
||||
AvatarHelper.setSelfAvatar(InstantOnboardingActivity.this, avatarBmp);
|
||||
Prefs.setProfileAvatarId(InstantOnboardingActivity.this, new SecureRandom().nextInt());
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
result = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute(Boolean result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
if (result) {
|
||||
boolean finalResult = result;
|
||||
runOnUiThread(() -> {
|
||||
if (finalResult) {
|
||||
attachmentManager.cleanup();
|
||||
startQrAccountCreation(providerQrData);
|
||||
} else {
|
||||
Toast.makeText(InstantOnboardingActivity.this, R.string.error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void startQrAccountCreation(String qrCode)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.thoughtcrime.securesms.qr;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.journeyapps.barcodescanner.BarcodeResult;
|
||||
import com.journeyapps.barcodescanner.CaptureManager;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
|
||||
public class CustomCaptureManager extends CaptureManager {
|
||||
|
||||
private OnResultInterceptor interceptor;
|
||||
|
||||
public CustomCaptureManager(Activity activity, DecoratedBarcodeView barcodeView) {
|
||||
super(activity, barcodeView);
|
||||
}
|
||||
|
||||
public void setResultInterceptor(OnResultInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void returnResult(BarcodeResult rawResult) {
|
||||
if (interceptor != null) {
|
||||
interceptor.onResult(rawResult, () -> {
|
||||
super.returnResult(rawResult);
|
||||
});
|
||||
} else {
|
||||
super.returnResult(rawResult);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnResultInterceptor {
|
||||
void onResult(BarcodeResult result, Runnable finishCallback);
|
||||
}
|
||||
}
|
||||
@@ -325,25 +325,29 @@ public class QrCodeHandler {
|
||||
}
|
||||
builder.setMessage(msg);
|
||||
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
||||
try {
|
||||
int newChatId = DcHelper.getRpc(activity).secureJoinWithUxInfo(dcContext.getAccountId(), qrRawString, source, uipath);
|
||||
if (newChatId == 0) throw new Exception("Securejoin failed to create a chat");
|
||||
|
||||
Intent intent = new Intent(activity, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, newChatId);
|
||||
activity.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
|
||||
builder1.setMessage(e.getMessage());
|
||||
builder1.setPositiveButton(android.R.string.ok, null);
|
||||
builder1.create().show();
|
||||
}
|
||||
secureJoinByQr(qrRawString, source, uipath);
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
}
|
||||
|
||||
public void addRelay(String qrData) {
|
||||
public void secureJoinByQr(String qrRawString, SecurejoinSource source, SecurejoinUiPath uipath) {
|
||||
try {
|
||||
int newChatId = DcHelper.getRpc(activity).secureJoinWithUxInfo(dcContext.getAccountId(), qrRawString, source, uipath);
|
||||
if (newChatId == 0) throw new Exception("Securejoin failed to create a chat");
|
||||
|
||||
Intent intent = new Intent(activity, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, newChatId);
|
||||
activity.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
|
||||
builder1.setMessage(e.getMessage());
|
||||
builder1.setPositiveButton(android.R.string.ok, null);
|
||||
builder1.create().show();
|
||||
}
|
||||
}
|
||||
|
||||
public void addRelay(String qrData) {
|
||||
ProgressDialog progressDialog = new ProgressDialog(activity);
|
||||
progressDialog.setMessage(activity.getResources().getString(R.string.one_moment));
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
@@ -10,8 +10,12 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.journeyapps.barcodescanner.CaptureManager;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcLot;
|
||||
import com.journeyapps.barcodescanner.CompoundBarcodeView;
|
||||
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity;
|
||||
@@ -26,10 +30,12 @@ public class RegistrationQrActivity extends BaseActionBarActivity {
|
||||
public static final String ADD_AS_SECOND_DEVICE_EXTRA = "add_as_second_device";
|
||||
public static final String QRDATA_EXTRA = "qrdata";
|
||||
|
||||
private CaptureManager capture;
|
||||
private CustomCaptureManager capture;
|
||||
|
||||
private CompoundBarcodeView barcodeScannerView;
|
||||
|
||||
private DcContext dcContext;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -66,6 +72,8 @@ public class RegistrationQrActivity extends BaseActionBarActivity {
|
||||
.onAnyResult(this::handleQrScanWithPermissions)
|
||||
.onAnyDenied(this::handleQrScanWithDeniedPermission)
|
||||
.execute();
|
||||
|
||||
dcContext = DcHelper.getContext(this);
|
||||
}
|
||||
|
||||
private void handleQrScanWithPermissions() {
|
||||
@@ -89,23 +97,70 @@ public class RegistrationQrActivity extends BaseActionBarActivity {
|
||||
DcHelper.openHelp(this, "#multiclient");
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_paste) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(QRDATA_EXTRA, Util.getTextFromClipboard(this));
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
String rawQr = Util.getTextFromClipboard(this);
|
||||
|
||||
Runnable okCallback = () -> {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(QRDATA_EXTRA, rawQr);
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
};
|
||||
|
||||
showConfirmDialog(rawQr, okCallback, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
private void showConfirmDialog(String rawQr, @NonNull Runnable okCallback, @Nullable Runnable cancelCallback) {
|
||||
DcLot qrParsed = dcContext.checkQr(rawQr);
|
||||
|
||||
String dialogMsg = "";
|
||||
if (qrParsed.getState() == DcContext.DC_QR_ASK_VERIFYCONTACT) {
|
||||
String name = dcContext.getContact(qrParsed.getId()).getDisplayName();
|
||||
dialogMsg = getString(R.string.instant_onboarding_confirm_contact, name);
|
||||
} else if (qrParsed.getState() == DcContext.DC_QR_ASK_VERIFYGROUP) {
|
||||
String groupName = qrParsed.getText1();
|
||||
dialogMsg = getString(R.string.instant_onboarding_confirm_group, groupName);
|
||||
}
|
||||
|
||||
if (qrParsed.getState() == DcContext.DC_QR_ASK_VERIFYCONTACT
|
||||
|| qrParsed.getState() == DcContext.DC_QR_ASK_VERIFYGROUP) {
|
||||
AlertDialog confirmDialog = new AlertDialog.Builder(this)
|
||||
.setMessage(dialogMsg)
|
||||
.setPositiveButton("OK", (dialog, which) -> {
|
||||
okCallback.run();
|
||||
})
|
||||
.setNegativeButton("Cancel", (dialog, which) -> {
|
||||
if (cancelCallback != null) {
|
||||
cancelCallback.run();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
okCallback.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
private void init(CompoundBarcodeView barcodeScannerView, Intent intent, Bundle savedInstanceState) {
|
||||
capture = new CaptureManager(this, barcodeScannerView);
|
||||
capture = new CustomCaptureManager(this, barcodeScannerView);
|
||||
|
||||
capture.setResultInterceptor((result, finishCallback) -> {
|
||||
String rawQr = result.getText();
|
||||
|
||||
showConfirmDialog(rawQr, finishCallback, () -> {
|
||||
barcodeScannerView.resume();
|
||||
capture.decode();
|
||||
});
|
||||
});
|
||||
|
||||
capture.initializeFromIntent(intent, savedInstanceState);
|
||||
capture.decode();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,17 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/invitation_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="start"
|
||||
android:visibility="gone"
|
||||
android:textColor="@color/gray50" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/information_label"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user