Search in sources :

Example 1 with BubbleUtil

use of org.thoughtcrime.securesms.util.BubbleUtil in project Signal-Android by WhisperSystems.

the class NotificationCancellationHelper method isCancellable.

/**
 * Checks whether the conversation for the given notification is allowed to be represented as a bubble.
 *
 * see {@link BubbleUtil#canBubble} for more information.
 */
@RequiresApi(ConversationUtil.CONVERSATION_SUPPORT_VERSION)
private static boolean isCancellable(@NonNull Context context, int notificationId) {
    NotificationManager manager = ServiceUtil.getNotificationManager(context);
    StatusBarNotification[] notifications = manager.getActiveNotifications();
    Notification notification = Stream.of(notifications).filter(n -> n.getId() == notificationId).findFirst().map(StatusBarNotification::getNotification).orElse(null);
    if (notification == null || notification.getShortcutId() == null || notification.getBubbleMetadata() == null) {
        Log.d(TAG, "isCancellable: bubbles not available or notification does not exist");
        return true;
    }
    RecipientId recipientId = ConversationUtil.getRecipientId(notification.getShortcutId());
    if (recipientId == null) {
        Log.d(TAG, "isCancellable: Unable to get recipient from shortcut id");
        return true;
    }
    Long threadId = SignalDatabase.threads().getThreadIdFor(recipientId);
    long focusedThreadId = ApplicationDependencies.getMessageNotifier().getVisibleThread();
    if (Objects.equals(threadId, focusedThreadId)) {
        Log.d(TAG, "isCancellable: user entered full screen thread.");
        return true;
    }
    return !BubbleUtil.canBubble(context, recipientId, threadId);
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) BubbleUtil(org.thoughtcrime.securesms.util.BubbleUtil) NotificationManager(android.app.NotificationManager) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) MessageNotifierV2(org.thoughtcrime.securesms.notifications.v2.MessageNotifierV2) Set(java.util.Set) ConversationUtil(org.thoughtcrime.securesms.util.ConversationUtil) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Notification(android.app.Notification) Build(android.os.Build) Collections(java.util.Collections) StatusBarNotification(android.service.notification.StatusBarNotification) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) NotificationManager(android.app.NotificationManager) StatusBarNotification(android.service.notification.StatusBarNotification) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 Build (android.os.Build)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 NonNull (androidx.annotation.NonNull)1 RequiresApi (androidx.annotation.RequiresApi)1 Stream (com.annimon.stream.Stream)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Log (org.signal.core.util.logging.Log)1 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)1 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)1 MessageNotifierV2 (org.thoughtcrime.securesms.notifications.v2.MessageNotifierV2)1 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)1 BubbleUtil (org.thoughtcrime.securesms.util.BubbleUtil)1 ConversationUtil (org.thoughtcrime.securesms.util.ConversationUtil)1 ServiceUtil (org.thoughtcrime.securesms.util.ServiceUtil)1