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

support multiple pub keys per recipient #1523

Merged
merged 39 commits into from
Nov 25, 2021

Conversation

DenBond7
Copy link
Collaborator

@DenBond7 DenBond7 commented Oct 26, 2021

This PR added support multiple pub keys for recipient

close #1188
close #1539
close #1540
close #1541
close #1542
close #1566
close #1570


Tests (delete all except exactly one):

  • Tests added or updated

To be filled by reviewers

I have reviewed that this PR... (tick whichever items you personally focused on during this review):

  • addresses the issue it closes (if any)
  • code is readable and understandable
  • is accompanied with tests, or tests are not needed
  • is free of vulnerabilities

@DenBond7 DenBond7 force-pushed the issue_1188_support_multiply_pub_keys_for_recipient branch 3 times, most recently from 5c30eb9 to 589c384 Compare October 28, 2021 16:11
@tomholub tomholub changed the title Issue 1188 support multiply pub keys for recipient Issue 1188 support multiple pub keys per recipient Oct 28, 2021
@DenBond7 DenBond7 force-pushed the issue_1188_support_multiply_pub_keys_for_recipient branch 15 times, most recently from b1ebbc3 to b53ba16 Compare November 1, 2021 16:05
@DenBond7
Copy link
Collaborator Author

@tomholub @IvanPizhenko It's ready for a review. Sorry, that is a huge and terrible PR. But I could not split it into a few smaller PRs. One thing relates to another one and so on. I had to change too many things.

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

Here you go.

General comment - the codebase is quite massive when I feel maybe less code could achieve the same thing. Often there are bits of functionality duplicated, like once suspend and once not, once xxxFlow and once not and so on. I hope, with some refactoring (not now) it could be streamlined. Else it will be a lot of work for you to make changes if many things are implemented twice to use in similar but a bit different ways.

