fixed mark read logic

This commit is contained in:
Mariotaku Lee 2017-02-17 19:34:02 +08:00
parent b848271117
commit f22acb2790
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 31 additions and 20 deletions

View File

@ -45,18 +45,16 @@ public class TwitterOfficialConversationExtras extends ConversationExtras implem
@JsonField(name = "status")
@DMResponse.Status
public String status;
@JsonField(name = "last_read_event_id")
public String lastReadEventId;
@JsonField(name = "last_read_event_timestamp")
public long lastReadEventTimestamp;
@JsonField(name = "max_entry_timestamp")
public long maxEntryTimestamp;
@Override
public String toString() {
return "TwitterOfficialConversationExtras{" +
"lastReadEventId='" + lastReadEventId + '\'' +
", maxEntryId='" + maxEntryId + '\'' +
"maxEntryId='" + maxEntryId + '\'' +
", minEntryId='" + minEntryId + '\'' +
", status='" + status + '\'' +
", maxEntryTimestamp=" + maxEntryTimestamp +
"} " + super.toString();
}

View File

@ -160,10 +160,6 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
loaderManager.initLoader(0, null, this)
showProgress()
if (savedInstanceState == null) {
markRead()
}
}
override fun onStart() {
@ -210,6 +206,10 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment<Messages
adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE
}
showContent()
if (conversation != null && !conversation.is_temp) {
markRead()
}
}
override fun onCreateAdapter(context: Context): MessagesConversationAdapter {

View File

@ -398,12 +398,19 @@ class GetMessagesTask(
if (myLastReadTimestamp > 0) {
conversation.last_read_timestamp = myLastReadTimestamp
}
conversation.conversation_extras = TwitterOfficialConversationExtras().apply {
val conversationExtras = conversation.conversation_extras as? TwitterOfficialConversationExtras ?: run {
val extras = TwitterOfficialConversationExtras()
conversation.conversation_extras = extras
return@run extras
}
conversationExtras.apply {
this.minEntryId = v.minEntryId
this.maxEntryId = v.maxEntryId
this.status = v.status
this.lastReadEventId = v.lastReadEventId
this.lastReadEventTimestamp = messagesMap.findLastReadTimestamp(k, v.lastReadEventId)
val maxEntryTimestamp = messagesMap.findLastReadTimestamp(k, maxEntryId)
if (maxEntryTimestamp > 0) {
this.maxEntryTimestamp = maxEntryTimestamp
}
}
}
return DatabaseUpdateData(conversations.values, messages, conversationDeletions,

View File

@ -74,10 +74,14 @@ class MarkMessageReadTask(
when (account.type) {
AccountType.TWITTER -> {
if (account.isOfficial(context)) {
val event = (conversation.conversation_extras as? TwitterOfficialConversationExtras)?.lastReadEvent ?: run {
val event = (conversation.conversation_extras as? TwitterOfficialConversationExtras)?.maxReadEvent ?: run {
val message = findRecentMessage(accountKey, conversationId) ?: return null
return@run Pair(message.id, message.timestamp)
}
if (conversation.last_read_timestamp > event.second) {
// Local is newer, ignore network request
return event
}
if (microBlog.markDmRead(conversation.id, event.first).isSuccessful) {
return event
}
@ -122,11 +126,11 @@ class MarkMessageReadTask(
return null
}
private val TwitterOfficialConversationExtras.lastReadEvent: Pair<String, Long>?
private val TwitterOfficialConversationExtras.maxReadEvent: Pair<String, Long>?
get() {
val id = lastReadEventId ?: return null
if (lastReadEventTimestamp < 0) return null
return Pair(id, lastReadEventTimestamp)
val id = maxEntryId ?: return null
if (maxEntryTimestamp < 0) return null
return Pair(id, maxEntryTimestamp)
}

View File

@ -14,6 +14,7 @@ import android.view.View.OnLongClickListener
import android.widget.ImageView
import kotlinx.android.synthetic.main.list_item_status.view.*
import org.mariotaku.ktextension.applyFontFamily
import org.mariotaku.ktextension.isNotNullOrEmpty
import org.mariotaku.twidere.Constants.*
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
@ -314,15 +315,16 @@ class StatusViewHolder(private val adapter: IStatusesAdapter<*>, itemView: View)
itemContent.drawEnd()
}
if (status.media?.isNotEmpty() ?: false) {
if (status.media.isNotNullOrEmpty()) {
if (!adapter.sensitiveContentEnabled && status.is_possibly_sensitive) {
// Sensitive content, show label instead of media view
mediaLabel.visibility = View.VISIBLE
mediaLabel.contentDescription = status.media?.firstOrNull()?.alt_text
mediaPreview.visibility = View.GONE
} else if (!adapter.mediaPreviewEnabled) {
// Media preview disabled, just show label
mediaLabel.visibility = View.VISIBLE
mediaLabel.contentDescription = status.media?.firstOrNull()?.alt_text
mediaPreview.visibility = View.GONE
} else {
// Show media