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);
}
Aggregations