Comment on lines 1007 to 1018
} else {
//todo-denbond7 temporary disable updating
button.gone()
}/*else if (existingRecipientWithPubKeys.publicKeys.firstOrNull()?.fingerprint.isNullOrEmpty()
|| keyDetails?.fingerprint?.equals(
existingPgpContact.fingerprint!!, ignoreCase = true
existingRecipientWithPubKeys.publicKeys.firstOrNull()?.fingerprint, ignoreCase = true
) == true
) {
initUpdateContactButton(block, button)
} else {
initReplaceContactButton(block, button)
}
}*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here it should be similar to other places:

  • if we already have this particular public key (by fingerprint) saved for this recipient, then we compare by last modified. If the one we already have is newer or same, we tell the user. If the received one is newer, we offer import (with "update")
  • if we don't have that pubkey for this recipient by fingerprint, offer import (with "save")

So it's not firstOrNull but we instead check if it's in the list, and then whether it's newer or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting. It seems I've disabled some functionality in MessageDetailsFragment.kt during migration and forgotten to fix it.(too many changes in this PR :( ) I have to fix that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please file a separate issue for the future to add a test for this. Since it could be disabled without noticing, it's not covered by any test.

Comment on lines 1082 to 1085
/*button.setOnClickListener { v ->
val RecipientWithPubKeys = block.keyDetails?.primaryRecipientWithPubKeys
if (RecipientWithPubKeys != null) {
recipientsViewModel.updateContact(RecipientWithPubKeys)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Plus here

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

Per above

Copy link
Contributor

@IvanPizhenko IvanPizhenko left a comment

Choose a reason for hiding this comment

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

Some comments. To say true, yes, it is really huge, and I don't have a lot to say here, since I'm not specialist in Android and not always get the rest of application logic. I've seen Tom made more meaningful comments.

@DenBond7
Copy link
Collaborator Author

General comment - the codebase is quite massive when I feel maybe less code could achieve the same thing. Often there are bits of functionality duplicated, like once suspend and once not, once xxxFlow and once not and so on.

Let me explain why we have the following situation. It relates to the current situation in code:

  1. Our code needs architecture improvements (Important architecture changes #1035)
  2. For now we have different ways to resolve the similar problems over the whole app

a) we have the old code that uses standard Java Threads. That's why we have to have for example this method

@Query("SELECT * FROM sqlite")
fun getRows(): List<Row>

b) we have code that uses coroutines. It requires the following version. Usually, such methods are used to fetch some info once. Like finding some entity and so on.

@Query("SELECT * FROM sqlite")
suspend fun getRows(): List<Row>

c) we have code that uses coroutines and Flow. Usually, such methods are used to fetch some info and observe changes. Like fetching a list and receiving updates: insert, delete, update items.

@Query("SELECT * FROM sqlite")
suspend fun getRowsFlow(): Flow<List<Row>>

I agree that we should drop a) and migrate to use b) and c) depending on our needs.

Just need to find some free time for that (between adding new functionality) :))

@DenBond7
Copy link
Collaborator Author

@IvanPizhenko @tomholub By the way, please mark a conversation as resolved if you don't have any other comments and it looks ok after my changes. It will help me to see what is already done and what I should fix. Thanks!

…multiply_pub_keys_for_recipient

# Conflicts:
#	FlowCrypt/src/main/java/com/flowcrypt/email/jetpack/viewmodel/ContactsViewModel.kt
#	FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/SelectRecipientsActivity.kt
@DenBond7 DenBond7 marked this pull request as draft November 25, 2021 08:42
@tomholub
Copy link
Collaborator

@IvanPizhenko @tomholub By the way, please mark a conversation as resolved if you don't have any other comments and it looks ok after my changes. It will help me to see what is already done and what I should fix. Thanks!

I've resolved some that don't need any code change. But let's do it the other way - if you made a code change that you believe resolves our concern, then please mark it as resolved. All of the comments are quite minor and you are the primary person who interacts with this codebase, so it's the most important that it works for you rather than that it works for us (except for things that affect functionality directly, but I guess there weren't any this time).

@tomholub
Copy link
Collaborator

General comment - the codebase is quite massive when I feel maybe less code could achieve the same thing. Often there are bits of functionality duplicated, like once suspend and once not, once xxxFlow and once not and so on.

Let me explain why we have the following situation. It relates to the current situation in code:

1. Our code needs architecture improvements ([Important architecture changes #1035](https://github.com/FlowCrypt/flowcrypt-android/issues/1035))

2. For now we have different ways to resolve the similar problems over the whole app

a) we have the old code that uses standard Java Threads. That's why we have to have for example this method

@Query("SELECT * FROM sqlite")
fun getRows(): List<Row>

b) we have code that uses coroutines. It requires the following version. Usually, such methods are used to fetch some info once. Like finding some entity and so on.

@Query("SELECT * FROM sqlite")
suspend fun getRows(): List<Row>

c) we have code that uses coroutines and Flow. Usually, such methods are used to fetch some info and observe changes. Like fetching a list and receiving updates: insert, delete, update items.

@Query("SELECT * FROM sqlite")
suspend fun getRowsFlow(): Flow<List<Row>>

I agree that we should drop a) and migrate to use b) and c) depending on our needs.

Just need to find some free time for that (between adding new functionality) :))

All good. I just wanted to make sure that we both don't like the situation. Yes, I know I haven't given you any time for refactoring lately. And it looks like there won't be any until at least February :-(

@tomholub
Copy link
Collaborator

because of #1550

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

checkpoint review - so far good

Comment on lines +45 to +47
companion object {
private const val SELECT_ALL_PUB_KEYS = "SELECT * FROM public_keys"
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

That means in the future we may be doing this for all. But that's also for another issue.

Copy link
Collaborator

@tomholub tomholub left a comment

Choose a reason for hiding this comment

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

.

@tomholub tomholub merged commit 20cd64b into master Nov 25, 2021
@tomholub tomholub deleted the issue_1188_support_multiply_pub_keys_for_recipient branch November 25, 2021 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment