improved get messages task

This commit is contained in:
Mariotaku Lee 2017-04-22 01:46:04 +08:00
parent d1b175b524
commit d86dd71294
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 2 additions and 9 deletions

View File

@ -137,16 +137,13 @@ class GetMessagesTask(
val sincePagination = param.pagination?.get(accountsCount + index) as? SinceMaxPagination
val firstFetch by lazy {
val firstFetchPref = preferences.getBoolean(KEY_FIRST_FETCH, true)
val noConversationsBefore = DataStoreUtils.queryCount(context.contentResolver,
Conversations.CONTENT_URI, Expression.equalsArgs(Conversations.ACCOUNT_KEY).sql,
arrayOf(accountKey.toString())) <= 0
return@lazy noConversationsBefore && firstFetchPref
return@lazy noConversationsBefore
}
val updateLastRead = param.pagination?.all {
(it as? SinceMaxPagination)?.maxId != null
} ?: false || firstFetch
val updateLastRead = param.hasMaxIds || firstFetch
val received = microBlog.getDirectMessages(Paging().apply {
count(100)
@ -194,10 +191,6 @@ class GetMessagesTask(
true, profileImageSize, updateLastRead)
}
if (firstFetch) {
preferences.edit().putBoolean(KEY_FIRST_FETCH, false).apply()
}
return DatabaseUpdateData(conversations.values, insertMessages)
}