Enable quick reply

This commit is contained in:
Mikunj Varsani 2020-03-12 10:42:08 +11:00
parent d694cfa68a
commit 996f233d25
2 changed files with 61 additions and 45 deletions

View File

@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.MultiDeviceUtilities;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.IncomingMessageObserver;
@ -58,6 +59,8 @@ import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.webrtc.CallNotificationBuilder;
import org.whispersystems.signalservice.internal.util.Util;
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
import java.util.HashSet;
import java.util.List;
@ -70,6 +73,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import me.leolin.shortcutbadger.ShortcutBadger;
import network.loki.messenger.R;
import nl.komponents.kovenant.Promise;
/**
@ -316,15 +320,35 @@ public class MessageNotifier {
long timestamp = notifications.get(0).getTimestamp();
if (timestamp != 0) builder.setWhen(timestamp);
long threadId = notifications.get(0).getThreadId();
ReplyMethod replyMethod = ReplyMethod.forRecipient(context, recipient);
// We can only reply if we are friends with the user or we're messaging a group
boolean isGroup = recipient.isGroupRecipient() && !recipient.getAddress().isRSSFeed();
boolean isFriends = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId) == LokiThreadFriendRequestStatus.FRIENDS;
// If we're not friends then we need to check if we're friends with any of the linked devices
if (!isGroup && !isFriends) {
Promise<Boolean, Exception> promise = PromiseUtil.timeout(MultiDeviceUtilities.isFriendsWithAnyLinkedDevice(context, recipient), 5000);
isFriends = PromiseUtil.get(promise, false);
}
boolean canReply = isGroup || isFriends;
PendingIntent quickReplyIntent = canReply ? notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()) : null;
PendingIntent remoteReplyIntent = canReply ? notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod) : null;
builder.addActions(notificationState.getMarkAsReadIntent(context, notificationId),
/*notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()),*/
notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod),
quickReplyIntent,
remoteReplyIntent,
replyMethod);
if (canReply) {
builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()),
notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp());
}
ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());

View File

@ -28,7 +28,6 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
import org.thoughtcrime.securesms.mms.GlideApp;
@ -39,7 +38,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
import java.util.LinkedList;
import java.util.List;
@ -156,31 +154,33 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
}
public void addActions(@NonNull PendingIntent markReadIntent,
@NonNull PendingIntent wearableReplyIntent,
@Nullable PendingIntent quickReplyIntent,
@Nullable PendingIntent wearableReplyIntent,
@NonNull ReplyMethod replyMethod)
{
Action markAsReadAction = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_mark_read),
markReadIntent);
addAction(markAsReadAction);
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(markAsReadAction);
if (quickReplyIntent != null) {
String actionName = context.getString(R.string.MessageNotifier_reply);
String label = context.getString(replyMethodLongDescription(replyMethod));
/*
Action replyAction = new Action(R.drawable.ic_reply_white_36dp,
actionName,
quickReplyIntent);
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
/*
replyAction = new Action.Builder(R.drawable.ic_reply_white_36dp,
actionName,
wearableReplyIntent)
.addRemoteInput(new RemoteInput.Builder(MessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(label).build())
.build();
*/
}
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
@ -190,25 +190,17 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
.setLabel(label).build())
.build();
addAction(markAsReadAction);
// addAction(replyAction);
extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction)
.addAction(wearableReplyAction));
addAction(replyAction);
wearableExtender.addAction(wearableReplyAction);
}
extend(wearableExtender);
}
@StringRes
private static int replyMethodLongDescription(@NonNull ReplyMethod replyMethod) {
switch (replyMethod) {
case GroupMessage:
return R.string.MessageNotifier_reply;
case SecureMessage:
return R.string.MessageNotifier_signal_message;
case UnsecuredSmsMessage:
return R.string.MessageNotifier_unsecured_sms;
default:
return R.string.MessageNotifier_reply;
}
}
public void addMessageBody(@NonNull Recipient threadRecipient,