0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 12:12:15 +02:00

Merge pull request #6604 from thundernest/more_MessageStore

Rewrite `MessagingController.loadMoreMessages()` to not use `LocalStore`
This commit is contained in:
cketti 2023-01-27 14:02:34 +01:00 committed by GitHub
commit d90800886d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 16 deletions

View File

@ -506,18 +506,24 @@ public class MessagingController {
}
}
public void loadMoreMessages(Account account, long folderId) {
putBackground("loadMoreMessages", null, () -> loadMoreMessagesSynchronous(account, folderId));
}
public void loadMoreMessages(Account account, long folderId, MessagingListener listener) {
try {
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(folderId);
if (localFolder.getVisibleLimit() > 0) {
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
}
synchronizeMailbox(account, folderId, false, listener);
} catch (MessagingException me) {
throw new RuntimeException("Unable to set visible limit on folder", me);
public void loadMoreMessagesSynchronous(Account account, long folderId) {
MessageStore messageStore = messageStoreManager.getMessageStore(account);
Integer visibleLimit = messageStore.getFolder(folderId, FolderDetailsAccessor::getVisibleLimit);
if (visibleLimit == null) {
Timber.v("loadMoreMessages(%s, %d): Folder not found", account, folderId);
return;
}
if (visibleLimit > 0) {
int newVisibleLimit = visibleLimit + account.getDisplayCount();
messageStore.setVisibleLimit(folderId, newVisibleLimit);
}
synchronizeMailboxSynchronous(account, folderId, false, null, new NotificationState());
}
/**

View File

@ -269,11 +269,6 @@ public class LocalFolder {
});
}
public int getVisibleLimit() throws MessagingException {
open();
return visibleLimit;
}
public void setVisibleLimit(final int visibleLimit) throws MessagingException {
updateMoreMessagesOnVisibleLimitChange(visibleLimit, this.visibleLimit);

View File

@ -276,6 +276,11 @@ interface MessageStore {
*/
fun setStatus(folderId: Long, status: String?)
/**
* Update a folder's "visible limit" value.
*/
fun setVisibleLimit(folderId: Long, visibleLimit: Int)
/**
* Delete folders.
*/

View File

@ -224,6 +224,10 @@ class K9MessageStore(
updateFolderOperations.setStatus(folderId, status)
}
override fun setVisibleLimit(folderId: Long, visibleLimit: Int) {
updateFolderOperations.setVisibleLimit(folderId, visibleLimit)
}
override fun deleteFolders(folderServerIds: List<String>) {
deleteFolderOperations.deleteFolders(folderServerIds)
}

View File

@ -79,6 +79,16 @@ internal class UpdateFolderOperations(private val lockableDatabase: LockableData
setString(folderId = folderId, columnName = "status", value = status)
}
fun setVisibleLimit(folderId: Long, visibleLimit: Int) {
lockableDatabase.execute(false) { db ->
val contentValues = ContentValues().apply {
put("visible_limit", visibleLimit)
}
db.update("folders", contentValues, "id = ?", arrayOf(folderId.toString()))
}
}
private fun setString(folderId: Long, columnName: String, value: String?) {
lockableDatabase.execute(false) { db ->
val contentValues = ContentValues().apply {

View File

@ -152,4 +152,15 @@ class UpdateFolderOperationsTest : RobolectricTest() {
assertThat(folder.id).isEqualTo(folderId)
assertThat(folder.status).isEqualTo("Sync error")
}
@Test
fun `update visible limit`() {
val folderId = sqliteDatabase.createFolder(visibleLimit = 10)
updateFolderOperations.setVisibleLimit(folderId = folderId, visibleLimit = 25)
val folder = sqliteDatabase.readFolders().first()
assertThat(folder.id).isEqualTo(folderId)
assertThat(folder.visibleLimit).isEqualTo(25)
}
}

View File

@ -485,7 +485,7 @@ class MessageListFragment :
if (currentFolder.moreMessages && !localSearch.isManualSearch) {
val folderId = currentFolder.databaseId
messagingController.loadMoreMessages(account, folderId, null)
messagingController.loadMoreMessages(account, folderId)
} else if (isRemoteSearch) {
val additionalSearchResults = extraSearchResults ?: return
if (additionalSearchResults.isEmpty()) return