diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index 4ef30d33eb..8948ff6123 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -20,11 +20,12 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.net.Uri; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.text.TextUtils; import android.util.Pair; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.annimon.stream.Collectors; import com.annimon.stream.Stream; import com.google.android.mms.pdu_alt.NotificationInd; @@ -840,13 +841,10 @@ public class MmsDatabase extends MessagingDatabase { contentValues.put(THREAD_ID, threadId); contentValues.put(CONTENT_LOCATION, contentLocation); contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); - // If the messages are from open groups, there will be a serverTimestamp, - // we use current time like a sortId of iOS as the receive time. - // Since the messages has been sorted by server timestamp before they are processed, - // the order here by actual receiving time should be correct. - long receiveTimestamp = serverTimestamp; - if (serverTimestamp == 0) { receiveTimestamp = retrieved.getSentTimeMillis(); } - contentValues.put(DATE_RECEIVED, receiveTimestamp); // Loki - This is important due to how we handle GIFs + // In open groups messages should be sorted by their server timestamp + long receivedTimestamp = serverTimestamp; + if (serverTimestamp == 0) { receivedTimestamp = retrieved.getSentTimeMillis(); } + contentValues.put(DATE_RECEIVED, receivedTimestamp); // Loki - This is important due to how we handle GIFs contentValues.put(PART_COUNT, retrieved.getAttachments().size()); contentValues.put(SUBSCRIPTION_ID, retrieved.getSubscriptionId()); contentValues.put(EXPIRES_IN, retrieved.getExpiresIn()); diff --git a/src/org/thoughtcrime/securesms/database/SmsDatabase.java b/src/org/thoughtcrime/securesms/database/SmsDatabase.java index aa9aeabdaf..ee4527d00b 100644 --- a/src/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -20,10 +20,11 @@ package org.thoughtcrime.securesms.database; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; -import androidx.annotation.NonNull; import android.text.TextUtils; import android.util.Pair; +import androidx.annotation.NonNull; + import com.annimon.stream.Stream; import net.sqlcipher.database.SQLiteDatabase; @@ -625,13 +626,10 @@ public class SmsDatabase extends MessagingDatabase { ContentValues values = new ContentValues(6); values.put(ADDRESS, message.getSender().serialize()); values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId()); - // If the messages are from open groups, there will be a serverTimestamp, - // we use current time like a sortId of iOS as the receive time. - // Since the messages has been sorted by server timestamp before they are processed, - // the order here by actual receiving time should be correct. - long receiveTimestamp = serverTimestamp; - if (serverTimestamp == 0) { receiveTimestamp = message.getSentTimestampMillis(); } - values.put(DATE_RECEIVED, receiveTimestamp); // Loki - This is important due to how we handle GIFs + // In open groups messages should be sorted by their server timestamp + long receivedTimestamp = serverTimestamp; + if (serverTimestamp == 0) { receivedTimestamp = message.getSentTimestampMillis(); } + values.put(DATE_RECEIVED, receivedTimestamp); // Loki - This is important due to how we handle GIFs values.put(DATE_SENT, message.getSentTimestampMillis()); values.put(PROTOCOL, message.getProtocol()); values.put(READ, unread ? 0 : 1);