Skip to content

Commit

Permalink
refactor: Clean code (#2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne authored Feb 12, 2025
2 parents fd45aec + 38fea2d commit 085d402
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ class RefreshController @Inject constructor(

var totalNewThreads = 0
var upToDateFolder = getUpToDateFolder(folderId)
var maxPagesToFetch = Utils.MAX_OLD_PAGES_TO_FETCH_TO_GET_ENOUGH_NEW_THREADS
var maxPagesToFetch = Utils.MAX_OLD_PAGES_TO_FETCH_TO_GET_ENOUGH_THREADS

while (
totalNewThreads < Utils.PAGE_SIZE / 2 &&
totalNewThreads < Utils.MIN_THREADS_TO_GET_ENOUGH_THREADS &&
upToDateFolder.oldMessagesUidsToFetch.isNotEmpty() &&
maxPagesToFetch > 0
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Folder : RealmObject, Cloneable {
val rolePropertyName = Folder::_role.name
val parentsPropertyName = Folder::_parents.name

const val INBOX_FOLDER_ID = "eJzz9HPyjwAABGYBgQ--"
const val DUMMY_FOLDER_ID = "eJzz9HPyjwAABGYBgQ--" // Fun fact: It's actually the INBOX folder id. But nobody cares.
private const val CUSTOM_FOLDER_ROLE_ORDER = 0
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class MainActivity : BaseActivity() {
Shortcuts.SEARCH.id -> {
navController.navigate(
R.id.searchFragment,
SearchFragmentArgs(dummyFolderId = mainViewModel.currentFolderId ?: Folder.INBOX_FOLDER_ID).toBundle(),
SearchFragmentArgs(dummyFolderId = mainViewModel.currentFolderId ?: Folder.DUMMY_FOLDER_ID).toBundle(),
)
}
Shortcuts.NEW_MESSAGE.id -> navController.navigate(R.id.newMessageActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ThreadListFragment : TwoPaneFragment() {
// We need a valid Folder ID for the API call to not fail, but the value itself won't be used.
// So if we don't have any, we use a hardcoded one (corresponding to "INBOX" folder).
ThreadListFragmentDirections.actionThreadListFragmentToSearchFragment(
dummyFolderId = mainViewModel.currentFolderId ?: Folder.INBOX_FOLDER_ID
dummyFolderId = mainViewModel.currentFolderId ?: Folder.DUMMY_FOLDER_ID
),
)
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ object SentryDebug {
category = "Cursor",
message = message,
data = mapOf(
"folderName" to folder.name,
"previousFolderCursor" to "${folder.cursor}",
"newFolderCursor" to "$cursor",
"folderRole or folderId" to folder.displayForSentry(),
"previous folderCursor" to "${folder.cursor}",
"new folderCursor" to "$cursor",
),
)
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/infomaniak/mail/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ object Utils {
const val NUMBER_OF_OLD_UIDS_TO_FETCH = 10_000 // Total number of Messages we will ever fetch in a Folder history
const val NUMBER_OF_OLD_MESSAGES_TO_FETCH = 500 // Number of Messages we want to fetch when 1st opening a Folder
const val PAGE_SIZE = 50 // Beware: the API refuses a PAGE_SIZE bigger than 200
const val MAX_OLD_PAGES_TO_FETCH_TO_GET_ENOUGH_NEW_THREADS = 5 // We don't want to spam the API, so we just get a few pages
const val MIN_THREADS_TO_GET_ENOUGH_THREADS = PAGE_SIZE / 2 // We want to get at least 25 Threads when we fetch 1 old page
const val MAX_OLD_PAGES_TO_FETCH_TO_GET_ENOUGH_THREADS = 5 // We don't want to spam the API, so we just get a few pages

const val MAX_UIDS_PER_CALL = 1_000 // Beware: the API refuses a MAX_UIDS_PER_CALL bigger than 1000

Expand Down

0 comments on commit 085d402

Please sign in to comment.