improved my last read timestamp

This commit is contained in:
Mariotaku Lee 2017-02-17 00:34:36 +08:00
parent 4bd54354fa
commit 168abbd100
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 24 additions and 4 deletions

View File

@ -667,6 +667,8 @@ public class DMResponse implements Parcelable {
String userId;
@JsonField(name = "join_time")
long joinTime;
@JsonField(name = "last_read_event_id")
String lastReadEventId;
public String getUserId() {
return userId;
@ -676,6 +678,10 @@ public class DMResponse implements Parcelable {
return joinTime;
}
public String getLastReadEventId() {
return lastReadEventId;
}
@Override
public int describeContents() {
return 0;

View File

@ -23,6 +23,7 @@ package org.mariotaku.twidere.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import com.bluelinelabs.logansquare.annotation.JsonField;
@ -142,10 +143,17 @@ public class ParcelableMessageConversation implements Parcelable {
@CursorField(value = Conversations.REQUEST_CURSOR)
public String request_cursor;
/**
* Last read id of <b>current</b> user
*/
@JsonField(name = "last_read_id")
@CursorField(value = Conversations.LAST_READ_ID)
@Nullable
public String last_read_id;
/**
* Last read timestamp of <b>current</b> user
*/
@JsonField(name = "last_read_timestamp")
@CursorField(value = Conversations.LAST_READ_TIMESTAMP)
public long last_read_timestamp;

View File

@ -343,6 +343,8 @@ class GetMessagesTask(
fun createDatabaseUpdateData(context: Context, account: AccountDetails, response: DMResponse):
DatabaseUpdateData {
val accountKey = account.key
val respConversations = response.conversations.orEmpty()
val respEntries = response.entries.orEmpty()
val respUsers = response.users.orEmpty()
@ -388,12 +390,12 @@ class GetMessagesTask(
conversation.conversation_avatar = v.avatarImageHttps
conversation.request_cursor = response.cursor
conversation.conversation_extras_type = ParcelableMessageConversation.ExtrasType.TWITTER_OFFICIAL
conversation.last_read_id = v.lastReadEventId
val longEventId = v.lastReadEventId.toLong(-1)
conversation.last_read_id = v.participants.first { it.userId == accountKey.id }?.lastReadEventId
val longEventId = conversation.last_read_id.toLong(-1)
// Find recent message timestamp
conversation.last_read_timestamp = messagesMap[k]?.filter { message ->
if (message.id == v.lastReadEventId) return@filter true
if (longEventId > 0 && longEventId < message.id.toLong(-1)) return@filter true
if (message.id == conversation.last_read_id) return@filter true
if (longEventId > 0 && longEventId >= message.id.toLong(-1)) return@filter true
return@filter false
}?.maxBy(ParcelableMessage::message_timestamp)?.message_timestamp ?: -1
conversation.conversation_extras = TwitterOfficialConversationExtras().apply {

View File

@ -240,6 +240,10 @@ class ContentNotificationManager(
Utils.sendPebbleNotification(context, context.getString(R.string.interactions), pebbleNotificationStringBuilder.toString())
}
fun showMessages(pref: AccountPreferences) {
}
private fun applyNotificationPreferences(builder: NotificationCompat.Builder, pref: AccountPreferences, defaultFlags: Int) {
var notificationDefaults = 0
if (AccountPreferences.isNotificationHasLight(defaultFlags)) {