Skip to content

Commit

Permalink
Fixed RecipientDao.getRecipientByEmail().| #1188
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Oct 26, 2021
1 parent 55355f0 commit c36f3ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface RecipientDao : BaseDao<RecipientEntity> {
@Query("SELECT * FROM recipients WHERE email = :email")
suspend fun getRecipientByEmailSuspend(email: String): RecipientEntity?

//fixed
@Query("SELECT * FROM recipients WHERE email = :email")
fun getRecipientByEmail(email: String): RecipientEntity?

Expand All @@ -64,4 +65,7 @@ interface RecipientDao : BaseDao<RecipientEntity> {
//fixed
@Query("DELETE FROM recipients")
suspend fun deleteAll(): Int

@Query("SELECT * FROM recipients WHERE email = :email")
fun getRecipientWithPubKeysByEmail(email: String): RecipientWithPubKeys?
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class EmailAndNameUpdaterService : JobIntentService() {
val email = pair.email?.lowercase(Locale.getDefault()) ?: continue
val recipientEntity = recipientDao.getRecipientByEmail(email)
if (recipientEntity != null) {
/*if (recipientEntity.name.isNullOrEmpty()) {
if (recipientEntity.name.isNullOrEmpty()) {
recipientDao.update(recipientEntity.copy(name = pair.name))
}*/
}
} else {
recipientDao.insert(PgpContact(email, pair.name).toRecipientEntity())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class PrepareOutgoingMessagesJobIntentService : JobIntentService() {
if (recipientEntity == null) {
recipientDao.insert(PgpContact(email, null).toRecipientEntity())
} else {
//recipientDao.update(recipientEntity.copy(lastUse = System.currentTimeMillis()))
recipientDao.update(recipientEntity.copy(lastUse = System.currentTimeMillis()))
}
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ class PreviewImportPgpContactFragment : BaseFragment(), View.OnClickListener,
override fun doInBackground(vararg uris: Void): Boolean {
val newCandidates = ArrayList<PgpContact>()
val updateCandidates = ArrayList<PgpContact>()
val recipientDao =
FlowCryptRoomDatabase.getDatabase(weakRef.get()?.requireContext()!!).recipientDao()

for (publicKeyInfo in publicKeyInfoList) {
val pgpContact = PgpContact(
Expand Down Expand Up @@ -355,9 +357,7 @@ class PreviewImportPgpContactFragment : BaseFragment(), View.OnClickListener,
if (newCandidates.size - i > STEP_AMOUNT) i + STEP_AMOUNT else newCandidates.size

if (weakRef.get() != null) {
FlowCryptRoomDatabase.getDatabase(weakRef.get()?.requireContext()!!)
.recipientDao()
.insert(newCandidates.subList(start, end).map { it.toRecipientEntity() })
recipientDao.insert(newCandidates.subList(start, end).map { it.toRecipientEntity() })
}
i = end

Expand All @@ -379,22 +379,21 @@ class PreviewImportPgpContactFragment : BaseFragment(), View.OnClickListener,
if (updateCandidates.size - i > STEP_AMOUNT) i + STEP_AMOUNT else updateCandidates.size - 1

if (weakRef.get() != null) {
val contacts = mutableListOf<RecipientEntity>()
val recipients = mutableListOf<RecipientEntity>()
val list = updateCandidates.subList(start, end + 1)

list.forEach { pgpContact ->
val foundRecipientEntity =
FlowCryptRoomDatabase.getDatabase(weakRef.get()?.requireContext()!!)
.recipientDao().getRecipientByEmail(pgpContact.email)
recipientDao.getRecipientWithPubKeysByEmail(pgpContact.email)
foundRecipientEntity?.let { entity ->
/*contacts.add(
//todo-denbond7 fix me
/*recipients.add(
pgpContact.toRecipientEntity().copy(id = entity.id)
)*/
}
}

FlowCryptRoomDatabase.getDatabase(weakRef.get()?.requireContext()!!).recipientDao()
.update(contacts)
recipientDao.update(recipients)
}
i = end + 1

Expand Down

0 comments on commit c36f3ad

Please sign in to comment.