Skip to content

Commit

Permalink
Fixed some PR comments. Refactored code. Step 2.| #1188
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Nov 25, 2021
1 parent 1a76ddd commit e6e08c2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class EmailUtil {
if (outgoingMsgInfo.encryptionType === MessageEncryptionType.ENCRYPTED) {
val recipients = outgoingMsgInfo.getAllRecipients().toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(context, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(context, recipients))
pubKeys.addAll(senderPgpKeyDetailsList.map { it.publicKey })
prvKeys = listOf(
senderPgpKeyDetailsList.firstOrNull()?.privateKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import kotlinx.coroutines.flow.Flow
*/
@Dao
interface PubKeyDao : BaseDao<PublicKeyEntity> {
@Query("SELECT * FROM public_keys")
@Query(SELECT_ALL_PUB_KEYS)
suspend fun getAllPublicKeys(): List<PublicKeyEntity>

@Query("SELECT * FROM public_keys")
@Query(SELECT_ALL_PUB_KEYS)
fun getAllPublicKeysFlow(): Flow<List<PublicKeyEntity>>

@Query("SELECT * FROM public_keys WHERE recipient = :recipient")
Expand All @@ -41,4 +41,8 @@ interface PubKeyDao : BaseDao<PublicKeyEntity> {

@Query("SELECT * FROM public_keys WHERE _id = :id")
fun getPublicKeyByIdFlow(id: Long): Flow<PublicKeyEntity?>

companion object {
private const val SELECT_ALL_PUB_KEYS = "SELECT * FROM public_keys"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati
}
}

fun deleteContact(recipientEntity: RecipientEntity) {
fun deleteRecipient(recipientEntity: RecipientEntity) {
viewModelScope.launch {
roomDatabase.recipientDao().deleteSuspend(recipientEntity)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class RecipientsViewModel(application: Application) : AccountViewModel(applicati
}
}

fun filterContacts(searchPattern: String?) {
fun filterContacts(searchPattern: String) {
searchPatternLiveData.value = searchPattern
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ForwardedAttachmentsDownloaderWorker(context: Context, params: WorkerParam
val senderEmail = EmailUtil.getFirstAddressString(msgEntity.from)
val recipients = msgEntity.allRecipients.toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(applicationContext, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(applicationContext, recipients))
pubKeys.addAll(
SecurityUtils.getSenderPgpKeyDetailsList(applicationContext, account, senderEmail)
.map { it.publicKey }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SecurityUtils {
* @throws NoKeyAvailableException
*/
@JvmStatic
fun getRecipientsPubKeys(context: Context, emails: MutableList<String>): List<String> {
fun getRecipientsUsablePubKeys(context: Context, emails: MutableList<String>): List<String> {
val publicKeys = mutableListOf<String>()
val recipientsWithPubKeys = FlowCryptRoomDatabase.getDatabase(context).recipientDao()
.getRecipientsWithPubKeysByEmails(emails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class PrepareOutgoingMessagesJobIntentService : JobIntentService() {
val senderEmail = outgoingMsgInfo.from
val recipients = outgoingMsgInfo.getAllRecipients().toMutableList()
pubKeys = mutableListOf()
pubKeys.addAll(SecurityUtils.getRecipientsPubKeys(applicationContext, recipients))
pubKeys.addAll(SecurityUtils.getRecipientsUsablePubKeys(applicationContext, recipients))
pubKeys.addAll(
SecurityUtils.getSenderPgpKeyDetailsList(applicationContext, accountEntity, senderEmail)
.map { it.publicKey }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RecipientsListFragment : BaseFragment(), ListProgressBehaviour {
true,
object : RecipientsRecyclerViewAdapter.OnRecipientActionsListener {
override fun onDeleteRecipient(recipientEntity: RecipientEntity) {
recipientsViewModel.deleteContact(recipientEntity)
recipientsViewModel.deleteRecipient(recipientEntity)
Toast.makeText(
context, getString(R.string.the_contact_was_deleted, recipientEntity.email),
Toast.LENGTH_SHORT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
private var imageButtonAdditionalRecipientsVisibility: View? = null
private var iBShowQuotedText: View? = null

private var isRecipientsUpdateEnabled = true
private var isUpdateToCompleted = true
private var isUpdateCcCompleted = true
private var isUpdateBccCompleted = true
Expand Down Expand Up @@ -862,12 +861,8 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
if (hasFocus) {
recipients?.clear()
} else {
if (isRecipientsUpdateEnabled) {
if (isAdded) {
fetchDetailsAboutRecipients(type)
}
} else {
progressBar?.visibility = View.INVISIBLE
if (isAdded) {
fetchDetailsAboutRecipients(type)
}
}
}
Expand Down Expand Up @@ -1498,8 +1493,6 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
*/
private fun sendMsg() {
dismissCurrentSnackBar()

isRecipientsUpdateEnabled = false
onMsgSendListener.sendMsg(getOutgoingMsgInfo())
}

Expand Down

0 comments on commit e6e08c2

Please sign in to comment.