mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +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
@ -358,8 +358,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
String contentLocation, long threadId, long mailbox)
|
String contentLocation, long threadId, long mailbox)
|
||||||
throws MmsException
|
throws MmsException
|
||||||
{
|
{
|
||||||
PduHeaders headers = retrieved.getPduHeaders();
|
PduHeaders headers = retrieved.getPduHeaders();
|
||||||
ContentValues contentValues = getContentValuesFromHeader(headers);
|
ContentValues contentValues = getContentValuesFromHeader(headers);
|
||||||
|
boolean unread = Util.isDefaultSmsProvider(context) || ((mailbox & Types.SECURE_MESSAGE_BIT) != 0);
|
||||||
|
|
||||||
if (!Util.isEmpty(retrieved.getCc())) {
|
if (!Util.isEmpty(retrieved.getCc())) {
|
||||||
try {
|
try {
|
||||||
@ -374,13 +375,17 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
contentValues.put(CONTENT_LOCATION, contentLocation);
|
contentValues.put(CONTENT_LOCATION, contentLocation);
|
||||||
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
||||||
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
||||||
|
contentValues.put(READ, unread ? 0 : 1);
|
||||||
|
|
||||||
if (!contentValues.containsKey(DATE_SENT))
|
if (!contentValues.containsKey(DATE_SENT))
|
||||||
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
||||||
|
|
||||||
long messageId = insertMediaMessage(masterSecret, retrieved, contentValues);
|
long messageId = insertMediaMessage(masterSecret, retrieved, contentValues);
|
||||||
|
|
||||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
if (unread) {
|
||||||
|
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||||
|
}
|
||||||
|
|
||||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
Trimmer.trimThread(context, threadId);
|
Trimmer.trimThread(context, threadId);
|
||||||
@ -427,6 +432,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
contentValues.put(THREAD_ID, threadId);
|
contentValues.put(THREAD_ID, threadId);
|
||||||
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
||||||
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
||||||
|
contentValues.put(READ, Util.isDefaultSmsProvider(context) ? 0 : 1);
|
||||||
|
|
||||||
if (!contentValues.containsKey(DATE_SENT))
|
if (!contentValues.containsKey(DATE_SENT))
|
||||||
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
||||||
@ -449,7 +455,11 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
public void markIncomingNotificationReceived(long threadId) {
|
public void markIncomingNotificationReceived(long threadId) {
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||||
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
|
||||||
|
if (Util.isDefaultSmsProvider(context)) {
|
||||||
|
DatabaseFactory.getThreadDatabase(context).setUnread(threadId);
|
||||||
|
}
|
||||||
|
|
||||||
Trimmer.trimThread(context, threadId);
|
Trimmer.trimThread(context, threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,16 +242,17 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
type |= Types.ENCRYPTION_REMOTE_BIT;
|
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);
|
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);
|
ContentValues values = new ContentValues(6);
|
||||||
values.put(ADDRESS, message.getSender());
|
values.put(ADDRESS, message.getSender());
|
||||||
values.put(DATE_RECEIVED, System.currentTimeMillis());
|
values.put(DATE_RECEIVED, System.currentTimeMillis());
|
||||||
values.put(DATE_SENT, message.getSentTimestampMillis());
|
values.put(DATE_SENT, message.getSentTimestampMillis());
|
||||||
values.put(PROTOCOL, message.getProtocol());
|
values.put(PROTOCOL, message.getProtocol());
|
||||||
values.put(READ, 0);
|
values.put(READ, unread ? 0 : 1);
|
||||||
|
|
||||||
if (!Util.isEmpty(message.getPseudoSubject()))
|
if (!Util.isEmpty(message.getPseudoSubject()))
|
||||||
values.put(SUBJECT, message.getPseudoSubject());
|
values.put(SUBJECT, message.getPseudoSubject());
|
||||||
@ -265,7 +266,10 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
long messageId = db.insert(TABLE_NAME, null, values);
|
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);
|
DatabaseFactory.getThreadDatabase(context).update(threadId);
|
||||||
notifyConversationListeners(threadId);
|
notifyConversationListeners(threadId);
|
||||||
Trimmer.trimThread(context, 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.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -104,10 +103,6 @@ public class MessageNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Util.isDefaultSmsProvider(context)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateNotification(context, masterSecret, false);
|
updateNotification(context, masterSecret, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,10 +113,6 @@ public class MessageNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Util.isDefaultSmsProvider(context)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (visibleThread == threadId) {
|
if (visibleThread == threadId) {
|
||||||
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
||||||
sendInThreadNotification(context);
|
sendInThreadNotification(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user