Don't redisplay notifications after they have been dismissed

Fixes #5751
Fixes #6218
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-03-08 17:38:55 -08:00
parent 33e0b4fc6d
commit 2f46c6ca1f
18 changed files with 141 additions and 88 deletions

View File

@ -544,9 +544,9 @@
</intent-filter>
</receiver>
<receiver android:name=".notifications.MessageNotifier$DeleteReceiver">
<receiver android:name=".notifications.DeleteNotificationReceiver">
<intent-filter>
<action android:name="org.thoughtcrime.securesms.MessageNotifier.DELETE_REMINDER_ACTION"/>
<action android:name="org.thoughtcrime.securesms.DELETE_NOTIFICATION"/>
</intent-filter>
</receiver>

View File

@ -8,7 +8,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath files('libs/gradle-witness.jar')
}
}
@ -189,7 +189,7 @@ dependencyVerification {
android {
compileSdkVersion 25
buildToolsVersion '23.0.3'
buildToolsVersion '25.0.0'
useLibrary 'org.apache.http.legacy'
dexOptions {

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

View File

@ -257,7 +257,7 @@ public class RedPhoneService extends Service implements CallStateListener {
private void handleMissedCall(String remoteNumber, boolean signal) {
Pair<Long, Long> messageAndThreadId = DatabaseFactory.getSmsDatabase(this).insertMissedCall(remoteNumber);
MessageNotifier.updateNotification(this, KeyCachingService.getMasterSecret(this),
false, messageAndThreadId.second, signal);
messageAndThreadId.second, signal);
}
private void handleAnswerCall(Intent intent) {

View File

@ -75,7 +75,8 @@ public class DatabaseFactory {
private static final int INTRODUCED_EXPIRE_MESSAGES_VERSION = 28;
private static final int INTRODUCED_LAST_SEEN = 29;
private static final int INTRODUCED_DIGEST = 30;
private static final int DATABASE_VERSION = 30;
private static final int INTRODUCED_NOTIFIED = 31;
private static final int DATABASE_VERSION = 31;
private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
@ -841,6 +842,17 @@ public class DatabaseFactory {
db.execSQL("ALTER TABLE groups ADD COLUMN avatar_digest BLOB");
}
if (oldVersion < INTRODUCED_NOTIFIED) {
db.execSQL("ALTER TABLE sms ADD COLUMN notified INTEGER DEFAULT 0");
db.execSQL("ALTER TABLE mms ADD COLUMN notified INTEGER DEFAULT 0");
db.execSQL("DROP INDEX sms_read_and_thread_id_index");
db.execSQL("CREATE INDEX IF NOT EXISTS sms_read_and_notified_and_thread_id_index ON sms(read,notified,thread_id)");
db.execSQL("DROP INDEX mms_read_and_thread_id_index");
db.execSQL("CREATE INDEX IF NOT EXISTS mms_read_and_notified_and_thread_id_index ON mms(read,notified,thread_id)");
}
db.setTransactionSuccessful();
db.endTransaction();
}

View File

@ -113,12 +113,12 @@ public class MmsDatabase extends MessagingDatabase {
RECEIPT_COUNT + " INTEGER DEFAULT 0, " + MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " +
NETWORK_FAILURE + " TEXT DEFAULT NULL," + "d_rpt" + " INTEGER, " +
SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " + EXPIRES_IN + " INTEGER DEFAULT 0, " +
EXPIRE_STARTED + " INTEGER DEFAULT 0);";
EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " INTEGER DEFAULT 0);";
public static final String[] CREATE_INDEXS = {
"CREATE INDEX IF NOT EXISTS mms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_read_index ON " + TABLE_NAME + " (" + READ + ");",
"CREATE INDEX IF NOT EXISTS mms_read_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_read_and_notified_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + NOTIFIED + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS mms_message_box_index ON " + TABLE_NAME + " (" + MESSAGE_BOX + ");",
"CREATE INDEX IF NOT EXISTS mms_date_sent_index ON " + TABLE_NAME + " (" + DATE_SENT + ");",
"CREATE INDEX IF NOT EXISTS mms_thread_date_index ON " + TABLE_NAME + " (" + THREAD_ID + ", " + DATE_RECEIVED + ");"
@ -133,7 +133,7 @@ public class MmsDatabase extends MessagingDatabase {
MESSAGE_SIZE, STATUS, TRANSACTION_ID,
BODY, PART_COUNT, ADDRESS, ADDRESS_DEVICE_ID,
RECEIPT_COUNT, MISMATCHED_IDENTITIES, NETWORK_FAILURE, SUBSCRIPTION_ID,
EXPIRES_IN, EXPIRE_STARTED,
EXPIRES_IN, EXPIRE_STARTED, NOTIFIED,
AttachmentDatabase.TABLE_NAME + "." + AttachmentDatabase.ROW_ID + " AS " + AttachmentDatabase.ATTACHMENT_ID_ALIAS,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
@ -458,6 +458,15 @@ public class MmsDatabase extends MessagingDatabase {
notifyConversationListeners(threadId);
}
public void markAsNotified(long id) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(NOTIFIED, 1);
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
}
public List<MarkedMessageInfo> setMessagesRead(long threadId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
String where = THREAD_ID + " = ? AND " + READ + " = 0";

View File

@ -17,6 +17,7 @@ public interface MmsSmsColumns {
public static final String SUBSCRIPTION_ID = "subscription_id";
public static final String EXPIRES_IN = "expires_in";
public static final String EXPIRE_STARTED = "expire_started";
public static final String NOTIFIED = "notified";
public static class Types {
protected static final long TOTAL_MASK = 0xFFFFFFFF;

View File

@ -56,7 +56,9 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.NETWORK_FAILURE,
MmsSmsColumns.SUBSCRIPTION_ID,
MmsSmsColumns.EXPIRES_IN,
MmsSmsColumns.EXPIRE_STARTED, TRANSPORT,
MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
TRANSPORT,
AttachmentDatabase.ATTACHMENT_ID_ALIAS,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
@ -107,13 +109,13 @@ public class MmsSmsDatabase extends Database {
public Cursor getUnread() {
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
String selection = MmsSmsColumns.READ + " = 0";
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0";
return queryTables(PROJECTION, selection, order, null);
}
public int getUnreadCount(long threadId) {
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId;
String selection = MmsSmsColumns.READ + " = 0 AND " + MmsSmsColumns.NOTIFIED + " = 0 AND " + MmsSmsColumns.THREAD_ID + " = " + threadId;
Cursor cursor = queryTables(PROJECTION, selection, null, null);
try {
@ -150,6 +152,7 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
MmsSmsColumns.RECEIPT_COUNT, MmsSmsColumns.MISMATCHED_IDENTITIES,
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
@ -177,6 +180,7 @@ public class MmsSmsDatabase extends Database {
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
MmsSmsColumns.RECEIPT_COUNT, MmsSmsColumns.MISMATCHED_IDENTITIES,
MmsSmsColumns.SUBSCRIPTION_ID, MmsSmsColumns.EXPIRES_IN, MmsSmsColumns.EXPIRE_STARTED,
MmsSmsColumns.NOTIFIED,
MmsDatabase.NETWORK_FAILURE, TRANSPORT,
AttachmentDatabase.UNIQUE_ID,
AttachmentDatabase.MMS_ID,
@ -227,6 +231,7 @@ public class MmsSmsDatabase extends Database {
mmsColumnsPresent.add(MmsDatabase.TRANSACTION_ID);
mmsColumnsPresent.add(MmsDatabase.MESSAGE_SIZE);
mmsColumnsPresent.add(MmsDatabase.EXPIRY);
mmsColumnsPresent.add(MmsDatabase.NOTIFIED);
mmsColumnsPresent.add(MmsDatabase.STATUS);
mmsColumnsPresent.add(MmsDatabase.NETWORK_FAILURE);
@ -255,6 +260,7 @@ public class MmsSmsDatabase extends Database {
smsColumnsPresent.add(MmsSmsColumns.SUBSCRIPTION_ID);
smsColumnsPresent.add(MmsSmsColumns.EXPIRES_IN);
smsColumnsPresent.add(MmsSmsColumns.EXPIRE_STARTED);
smsColumnsPresent.add(MmsSmsColumns.NOTIFIED);
smsColumnsPresent.add(SmsDatabase.TYPE);
smsColumnsPresent.add(SmsDatabase.SUBJECT);
smsColumnsPresent.add(SmsDatabase.DATE_SENT);

View File

@ -79,12 +79,12 @@ public class SmsDatabase extends MessagingDatabase {
STATUS + " INTEGER DEFAULT -1," + TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " +
RECEIPT_COUNT + " INTEGER DEFAULT 0," + SUBJECT + " TEXT, " + BODY + " TEXT, " +
MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " + SERVICE_CENTER + " TEXT, " + SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " +
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0);";
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " DEFAULT 0);";
public static final String[] CREATE_INDEXS = {
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_read_index ON " + TABLE_NAME + " (" + READ + ");",
"CREATE INDEX IF NOT EXISTS sms_read_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_read_and_notified_and_thread_id_index ON " + TABLE_NAME + "(" + READ + "," + NOTIFIED + "," + THREAD_ID + ");",
"CREATE INDEX IF NOT EXISTS sms_type_index ON " + TABLE_NAME + " (" + TYPE + ");",
"CREATE INDEX IF NOT EXISTS sms_date_sent_index ON " + TABLE_NAME + " (" + DATE_SENT + ");",
"CREATE INDEX IF NOT EXISTS sms_thread_date_index ON " + TABLE_NAME + " (" + THREAD_ID + ", " + DATE_RECEIVED + ");"
@ -96,7 +96,8 @@ public class SmsDatabase extends MessagingDatabase {
DATE_SENT + " AS " + NORMALIZED_DATE_SENT,
PROTOCOL, READ, STATUS, TYPE,
REPLY_PATH_PRESENT, SUBJECT, BODY, SERVICE_CENTER, RECEIPT_COUNT,
MISMATCHED_IDENTITIES, SUBSCRIPTION_ID, EXPIRES_IN, EXPIRE_STARTED
MISMATCHED_IDENTITIES, SUBSCRIPTION_ID, EXPIRES_IN, EXPIRE_STARTED,
NOTIFIED
};
private static final EarlyReceiptCache earlyReceiptCache = new EarlyReceiptCache();
@ -271,6 +272,15 @@ public class SmsDatabase extends MessagingDatabase {
updateTypeBitmask(id, Types.BASE_TYPE_MASK, Types.BASE_SENT_FAILED_TYPE);
}
public void markAsNotified(long id) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(NOTIFIED, 1);
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
}
public void incrementDeliveryReceiptCount(SyncMessageId messageId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
Cursor cursor = null;

View File

@ -111,7 +111,6 @@ public class PushDecryptJob extends ContextJob {
if (!IdentityKeyUtil.hasIdentityKey(context)) {
Log.w(TAG, "Skipping job, waiting for migration...");
MessageNotifier.updateNotification(context, null, true, -2);
return;
}

View File

@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.notifications;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import org.thoughtcrime.securesms.database.DatabaseFactory;
public class DeleteNotificationReceiver extends BroadcastReceiver {
public static String DELETE_NOTIFICATION_ACTION = "org.thoughtcrime.securesms.DELETE_NOTIFICATION";
public static String EXTRA_IDS = "message_ids";
public static String EXTRA_MMS = "is_mms";
@Override
public void onReceive(final Context context, Intent intent) {
if (DELETE_NOTIFICATION_ACTION.equals(intent.getAction())) {
MessageNotifier.clearReminder(context);
final long[] ids = intent.getLongArrayExtra(EXTRA_IDS);
final boolean[] mms = intent.getBooleanArrayExtra(EXTRA_MMS);
if (ids == null || mms == null || ids.length != mms.length) return;
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
for (int i=0;i<ids.length;i++) {
if (!mms[i]) DatabaseFactory.getSmsDatabase(context).markAsNotified(ids[i]);
else DatabaseFactory.getMmsDatabase(context).markAsNotified(ids[i]);
}
return null;
}
}.execute();
}
}
}

View File

@ -34,10 +34,7 @@ import android.service.notification.StatusBarNotification;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationManagerCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import org.thoughtcrime.redphone.ui.NotificationBarManager;
@ -48,14 +45,12 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
import org.thoughtcrime.securesms.database.PushDatabase;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.service.MessageRetrievalService;
@ -63,7 +58,6 @@ import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import java.util.HashSet;
import java.util.List;
@ -187,7 +181,7 @@ public class MessageNotifier {
return;
}
updateNotification(context, masterSecret, false, false, 0);
updateNotification(context, masterSecret, false, 0);
}
public static void updateNotification(@NonNull Context context,
@ -198,21 +192,12 @@ public class MessageNotifier {
Log.w(TAG, "Scheduling delayed notification...");
executor.execute(new DelayedNotification(context, masterSecret, threadId));
} else {
updateNotification(context, masterSecret, false, threadId, true);
updateNotification(context, masterSecret, threadId, true);
}
}
public static void updateNotification(@NonNull Context context,
@Nullable MasterSecret masterSecret,
boolean includePushDatabase,
long threadId)
{
updateNotification(context, masterSecret, includePushDatabase, threadId, true);
}
public static void updateNotification(@NonNull Context context,
@Nullable MasterSecret masterSecret,
boolean includePushDatabase,
long threadId,
boolean signal)
{
@ -236,14 +221,13 @@ public class MessageNotifier {
if (isVisible) {
sendInThreadNotification(context, threads.getRecipientsForThreadId(threadId));
} else {
updateNotification(context, masterSecret, signal, includePushDatabase, 0);
updateNotification(context, masterSecret, signal, 0);
}
}
private static void updateNotification(@NonNull Context context,
@Nullable MasterSecret masterSecret,
boolean signal,
boolean includePushDatabase,
int reminderCount)
{
Cursor telcoCursor = null;
@ -264,10 +248,6 @@ public class MessageNotifier {
NotificationState notificationState = constructNotificationState(context, masterSecret, telcoCursor);
if (includePushDatabase) {
appendPushNotificationState(context, notificationState, pushCursor);
}
if (signal && (System.currentTimeMillis() - lastAudibleNotification) < MIN_AUDIBLE_PERIOD_MILLIS) {
signal = false;
} else if (signal) {
@ -320,6 +300,7 @@ public class MessageNotifier {
notifications.get(0).getText(), notifications.get(0).getSlideDeck());
builder.setContentIntent(notifications.get(0).getPendingIntent(context));
builder.setGroup(NOTIFICATION_GROUP);
builder.setDeleteIntent(notificationState.getDeleteIntent(context));
long timestamp = notifications.get(0).getTimestamp();
if (timestamp != 0) builder.setWhen(timestamp);
@ -362,6 +343,7 @@ public class MessageNotifier {
builder.setMessageCount(notificationState.getMessageCount(), notificationState.getThreadCount());
builder.setMostRecentSender(notifications.get(0).getIndividualRecipient());
builder.setGroup(NOTIFICATION_GROUP);
builder.setDeleteIntent(notificationState.getDeleteIntent(context));
long timestamp = notifications.get(0).getTimestamp();
if (timestamp != 0) builder.setWhen(timestamp);
@ -432,33 +414,6 @@ public class MessageNotifier {
ringtone.play();
}
private static void appendPushNotificationState(@NonNull Context context,
@NonNull NotificationState notificationState,
@NonNull Cursor cursor)
{
PushDatabase.Reader reader = null;
SignalServiceEnvelope envelope;
try {
reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);
while ((envelope = reader.getNext()) != null) {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
Recipient recipient = recipients.getPrimaryRecipient();
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
SpannableString body = new SpannableString(context.getString(R.string.MessageNotifier_locked_message));
body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!recipients.isMuted()) {
notificationState.addNotification(new NotificationItem(recipient, recipients, null, threadId, body, 0, null));
}
}
} finally {
if (reader != null)
reader.close();
}
}
private static NotificationState constructNotificationState(@NonNull Context context,
@Nullable MasterSecret masterSecret,
@NonNull Cursor cursor)
@ -471,6 +426,8 @@ public class MessageNotifier {
else reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);
while ((record = reader.getNext()) != null) {
long id = record.getId();
boolean mms = record.isMms() || record.isMmsNotification();
Recipient recipient = record.getIndividualRecipient();
Recipients recipients = record.getRecipients();
long threadId = record.getThreadId();
@ -478,7 +435,7 @@ public class MessageNotifier {
Recipients threadRecipients = null;
SlideDeck slideDeck = null;
long timestamp = record.getTimestamp();
if (threadId != -1) {
threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
@ -497,7 +454,7 @@ public class MessageNotifier {
}
if (threadRecipients == null || !threadRecipients.isMuted()) {
notificationState.addNotification(new NotificationItem(recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
notificationState.addNotification(new NotificationItem(id, mms, recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
}
}
@ -531,7 +488,7 @@ public class MessageNotifier {
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeout, pendingIntent);
}
private static void clearReminder(Context context) {
public static void clearReminder(Context context) {
Intent alarmIntent = new Intent(ReminderReceiver.REMINDER_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
@ -549,7 +506,7 @@ public class MessageNotifier {
protected Void doInBackground(Void... params) {
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
int reminderCount = intent.getIntExtra("reminder_count", 0);
MessageNotifier.updateNotification(context, masterSecret, true, false, reminderCount + 1);
MessageNotifier.updateNotification(context, masterSecret, true, reminderCount + 1);
return null;
}
@ -557,16 +514,6 @@ public class MessageNotifier {
}
}
public static class DeleteReceiver extends BroadcastReceiver {
public static final String DELETE_REMINDER_ACTION = "org.thoughtcrime.securesms.MessageNotifier.DELETE_REMINDER_ACTION";
@Override
public void onReceive(Context context, Intent intent) {
clearReminder(context);
}
}
private static class DelayedNotification implements Runnable {
private static final long DELAY = TimeUnit.SECONDS.toMillis(5);
@ -599,7 +546,7 @@ public class MessageNotifier {
if (!canceled.get()) {
Log.w(TAG, "Not canceled, notifying...");
MessageNotifier.updateNotification(context, masterSecret, false, threadId, true);
MessageNotifier.updateNotification(context, masterSecret, threadId, true);
MessageNotifier.cancelDelayedNotifications();
} else {
Log.w(TAG, "Canceled, not notifying...");

View File

@ -30,7 +30,6 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
setCategory(NotificationCompat.CATEGORY_MESSAGE);
setPriority(NotificationCompat.PRIORITY_HIGH);
setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(MessageNotifier.DeleteReceiver.DELETE_REMINDER_ACTION), 0));
setGroupSummary(true);
}

View File

@ -15,6 +15,8 @@ import org.thoughtcrime.securesms.recipients.Recipients;
public class NotificationItem {
private final long id;
private final boolean mms;
private final @NonNull Recipients recipients;
private final @NonNull Recipient individualRecipient;
private final @Nullable Recipients threadRecipients;
@ -23,12 +25,15 @@ public class NotificationItem {
private final long timestamp;
private final @Nullable SlideDeck slideDeck;
public NotificationItem(@NonNull Recipient individualRecipient,
public NotificationItem(long id, boolean mms,
@NonNull Recipient individualRecipient,
@NonNull Recipients recipients,
@Nullable Recipients threadRecipients,
long threadId, @Nullable CharSequence text, long timestamp,
@Nullable SlideDeck slideDeck)
{
this.id = id;
this.mms = mms;
this.individualRecipient = individualRecipient;
this.recipients = recipients;
this.threadRecipients = threadRecipients;
@ -75,5 +80,11 @@ public class NotificationItem {
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
public long getId() {
return id;
}
public boolean isMms() {
return mms;
}
}

View File

@ -171,5 +171,24 @@ public class NotificationState {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public PendingIntent getDeleteIntent(Context context) {
int index = 0;
long[] ids = new long[notifications.size()];
boolean[] mms = new boolean[ids.length];
for (NotificationItem notificationItem : notifications) {
ids[index] = notificationItem.getId();
mms[index++] = notificationItem.isMms();
}
Intent intent = new Intent(context, DeleteNotificationReceiver.class);
intent.setAction(DeleteNotificationReceiver.DELETE_NOTIFICATION_ACTION);
intent.putExtra(DeleteNotificationReceiver.EXTRA_IDS, ids);
intent.putExtra(DeleteNotificationReceiver.EXTRA_MMS, mms);
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
}

View File

@ -53,7 +53,6 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
setColor(context.getResources().getColor(R.color.textsecure_primary));
setPriority(NotificationCompat.PRIORITY_HIGH);
setCategory(NotificationCompat.CATEGORY_MESSAGE);
setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(MessageNotifier.DeleteReceiver.DELETE_REMINDER_ACTION), 0));
}
public void setThread(@NonNull Recipients recipients) {

View File

@ -639,7 +639,7 @@ public class WebRtcCallService extends Service implements InjectableType, PeerCo
private void insertMissedCall(@NonNull Recipient recipient, boolean signal) {
Pair<Long, Long> messageAndThreadId = DatabaseFactory.getSmsDatabase(this).insertMissedCall(recipient.getNumber());
MessageNotifier.updateNotification(this, KeyCachingService.getMasterSecret(this),
false, messageAndThreadId.second, signal);
messageAndThreadId.second, signal);
}
private void handleAnswerCall(Intent intent) {

View File

@ -239,9 +239,9 @@ public class DirectoryHelper {
if (insertResult.isPresent()) {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if (hour >= 9 && hour < 23) {
MessageNotifier.updateNotification(context, masterSecret, false, insertResult.get().getThreadId(), true);
MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), true);
} else {
MessageNotifier.updateNotification(context, masterSecret, false, insertResult.get().getThreadId(), false);
MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId(), false);
}
}
}