Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent creating contact without encryption in chatmail account #3177

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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 WARN_ADDR_EXTRA = "warn_addr";
adbenitez marked this conversation as resolved.
Show resolved Hide resolved

private ConversationListFragment conversationListFragment;
public TextView title;
Expand Down Expand Up @@ -238,6 +239,11 @@ private void refresh() {
AccountManager.getInstance().switchAccountAndStartActivity(this, accountId);
}

String warnAddr = getIntent().getStringExtra(WARN_ADDR_EXTRA);
if (!TextUtils.isEmpty(warnAddr)) {
DcHelper.showEncryptionRequiredDialog(this, warnAddr);
}

refreshAvatar();
refreshUnreadIndicator();
refreshTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public void onContactSelected(int specialId, String addr) {
int contactId = dcContext.lookupContactIdByAddr(addr);
if (contactId!=0 && dcContext.getChatIdByContactId(contactId)!=0) {
openConversation(dcContext.getChatIdByContactId(contactId));
} else if (contactId == 0 && dcContext.isChatmail()) {
DcHelper.showEncryptionRequiredDialog(this, addr);
} else {
String nameNAddr = contactId == 0 ? addr : dcContext.getContact(contactId).getNameNAddr();
new AlertDialog.Builder(this)
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/org/thoughtcrime/securesms/ShareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,26 @@ private void handleResolvedMedia(Intent intent) {
}
*/

String addr = null;
if(chatId == -1 && extraEmail != null && extraEmail.length > 0) {
final String addr = extraEmail[0];
addr = extraEmail[0];
int contactId = dcContext.lookupContactIdByAddr(addr);

if(contactId == 0) {
contactId = dcContext.createContact(null, addr);
}
if(contactId != 0 || !dcContext.isChatmail()) {
if(contactId == 0) {
contactId = dcContext.createContact(null, addr);
}

chatId = dcContext.createChatByContactId(contactId);
chatId = dcContext.createChatByContactId(contactId);
addr = null;
}
}
Intent composeIntent;
if (chatId != -1) {
if (addr != null) {
composeIntent = new Intent(this, ConversationListActivity.class);
composeIntent.putExtra(ConversationListActivity.WARN_ADDR_EXTRA, addr);
startActivity(composeIntent);
} else if (chatId != -1) {
composeIntent = getBaseShareIntent(ConversationActivity.class);
composeIntent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
RelayUtil.setSharedUris(composeIntent, resolvedExtras);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/thoughtcrime/securesms/connect/DcHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ public static void showInvalidUnencryptedDialog(Context context) {
.show();
}

public static void showEncryptionRequiredDialog(Context context, String addr) {
new AlertDialog.Builder(context)
.setMessage(context.getString(R.string.encryption_required_for_new_contact, addr))
.setNeutralButton(R.string.learn_more, (d, w) -> openHelp(context, "#howtoe2ee"))
.setNegativeButton(R.string.qrscan_title, (d, w) -> context.startActivity(new Intent(context, QrActivity.class)))
.setPositiveButton(R.string.ok, null)
.setCancelable(true)
.show();
}

public static void openHelp(Context context, String section) {
Intent intent = new Intent(context, LocalHelpActivity.class);
if (section != null) { intent.putExtra(LocalHelpActivity.SECTION_EXTRA, section); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ public void handleQrData(String rawString) {
showFingerPrintError(builder, nameAndAddress);
break;

case DcContext.DC_QR_FPR_OK:
case DcContext.DC_QR_ADDR:
if (dcContext.isChatmail()) {
dcContext.deleteContact(qrParsed.getId());
DcHelper.showEncryptionRequiredDialog(activity, nameAndAddress);
return;
}
r10s marked this conversation as resolved.
Show resolved Hide resolved
case DcContext.DC_QR_FPR_OK:
showFingerprintOrQrSuccess(builder, qrParsed, nameAndAddress);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ public void onClick(View widget) {
String addr = prepareUrl(url);
Activity activity = (Activity) widget.getContext();
DcContext dcContext = DcHelper.getContext(activity);
DcContact contact = dcContext.getContact(dcContext.createContact(null, addr));
if (contact.getId() != 0 && !contact.isBlocked() && dcContext.getChatIdByContactId(contact.getId()) != 0) {
int contactId = dcContext.lookupContactIdByAddr(addr);
DcContact contact = (contactId != 0)? dcContext.getContact(contactId) : null;
if (contact != null && !contact.isBlocked() && dcContext.getChatIdByContactId(contactId) != 0) {
openChat(activity, contact);
} else if (contact == null && dcContext.isChatmail()) {
DcHelper.showEncryptionRequiredDialog(activity, addr);
} else {
String nameNAddr = contact != null ? contact.getNameNAddr() : addr;
new AlertDialog.Builder(activity)
.setMessage(activity.getString(R.string.ask_start_chat_with, contact.getNameNAddr()))
.setMessage(activity.getString(R.string.ask_start_chat_with, nameNAddr))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
openChat(activity, contact);
openChat(activity, contact == null? dcContext.getContact(dcContext.createContact(null, addr)) : contact);
})
.setNegativeButton(R.string.cancel, null)
.show();
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@
<string name="chat_protection_broken_explanation">End-to-end encryption cannot be guaranteed anymore, likely because %1$s reinstalled Delta Chat or sent a message from another device.\n\nYou may meet them in person and scan their QR code again to reestablish guaranteed end-to-end encryption.</string>
<string name="invalid_unencrypted_tap_to_learn_more">⚠️ %1$s requires end-to-end encryption which is not setup for this chat yet. Tap to learn more.</string>
<string name="invalid_unencrypted_explanation">To establish end-to-end-encryption, you may meet contacts in person and scan their QR Code to introduce them.</string>
<string name="encryption_required_for_new_contact">End-to-end encryption is required but it is not setup for %1$s yet.\n\nYou may share your invite link with them or meet in person and scan their QR Code.</string>
Copy link
Member Author

@adbenitez adbenitez Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to tweak the message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fill free/feel free/ - tweaked :)

<string name="learn_more">Learn More</string>

<string name="devicemsg_self_deleted">You deleted the \"Saved messages\" chat.\n\nℹ️ To use the \"Saved messages\" feature again, create a new chat with yourself.</string>
Expand Down
Loading