Skip to content

Commit

Permalink
Merge pull request #1928 from Infomaniak/fix-npe
Browse files Browse the repository at this point in the history
Fix NPE when trying to get local contact email
  • Loading branch information
KevinBoulongne committed Jun 20, 2024
2 parents b1c02da + 686f249 commit 7387631
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/infomaniak/mail/utils/ContactUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ object ContactUtils {
}

private fun Context.getLocalEmails(): Map<Long, Set<String>> {
val mailDictionary: MutableMap<Long, MutableSet<String>> = mutableMapOf()
val mailDictionary = mutableMapOf<Long, MutableSet<String>>()
val projection = arrayOf(Email.CONTACT_ID, Email.ADDRESS)
val contentUri = Email.CONTENT_URI

contentResolver.query(contentUri, projection, null, null, null)?.use { cursor ->
while (cursor.moveToNext()) {
val address = cursor.getString(cursor.getColumnIndexOrThrow(Email.ADDRESS)) ?: continue
val id = cursor.getLong(cursor.getColumnIndexOrThrow(Email.CONTACT_ID))
val address = cursor.getString(cursor.getColumnIndexOrThrow(Email.ADDRESS))

mailDictionary[id]?.add(address) ?: run { mailDictionary[id] = mutableSetOf(address) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ import javax.inject.Inject
import javax.inject.Singleton

/**
* When user doesn't have PlayServices, we can't receive push notifications via
* `ProcessMessageNotificationsWorker`. So we have to routinely fetch Messages.
* When the user doesn't have PlayServices, we can't receive push notifications via `ProcessMessageNotificationsWorker`.
* So we have to routinely fetch Messages (every ~15 min).
*
* This Worker is also used to fetch Messages every few hours (~4h),
* even if the user has PlayServices, to be sure that we are up-to-date.
*/
@HiltWorker
class SyncMailboxesWorker @AssistedInject constructor(
Expand Down

0 comments on commit 7387631

Please sign in to comment.