diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index c7d145b2fc..64901f9862 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -358,8 +358,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns { String contentLocation, long threadId, long mailbox) throws MmsException { - PduHeaders headers = retrieved.getPduHeaders(); + PduHeaders headers = retrieved.getPduHeaders(); ContentValues contentValues = getContentValuesFromHeader(headers); + boolean unread = Util.isDefaultSmsProvider(context) || ((mailbox & Types.SECURE_MESSAGE_BIT) != 0); if (!Util.isEmpty(retrieved.getCc())) { try { @@ -374,13 +375,17 @@ public class MmsDatabase extends Database implements MmsSmsColumns { contentValues.put(CONTENT_LOCATION, contentLocation); contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000); + contentValues.put(READ, unread ? 0 : 1); if (!contentValues.containsKey(DATE_SENT)) contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED)); long messageId = insertMediaMessage(masterSecret, retrieved, contentValues); - DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + if (unread) { + DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + } + DatabaseFactory.getThreadDatabase(context).update(threadId); notifyConversationListeners(threadId); Trimmer.trimThread(context, threadId); @@ -427,6 +432,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns { contentValues.put(THREAD_ID, threadId); contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED); contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000); + contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1); if (!contentValues.containsKey(DATE_SENT)) contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED)); @@ -449,7 +455,11 @@ public class MmsDatabase extends Database implements MmsSmsColumns { public void markIncomingNotificationReceived(long threadId) { notifyConversationListeners(threadId); DatabaseFactory.getThreadDatabase(context).update(threadId); - DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + + if (Util.isDefaultSmsProvider(context)) { + DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + } + Trimmer.trimThread(context, threadId); } diff --git a/src/org/thoughtcrime/securesms/database/SmsDatabase.java b/src/org/thoughtcrime/securesms/database/SmsDatabase.java index b2f52f47f7..6f772eca33 100644 --- a/src/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -242,16 +242,17 @@ public class SmsDatabase extends Database implements MmsSmsColumns { type |= Types.ENCRYPTION_REMOTE_BIT; } - Recipient recipient = new Recipient(null, message.getSender(), null, null); + Recipient recipient = new Recipient(null, message.getSender(), null, null); Recipients recipients = new Recipients(recipient); - long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); + long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients); + boolean unread = Util.isDefaultSmsProvider(context) || message.isSecureMessage() || message.isKeyExchange(); ContentValues values = new ContentValues(6); values.put(ADDRESS, message.getSender()); values.put(DATE_RECEIVED, System.currentTimeMillis()); values.put(DATE_SENT, message.getSentTimestampMillis()); values.put(PROTOCOL, message.getProtocol()); - values.put(READ, 0); + values.put(READ, unread ? 0 : 1); if (!Util.isEmpty(message.getPseudoSubject())) values.put(SUBJECT, message.getPseudoSubject()); @@ -265,7 +266,10 @@ public class SmsDatabase extends Database implements MmsSmsColumns { SQLiteDatabase db = databaseHelper.getWritableDatabase(); long messageId = db.insert(TABLE_NAME, null, values); - DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + if (unread) { + DatabaseFactory.getThreadDatabase(context).setUnread(threadId); + } + DatabaseFactory.getThreadDatabase(context).update(threadId); notifyConversationListeners(threadId); Trimmer.trimThread(context, threadId); diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 07b44e45eb..9351c55806 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -48,7 +48,6 @@ import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.model.MessageRecord; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipients; -import org.thoughtcrime.securesms.util.Util; import java.io.IOException; import java.util.List; @@ -104,10 +103,6 @@ public class MessageNotifier { return; } - if (!Util.isDefaultSmsProvider(context)) { - return; - } - updateNotification(context, masterSecret, false); } @@ -118,10 +113,6 @@ public class MessageNotifier { return; } - if (!Util.isDefaultSmsProvider(context)) { - return; - } - if (visibleThread == threadId) { DatabaseFactory.getThreadDatabase(context).setRead(threadId); sendInThreadNotification(context);