Add notification for failed story messages.

This commit is contained in:
Clark
2023-03-17 12:23:02 -04:00
committed by Greyson Parrelli
parent 069b707d9d
commit 150c42c590
14 changed files with 135 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ public interface MessageNotifier {
void clearVisibleThread();
void setLastDesktopActivityTimestamp(long timestamp);
void notifyMessageDeliveryFailed(@NonNull Context context, @NonNull Recipient recipient, @NonNull ConversationId conversationId);
void notifyStoryDeliveryFailed(@NonNull Context context, @NonNull Recipient recipient, @NonNull ConversationId conversationId);
void notifyProofRequired(@NonNull Context context, @NonNull Recipient recipient, @NonNull ConversationId conversationId);
void cancelDelayedNotifications();
void updateNotification(@NonNull Context context);

View File

@@ -58,6 +58,11 @@ public class OptimizedMessageNotifier implements MessageNotifier {
getNotifier().notifyMessageDeliveryFailed(context, recipient, conversationId);
}
@Override
public void notifyStoryDeliveryFailed(@NonNull Context context, @NonNull Recipient recipient, @NonNull ConversationId threadId) {
getNotifier().notifyStoryDeliveryFailed(context, recipient, threadId);
}
@Override
public void notifyProofRequired(@NonNull Context context, @NonNull Recipient recipient, @NonNull ConversationId conversationId) {
getNotifier().notifyProofRequired(context, recipient, conversationId);

View File

@@ -85,6 +85,10 @@ class DefaultMessageNotifier(context: Application) : MessageNotifier {
NotificationFactory.notifyMessageDeliveryFailed(context, recipient, conversationId, visibleThread)
}
override fun notifyStoryDeliveryFailed(context: Context, recipient: Recipient, conversationId: ConversationId) {
NotificationFactory.notifyStoryDeliveryFailed(context, recipient, conversationId)
}
override fun notifyProofRequired(context: Context, recipient: Recipient, conversationId: ConversationId) {
NotificationFactory.notifyProofRequired(context, recipient, conversationId, visibleThread)
}

View File

@@ -19,7 +19,10 @@ import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.MainActivity
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.components.emoji.EmojiStrings
import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto
import org.thoughtcrime.securesms.conversation.ConversationIntents
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.database.model.InMemoryMessageRecord
import org.thoughtcrime.securesms.keyvalue.SignalStore
@@ -324,6 +327,46 @@ object NotificationFactory {
NotificationManagerCompat.from(context).safelyNotify(recipient, NotificationIds.getNotificationIdForMessageDeliveryFailed(thread), builder.build())
}
fun notifyStoryDeliveryFailed(context: Context, recipient: Recipient, thread: ConversationId) {
val intent = Intent(context, MyStoriesActivity::class.java).makeUniqueToPreventMerging()
val contentTitle = if (SignalStore.settings().messageNotificationsPrivacy.isDisplayContact) {
if (recipient.isGroup) {
context.getString(R.string.MessageNotifier_group_story_title, recipient.getDisplayName(context))
} else {
recipient.getDisplayName(context)
}
} else {
context.getString(R.string.SingleRecipientNotificationBuilder_signal)
}
val largeIcon = if (SignalStore.settings().messageNotificationsPrivacy.isDisplayContact) {
if (recipient.isMyStory) {
Recipient.self().getContactDrawable(context)
} else {
recipient.getContactDrawable(context)
}
} else {
GeneratedContactPhoto("Unknown", R.drawable.ic_profile_outline_40).asDrawable(context, AvatarColor.UNKNOWN)
}.toLargeBitmap(context)
val builder: NotificationBuilder = NotificationBuilder.create(context)
builder.apply {
setSmallIcon(R.drawable.ic_notification)
setLargeIcon(largeIcon)
setContentTitle(contentTitle)
setContentText(String.format("%s %s", EmojiStrings.FAILED_STORY, context.getString(R.string.MessageNotifier_story_delivery_failed)))
setTicker(context.getString(R.string.MessageNotifier_story_delivery_failed))
setContentIntent(NotificationPendingIntentHelper.getActivity(context, 0, intent, PendingIntentFlags.mutable()))
setAutoCancel(true)
setAlarms(recipient)
setChannelId(NotificationChannels.getInstance().FAILURES)
}
NotificationManagerCompat.from(context).safelyNotify(recipient, NotificationIds.getNotificationIdForMessageDeliveryFailed(thread), builder.build())
}
fun notifyProofRequired(context: Context, recipient: Recipient, thread: ConversationId, visibleThread: ConversationId?) {
if (thread == visibleThread) {
notifyInThread(context, recipient, 0)