2013-05-30 12:39:56 -07:00
|
|
|
package org.thoughtcrime.securesms.notifications;
|
|
|
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.AsyncTask;
|
2014-01-18 18:25:51 -08:00
|
|
|
import android.util.Log;
|
2013-05-30 12:39:56 -07:00
|
|
|
|
2013-08-17 18:37:18 -07:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-05-30 12:39:56 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
|
|
|
|
public class MarkReadReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(final Context context, Intent intent) {
|
|
|
|
if (!intent.getAction().equals(CLEAR_ACTION))
|
|
|
|
return;
|
|
|
|
|
2014-01-18 18:25:51 -08:00
|
|
|
final long[] threadIds = intent.getLongArrayExtra("thread_ids");
|
2013-05-30 12:39:56 -07:00
|
|
|
final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
|
|
|
|
|
2014-01-18 18:25:51 -08:00
|
|
|
if (threadIds != null && masterSecret != null) {
|
|
|
|
Log.w("MarkReadReceiver", "threadIds length: " + threadIds.length);
|
2013-05-30 12:39:56 -07:00
|
|
|
|
|
|
|
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
|
|
|
.cancel(MessageNotifier.NOTIFICATION_ID);
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2014-01-18 18:25:51 -08:00
|
|
|
for (long threadId : threadIds) {
|
|
|
|
Log.w("MarkReadReceiver", "Marking as read: " + threadId);
|
|
|
|
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
|
|
|
}
|
2013-05-30 12:39:56 -07:00
|
|
|
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|