mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-08 07:48:45 +01:00
possible fix to #749
This commit is contained in:
parent
629f0ae0f6
commit
0e607ad4d3
@ -29,6 +29,7 @@ import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.ParcelableMessageConversation
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.event.UnreadCountUpdatedEvent
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Messages.Conversations
|
||||
import org.mariotaku.twidere.task.ExceptionHandlingAbstractTask
|
||||
@ -63,7 +64,10 @@ class BatchMarkMessageReadTask(
|
||||
cur.forEachRow { cur, _ ->
|
||||
val conversation = indices.newObject(cur)
|
||||
try {
|
||||
MarkMessageReadTask.performMarkRead(context, microBlog, account, conversation)
|
||||
val lastReadEvent = MarkMessageReadTask.performMarkRead(context, microBlog,
|
||||
account, conversation) ?: return@forEachRow false
|
||||
MarkMessageReadTask.updateLocalLastRead(cr, account.key, conversation.id,
|
||||
lastReadEvent)
|
||||
return@forEachRow true
|
||||
} catch (e: MicroBlogException) {
|
||||
return@forEachRow false
|
||||
@ -73,4 +77,7 @@ class BatchMarkMessageReadTask(
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSucceed(callback: Unit?, result: Boolean) {
|
||||
bus.post(UnreadCountUpdatedEvent(-1))
|
||||
}
|
||||
}
|
||||
|
@ -67,15 +67,7 @@ class MarkMessageReadTask(
|
||||
val lastReadEvent = conversation?.let {
|
||||
return@let performMarkRead(context, microBlog, account, conversation)
|
||||
} ?: return false
|
||||
val values = ContentValues()
|
||||
values.put(Conversations.LAST_READ_ID, lastReadEvent.first)
|
||||
values.put(Conversations.LAST_READ_TIMESTAMP, lastReadEvent.second)
|
||||
val updateWhere = Expression.and(Expression.equalsArgs(Conversations.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Conversations.CONVERSATION_ID),
|
||||
Expression.lesserThanArgs(Conversations.LAST_READ_TIMESTAMP)).sql
|
||||
val updateWhereArgs = arrayOf(accountKey.toString(), conversationId,
|
||||
lastReadEvent.second.toString())
|
||||
context.contentResolver.update(Conversations.CONTENT_URI, values, updateWhere, updateWhereArgs)
|
||||
updateLocalLastRead(context.contentResolver, accountKey, conversationId, lastReadEvent)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -111,6 +103,18 @@ class MarkMessageReadTask(
|
||||
return Pair(message.id, message.timestamp)
|
||||
}
|
||||
|
||||
internal fun updateLocalLastRead(cr: ContentResolver, accountKey: UserKey,
|
||||
conversationId: String, lastRead: Pair<String, Long>) {
|
||||
val values = ContentValues()
|
||||
values.put(Conversations.LAST_READ_ID, lastRead.first)
|
||||
values.put(Conversations.LAST_READ_TIMESTAMP, lastRead.second)
|
||||
val updateWhere = Expression.and(Expression.equalsArgs(Conversations.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(Conversations.CONVERSATION_ID),
|
||||
Expression.lesserThanArgs(Conversations.LAST_READ_TIMESTAMP)).sql
|
||||
val updateWhereArgs = arrayOf(accountKey.toString(), conversationId,
|
||||
lastRead.second.toString())
|
||||
cr.update(Conversations.CONTENT_URI, values, updateWhere, updateWhereArgs)
|
||||
}
|
||||
|
||||
private fun ContentResolver.findRecentMessage(accountKey: UserKey, conversationId: String): ParcelableMessage? {
|
||||
val where = Expression.and(Expression.equalsArgs(Messages.ACCOUNT_KEY),
|
||||
|
Loading…
x
Reference in New Issue
Block a user