From d51adab76b1d73dddefe77674cf753203a1955e2 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 12 Jun 2014 08:59:54 -0700 Subject: [PATCH] Use "date sent" as timestamp for push, "date received" for SMS. The "sent time" is not reliable on SMS messages. This switches to using "sent time" by default for push messages, but "received time" for SMS messages. --- .../thoughtcrime/securesms/ConversationItem.java | 5 ++++- .../securesms/database/ThreadDatabase.java | 16 ++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index 9171bb8dcc..9553952a59 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -266,7 +266,10 @@ public class ConversationItem extends LinearLayout { } else if (messageRecord.isPending()) { dateText.setText(" ยทยทยท "); } else { - final long timestamp = messageRecord.getDateSent(); + final long timestamp; + + if (messageRecord.isPush()) timestamp = messageRecord.getDateSent(); + else timestamp = messageRecord.getDateReceived(); dateText.setText(DateUtils.getBetterRelativeTimeSpanString(getContext(), timestamp)); } diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index c519414de9..933a6c13b1 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -23,15 +23,14 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; -import org.whispersystems.textsecure.crypto.InvalidMessageException; -import org.whispersystems.textsecure.crypto.MasterCipher; -import org.whispersystems.textsecure.crypto.MasterSecret; import org.thoughtcrime.securesms.database.model.DisplayRecord; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.Recipients; +import org.whispersystems.textsecure.crypto.InvalidMessageException; +import org.whispersystems.textsecure.crypto.MasterCipher; import org.whispersystems.textsecure.util.Util; import java.util.Arrays; @@ -379,11 +378,16 @@ public class ThreadDatabase extends Database { MmsSmsDatabase.Reader reader = null; try { - reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId)); - MessageRecord record = null; + reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId)); + MessageRecord record; if (reader != null && (record = reader.getNext()) != null) { - updateThread(threadId, count, record.getBody().getBody(), record.getDateReceived(), record.getType()); + final long timestamp; + + if (record.isPush()) timestamp = record.getDateSent(); + else timestamp = record.getDateReceived(); + + updateThread(threadId, count, record.getBody().getBody(), timestamp, record.getType()); } else { deleteThread(threadId); }