mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Change the way notifications work for non-default KitKat.
Messages that are not "secure" (encrypted or key exchange) are automatically marked as read if TextSecure isn't the default KitKat SMS app. This change in functionality allows people who aren't using TextSecure as a default SMS app on KitKat to still receive notifications when they get incoming encrypted messages.
This commit is contained in:
parent
99d295abc5
commit
7489f3463a
@ -360,6 +360,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
{
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (Util.isDefaultSmsProvider(context)) {
|
||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||
}
|
||||
|
||||
Trimmer.trimThread(context, threadId);
|
||||
}
|
||||
|
||||
|
@ -245,13 +245,14 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
Recipient recipient = new Recipient(null, message.getSender(), null, null);
|
||||
Recipients recipients = new Recipients(recipient);
|
||||
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);
|
||||
|
||||
if (unread) {
|
||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||
}
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||
notifyConversationListeners(threadId);
|
||||
Trimmer.trimThread(context, threadId);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user