Disable Contact Join Notification via Action.

This commit is contained in:
Alex Hart
2020-08-06 15:47:34 -03:00
committed by Greyson Parrelli
parent 25c17082f2
commit 36d1e7c44a
9 changed files with 154 additions and 37 deletions

View File

@@ -364,18 +364,25 @@ public class DefaultMessageNotifier implements MessageNotifier {
long timestamp = notifications.get(0).getTimestamp();
if (timestamp != 0) builder.setWhen(timestamp);
boolean isSingleNotificationContactJoined = notifications.size() == 1 && notifications.get(0).isJoin();
if (!KeyCachingService.isLocked(context) && RecipientUtil.isMessageRequestAccepted(context, recipient.resolve())) {
ReplyMethod replyMethod = ReplyMethod.forRecipient(context, recipient);
builder.addActions(notificationState.getMarkAsReadIntent(context, notificationId),
notificationState.getQuickReplyIntent(context, notifications.get(0).getRecipient()),
notificationState.getRemoteReplyIntent(context, notifications.get(0).getRecipient(), replyMethod),
replyMethod);
replyMethod,
!isSingleNotificationContactJoined);
builder.addAndroidAutoAction(notificationState.getAndroidAutoReplyIntent(context, notifications.get(0).getRecipient()),
notificationState.getAndroidAutoHeardIntent(context, notificationId), notifications.get(0).getTimestamp());
}
if (!KeyCachingService.isLocked(context) && isSingleNotificationContactJoined) {
builder.addTurnOffTheseNotificationsAction(notificationState.getTurnOffTheseNotificationsIntent(context));
}
ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
while(iterator.hasPrevious()) {
@@ -538,7 +545,7 @@ public class DefaultMessageNotifier implements MessageNotifier {
}
if (threadRecipients == null || includeMessage) {
notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, receivedTimestamp, slideDeck, false));
notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, receivedTimestamp, slideDeck, false, record.isJoined()));
}
}
@@ -572,7 +579,7 @@ public class DefaultMessageNotifier implements MessageNotifier {
}
if (threadRecipients == null || !threadRecipients.isMuted()) {
notificationState.addNotification(new NotificationItem(id, mms, reactionSender, conversationRecipient, threadRecipients, threadId, body, reaction.getDateReceived(), receivedTimestamp, null, true));
notificationState.addNotification(new NotificationItem(id, mms, reactionSender, conversationRecipient, threadRecipients, threadId, body, reaction.getDateReceived(), receivedTimestamp, null, true, record.isJoined()));
}
}
}

View File

@@ -27,6 +27,7 @@ public class NotificationItem {
private final long messageReceivedTimestamp;
@Nullable private final SlideDeck slideDeck;
private final boolean jumpToMessage;
private final boolean isJoin;
public NotificationItem(long id,
boolean mms,
@@ -38,7 +39,8 @@ public class NotificationItem {
long notificationTimestamp,
long messageReceivedTimestamp,
@Nullable SlideDeck slideDeck,
boolean jumpToMessage)
boolean jumpToMessage,
boolean isJoin)
{
this.id = id;
this.mms = mms;
@@ -51,6 +53,7 @@ public class NotificationItem {
this.messageReceivedTimestamp = messageReceivedTimestamp;
this.slideDeck = slideDeck;
this.jumpToMessage = jumpToMessage;
this.isJoin = isJoin;
}
public @NonNull Recipient getRecipient() {
@@ -98,6 +101,10 @@ public class NotificationItem {
return mms;
}
public boolean isJoin() {
return isJoin;
}
private static int getStartingPosition(@NonNull Context context, long threadId, long receivedTimestampMs) {
return DatabaseFactory.getMmsSmsDatabase(context).getMessagePositionInConversation(threadId, receivedTimestampMs);
}

View File

@@ -8,6 +8,7 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.contacts.TurnOffContactJoinedNotificationsActivity;
import org.thoughtcrime.securesms.conversation.ConversationActivity;
import org.thoughtcrime.securesms.conversation.ConversationPopupActivity;
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
@@ -101,6 +102,15 @@ public class NotificationState {
return list;
}
public PendingIntent getTurnOffTheseNotificationsIntent(Context context) {
long threadId = threads.iterator().next();
return PendingIntent.getActivity(context,
0,
TurnOffContactJoinedNotificationsActivity.newIntent(context, threadId),
PendingIntent.FLAG_UPDATE_CURRENT);
}
public PendingIntent getMarkAsReadIntent(Context context, int notificationId) {
long[] threadArray = new long[threads.size()];
int index = 0;

View File

@@ -7,6 +7,8 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.text.SpannableStringBuilder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@@ -17,8 +19,6 @@ import androidx.core.app.Person;
import androidx.core.app.RemoteInput;
import androidx.core.graphics.drawable.IconCompat;
import android.text.SpannableStringBuilder;
import com.annimon.stream.Stream;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
@@ -156,43 +156,57 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConversationBuilder.build()));
}
public void addTurnOffTheseNotificationsAction(@NonNull PendingIntent turnOffTheseNotificationsIntent) {
Action turnOffTheseNotifications = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_turn_off_these_notifications),
turnOffTheseNotificationsIntent);
addAction(turnOffTheseNotifications);
}
public void addActions(@NonNull PendingIntent markReadIntent,
@NonNull PendingIntent quickReplyIntent,
@NonNull PendingIntent wearableReplyIntent,
@NonNull ReplyMethod replyMethod)
@NonNull ReplyMethod replyMethod,
boolean replyEnabled)
{
Action markAsReadAction = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_mark_read),
markReadIntent);
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(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(label).build())
.build();
}
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
actionName,
wearableReplyIntent)
.addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(label).build())
.build();
NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
Action markAsReadAction = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_mark_read),
markReadIntent);
addAction(markAsReadAction);
addAction(replyAction);
extender.addAction(markAsReadAction);
extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction)
.addAction(wearableReplyAction));
if (replyEnabled) {
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(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(label)
.build())
.build();
}
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
actionName,
wearableReplyIntent)
.addRemoteInput(new RemoteInput.Builder(DefaultMessageNotifier.EXTRA_REMOTE_REPLY)
.setLabel(label)
.build())
.build();
addAction(replyAction);
extend(extender.addAction(wearableReplyAction));
}
}
@StringRes