Fix up wearable reply stuff a little.
1) Don't include MasterSecret in PendingIntents. 2) Correctly reply to non-push group threads, rather than just an individual in that group. // FREEBIE
This commit is contained in:
parent
f0b2cc5590
commit
13eed3baa7
7 changed files with 102 additions and 93 deletions
|
@ -981,15 +981,6 @@
|
||||||
<!-- transport_selection_list_item -->
|
<!-- transport_selection_list_item -->
|
||||||
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
|
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Wear Reply -->
|
|
||||||
<string name="wear_reply_label">Reply</string>
|
|
||||||
<string-array name="wear_replies">
|
|
||||||
<item>Yes</item>
|
|
||||||
<item>No</item>
|
|
||||||
<item>OK</item>
|
|
||||||
<item>Thanks</item>
|
|
||||||
</string-array>
|
|
||||||
<!-- EOF -->
|
<!-- EOF -->
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -5,25 +5,29 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
|
||||||
public class MarkReadReceiver extends BroadcastReceiver {
|
public class MarkReadReceiver extends MasterSecretBroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String TAG = MarkReadReceiver.class.getSimpleName();
|
||||||
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
|
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
|
||||||
|
public static final String THREAD_IDS_EXTRA = "thread_ids";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, Intent intent) {
|
protected void onReceive(final Context context, Intent intent,
|
||||||
if (!intent.getAction().equals(CLEAR_ACTION))
|
@Nullable final MasterSecret masterSecret)
|
||||||
|
{
|
||||||
|
if (!CLEAR_ACTION.equals(intent.getAction()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final long[] threadIds = intent.getLongArrayExtra("thread_ids");
|
final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);
|
||||||
final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
|
|
||||||
|
|
||||||
if (threadIds != null && masterSecret != null) {
|
if (threadIds != null) {
|
||||||
Log.w("MarkReadReceiver", "threadIds length: " + threadIds.length);
|
Log.w("TAG", "threadIds length: " + threadIds.length);
|
||||||
|
|
||||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||||
.cancel(MessageNotifier.NOTIFICATION_ID);
|
.cancel(MessageNotifier.NOTIFICATION_ID);
|
||||||
|
@ -32,7 +36,7 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
for (long threadId : threadIds) {
|
for (long threadId : threadIds) {
|
||||||
Log.w("MarkReadReceiver", "Marking as read: " + threadId);
|
Log.w(TAG, "Marking as read: " + threadId);
|
||||||
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.thoughtcrime.securesms.notifications;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||||
|
|
||||||
|
public abstract class MasterSecretBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onReceive(Context context, Intent intent) {
|
||||||
|
onReceive(context, intent, KeyCachingService.getMasterSecret(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void onReceive(Context context, Intent intent, @Nullable MasterSecret masterSecret);
|
||||||
|
}
|
|
@ -98,8 +98,8 @@ public class MessageNotifier {
|
||||||
sendInThreadNotification(context, recipients);
|
sendInThreadNotification(context, recipients);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(context, ConversationActivity.class);
|
Intent intent = new Intent(context, ConversationActivity.class);
|
||||||
intent.putExtra("recipients", recipients.getIds());
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
||||||
intent.putExtra("thread_id", threadId);
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||||
|
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
|
@ -195,8 +195,8 @@ public class MessageNotifier {
|
||||||
|
|
||||||
List<NotificationItem> notifications = notificationState.getNotifications();
|
List<NotificationItem> notifications = notificationState.getNotifications();
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
Recipient recipient = notifications.get(0).getIndividualRecipient();
|
|
||||||
Recipients recipients = notifications.get(0).getRecipients();
|
Recipients recipients = notifications.get(0).getRecipients();
|
||||||
|
Recipient recipient = notifications.get(0).getIndividualRecipient();
|
||||||
int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||||
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR.toConversationColor(context) :
|
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR.toConversationColor(context) :
|
||||||
recipients.getColor().toConversationColor(context));
|
recipients.getColor().toConversationColor(context));
|
||||||
|
@ -224,16 +224,16 @@ public class MessageNotifier {
|
||||||
if (masterSecret != null) {
|
if (masterSecret != null) {
|
||||||
Action markAsReadAction = new Action(R.drawable.check,
|
Action markAsReadAction = new Action(R.drawable.check,
|
||||||
context.getString(R.string.MessageNotifier_mark_read),
|
context.getString(R.string.MessageNotifier_mark_read),
|
||||||
notificationState.getMarkAsReadIntent(context, masterSecret));
|
notificationState.getMarkAsReadIntent(context));
|
||||||
|
|
||||||
Action replyAction = new Action(R.drawable.ic_reply_white_36dp,
|
Action replyAction = new Action(R.drawable.ic_reply_white_36dp,
|
||||||
context.getString(R.string.MessageNotifier_reply),
|
context.getString(R.string.MessageNotifier_reply),
|
||||||
notifications.get(0).getReplyIntent(context));
|
notificationState.getQuickReplyIntent(context, recipients));
|
||||||
|
|
||||||
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
|
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
|
||||||
context.getString(R.string.wear_reply_label),
|
context.getString(R.string.MessageNotifier_reply),
|
||||||
notificationState.getReplyIntent(context, masterSecret, recipient.getRecipientId()))
|
notificationState.getWearableReplyIntent(context, recipients))
|
||||||
.addRemoteInput(new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(context.getString(R.string.wear_reply_label)).build())
|
.addRemoteInput(new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(context.getString(R.string.MessageNotifier_reply)).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
builder.addAction(markAsReadAction);
|
builder.addAction(markAsReadAction);
|
||||||
|
@ -296,7 +296,7 @@ public class MessageNotifier {
|
||||||
if (masterSecret != null) {
|
if (masterSecret != null) {
|
||||||
Action markAllAsReadAction = new Action(R.drawable.check,
|
Action markAllAsReadAction = new Action(R.drawable.check,
|
||||||
context.getString(R.string.MessageNotifier_mark_all_as_read),
|
context.getString(R.string.MessageNotifier_mark_all_as_read),
|
||||||
notificationState.getMarkAsReadIntent(context, masterSecret));
|
notificationState.getMarkAsReadIntent(context));
|
||||||
builder.addAction(markAllAsReadAction);
|
builder.addAction(markAllAsReadAction);
|
||||||
builder.extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
|
builder.extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class NotificationItem {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Recipients getRecipients() {
|
public Recipients getRecipients() {
|
||||||
return threadRecipients;
|
return threadRecipients == null ? recipients : threadRecipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Recipient getIndividualRecipient() {
|
public Recipient getIndividualRecipient() {
|
||||||
|
@ -92,16 +92,5 @@ public class NotificationItem {
|
||||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PendingIntent getReplyIntent(Context context) {
|
|
||||||
Intent intent = new Intent(context, ConversationPopupActivity.class);
|
|
||||||
Recipients notifyRecipients = threadRecipients != null ? threadRecipients : recipients;
|
|
||||||
if (notifyRecipients != null) intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, notifyRecipients.getIds());
|
|
||||||
|
|
||||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
||||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
|
||||||
|
|
||||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.ConversationActivity;
|
||||||
|
import org.thoughtcrime.securesms.ConversationPopupActivity;
|
||||||
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
|
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
|
|
||||||
|
@ -70,20 +70,7 @@ public class NotificationState {
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PendingIntent getMarkAsReadIntent(Context context, MasterSecret masterSecret) {
|
public PendingIntent getMarkAsReadIntent(Context context) {
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putParcelable("master_secret", masterSecret);
|
|
||||||
return craftIntent(context, MarkReadReceiver.CLEAR_ACTION, extras);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PendingIntent getReplyIntent(Context context, MasterSecret masterSecret, long recipientId) {
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putParcelable("master_secret", masterSecret);
|
|
||||||
extras.putLong("recipient_id", recipientId);
|
|
||||||
return craftIntent(context, WearReplyReceiver.REPLY_ACTION, extras);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PendingIntent craftIntent(Context context, String intentAction, Bundle extras) {
|
|
||||||
long[] threadArray = new long[threads.size()];
|
long[] threadArray = new long[threads.size()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
|
@ -92,9 +79,8 @@ public class NotificationState {
|
||||||
threadArray[index++] = thread;
|
threadArray[index++] = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(intentAction);
|
Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION);
|
||||||
intent.putExtra("thread_ids", threadArray);
|
intent.putExtra(MarkReadReceiver.THREAD_IDS_EXTRA, threadArray);
|
||||||
intent.putExtras(extras);
|
|
||||||
intent.setPackage(context.getPackageName());
|
intent.setPackage(context.getPackageName());
|
||||||
|
|
||||||
// XXX : This is an Android bug. If we don't pull off the extra
|
// XXX : This is an Android bug. If we don't pull off the extra
|
||||||
|
@ -105,4 +91,27 @@ public class NotificationState {
|
||||||
|
|
||||||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PendingIntent getWearableReplyIntent(Context context, Recipients recipients) {
|
||||||
|
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
|
||||||
|
|
||||||
|
Intent intent = new Intent(WearReplyReceiver.REPLY_ACTION);
|
||||||
|
intent.putExtra(WearReplyReceiver.RECIPIENT_IDS_EXTRA, recipients.getIds());
|
||||||
|
intent.setPackage(context.getPackageName());
|
||||||
|
|
||||||
|
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PendingIntent getQuickReplyIntent(Context context, Recipients recipients) {
|
||||||
|
if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, ConversationPopupActivity.class);
|
||||||
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
||||||
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, (long)threads.toArray()[0]);
|
||||||
|
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||||
|
|
||||||
|
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,70 +17,67 @@
|
||||||
|
|
||||||
package org.thoughtcrime.securesms.notifications;
|
package org.thoughtcrime.securesms.notifications;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.RemoteInput;
|
import android.support.v4.app.RemoteInput;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientProvider;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||||
|
|
||||||
|
import ws.com.google.android.mms.pdu.PduBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the response text from the Wearable Device and sends an message as a reply
|
* Get the response text from the Wearable Device and sends an message as a reply
|
||||||
*
|
|
||||||
* @author Alix Ducros (Ported to TextSecure-Codebase by Christoph Haefner)
|
|
||||||
*/
|
*/
|
||||||
public class WearReplyReceiver extends BroadcastReceiver {
|
public class WearReplyReceiver extends MasterSecretBroadcastReceiver {
|
||||||
|
|
||||||
public static final String TAG = WearReplyReceiver.class.getSimpleName();
|
public static final String TAG = WearReplyReceiver.class.getSimpleName();
|
||||||
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
|
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
|
||||||
|
public static final String RECIPIENT_IDS_EXTRA = "recipient_ids";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(final Context context, Intent intent) {
|
protected void onReceive(final Context context, Intent intent,
|
||||||
if (!intent.getAction().equals(REPLY_ACTION))
|
final @Nullable MasterSecret masterSecret)
|
||||||
return;
|
{
|
||||||
|
if (!REPLY_ACTION.equals(intent.getAction())) return;
|
||||||
|
|
||||||
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
||||||
if (remoteInput == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
final long[] threadIds = intent.getLongArrayExtra("thread_ids");
|
if (remoteInput == null) return;
|
||||||
final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
|
|
||||||
final long recipientId = intent.getLongExtra("recipient_id", -1);
|
final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
|
||||||
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_VOICE_REPLY);
|
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_VOICE_REPLY);
|
||||||
|
final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
|
||||||
|
|
||||||
final Recipients recipients = RecipientFactory.getRecipientsForIds(context, new long[]{recipientId}, false);
|
if (masterSecret != null && responseText != null) {
|
||||||
|
|
||||||
if (threadIds != null && masterSecret != null) {
|
|
||||||
|
|
||||||
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
|
|
||||||
.cancel(MessageNotifier.NOTIFICATION_ID);
|
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
for (long threadId : threadIds) {
|
long threadId;
|
||||||
Log.w(TAG, "Marking as read: " + threadId);
|
|
||||||
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
if (recipients.isGroupRecipient()) {
|
||||||
|
OutgoingMediaMessage reply = new OutgoingMediaMessage(context, recipients, new PduBody(), responseText.toString(), 0);
|
||||||
|
threadId = MessageSender.send(context, masterSecret, reply, -1, false);
|
||||||
|
} else {
|
||||||
|
OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString());
|
||||||
|
threadId = MessageSender.send(context, masterSecret, reply, -1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString());
|
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
|
||||||
MessageSender.send(context, masterSecret, reply, threadIds[0], false);
|
|
||||||
|
|
||||||
MessageNotifier.updateNotification(context, masterSecret);
|
MessageNotifier.updateNotification(context, masterSecret);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue