Fix bug with notification privacy and bubbles.

fork-5.53.8
Cody Henthorne 2021-04-15 11:35:27 -04:00
rodzic 3dd0a60555
commit 1457738905
2 zmienionych plików z 35 dodań i 13 usunięć

Wyświetl plik

@ -54,7 +54,6 @@ sealed class NotificationBuilder(protected val context: Context) {
abstract fun setChannelId(channelId: String)
abstract fun setContentTitle(contentTitle: CharSequence)
abstract fun setLargeIcon(largeIcon: Bitmap?)
abstract fun setShortcutId(shortcutId: String)
abstract fun setContentInfo(contentInfo: String)
abstract fun setNumber(number: Int)
abstract fun setContentText(contentText: CharSequence?)
@ -62,7 +61,6 @@ sealed class NotificationBuilder(protected val context: Context) {
abstract fun setDeleteIntent(deleteIntent: PendingIntent?)
abstract fun setSortKey(sortKey: String)
abstract fun setOnlyAlertOnce(onlyAlertOnce: Boolean)
abstract fun addMessages(conversation: NotificationConversation)
abstract fun setGroupSummary(isGroupSummary: Boolean)
abstract fun setSubText(subText: String)
abstract fun addMarkAsReadActionActual(state: NotificationStateV2)
@ -70,14 +68,16 @@ sealed class NotificationBuilder(protected val context: Context) {
abstract fun setAlarms(recipient: Recipient?)
abstract fun setTicker(ticker: CharSequence)
abstract fun addTurnOffJoinedNotificationsAction(pendingIntent: PendingIntent)
abstract fun setBubbleMetadata(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState)
abstract fun setAutoCancel(autoCancel: Boolean)
abstract fun build(): Notification
protected abstract fun addPersonActual(recipient: Recipient)
protected abstract fun setShortcutIdActual(shortcutId: String)
protected abstract fun setWhen(timestamp: Long)
protected abstract fun addActions(replyMethod: ReplyMethod, conversation: NotificationConversation)
protected abstract fun addMessagesActual(conversation: NotificationConversation, includeShortcut: Boolean)
protected abstract fun addMessagesActual(state: NotificationStateV2)
protected abstract fun setBubbleMetadataActual(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState)
protected abstract fun setLights(@ColorInt color: Int, onTime: Int, offTime: Int)
fun addPerson(recipient: Recipient) {
@ -86,6 +86,12 @@ sealed class NotificationBuilder(protected val context: Context) {
}
}
fun setShortcutId(shortcutId: String) {
if (privacy.isDisplayContact) {
setShortcutIdActual(shortcutId)
}
}
fun setWhen(conversation: NotificationConversation) {
if (conversation.getWhen() != 0L) {
setWhen(conversation.getWhen())
@ -115,14 +121,24 @@ sealed class NotificationBuilder(protected val context: Context) {
}
}
fun addMessages(conversation: NotificationConversation) {
addMessagesActual(conversation, privacy.isDisplayContact)
}
fun addMessages(state: NotificationStateV2) {
if (!privacy.isDisplayContact && !privacy.isDisplayMessage) {
if (privacy.isDisplayNothing) {
return
}
addMessagesActual(state)
}
fun setBubbleMetadata(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState) {
if (privacy.isDisplayContact) {
setBubbleMetadataActual(conversation, bubbleState)
}
}
fun setSummaryContentText(recipient: Recipient) {
if (privacy.isDisplayContact) {
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s, recipient.getDisplayName(context)))
@ -217,7 +233,7 @@ sealed class NotificationBuilder(protected val context: Context) {
builder.addAction(turnOffTheseNotifications)
}
override fun addMessages(conversation: NotificationConversation) {
override fun addMessagesActual(conversation: NotificationConversation, includeShortcut: Boolean) {
val bigPictureUri: Uri? = conversation.getSlideBigPictureUri(context)
if (bigPictureUri != null) {
builder.setStyle(
@ -235,12 +251,15 @@ sealed class NotificationBuilder(protected val context: Context) {
conversation.notificationItems.forEach { notificationItem ->
val personBuilder: Person.Builder = Person.Builder()
.setKey(ConversationUtil.getShortcutId(notificationItem.individualRecipient))
.setBot(false)
.setName(notificationItem.getPersonName(context))
.setUri(notificationItem.getPersonUri(context))
.setIcon(notificationItem.getPersonIcon(context).toIconCompat())
if (includeShortcut) {
personBuilder.setKey(ConversationUtil.getShortcutId(notificationItem.individualRecipient))
}
val (dataUri: Uri?, mimeType: String?) = notificationItem.getThumbnailInfo(context)
messagingStyle.addMessage(NotificationCompat.MessagingStyle.Message(notificationItem.getPrimaryText(context), notificationItem.timestamp, personBuilder.build()).setData(mimeType, dataUri))
@ -289,7 +308,7 @@ sealed class NotificationBuilder(protected val context: Context) {
}
}
override fun setBubbleMetadata(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState) {
override fun setBubbleMetadataActual(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState) {
// Intentionally left blank
}
@ -329,7 +348,7 @@ sealed class NotificationBuilder(protected val context: Context) {
builder.setLargeIcon(largeIcon)
}
override fun setShortcutId(shortcutId: String) {
override fun setShortcutIdActual(shortcutId: String) {
builder.setShortcutId(shortcutId)
}
@ -455,7 +474,7 @@ sealed class NotificationBuilder(protected val context: Context) {
builder.addAction(turnOffTheseNotifications)
}
override fun addMessages(conversation: NotificationConversation) {
override fun addMessagesActual(conversation: NotificationConversation, includeShortcut: Boolean) {
val bigPictureUri: Uri? = conversation.getSlideBigPictureUri(context)
if (bigPictureUri != null) {
builder.style = Notification.BigPictureStyle()
@ -471,12 +490,15 @@ sealed class NotificationBuilder(protected val context: Context) {
conversation.notificationItems.forEach { notificationItem ->
val personBuilder: android.app.Person.Builder = android.app.Person.Builder()
.setKey(ConversationUtil.getShortcutId(notificationItem.individualRecipient))
.setBot(false)
.setName(notificationItem.getPersonName(context))
.setUri(notificationItem.getPersonUri(context))
.setIcon(notificationItem.getPersonIcon(context).toIcon())
if (includeShortcut) {
personBuilder.setKey(ConversationUtil.getShortcutId(notificationItem.individualRecipient))
}
val (dataUri: Uri?, mimeType: String?) = notificationItem.getThumbnailInfo(context)
messagingStyle.addMessage(Notification.MessagingStyle.Message(notificationItem.getPrimaryText(context), notificationItem.timestamp, personBuilder.build()).setData(mimeType, dataUri))
@ -485,7 +507,7 @@ sealed class NotificationBuilder(protected val context: Context) {
builder.style = messagingStyle
}
override fun setBubbleMetadata(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState) {
override fun setBubbleMetadataActual(conversation: NotificationConversation, bubbleState: BubbleUtil.BubbleState) {
if (Build.VERSION.SDK_INT < ConversationUtil.CONVERSATION_SUPPORT_VERSION) {
return
}
@ -550,7 +572,7 @@ sealed class NotificationBuilder(protected val context: Context) {
builder.setLargeIcon(largeIcon)
}
override fun setShortcutId(shortcutId: String) {
override fun setShortcutIdActual(shortcutId: String) {
builder.setShortcutId(shortcutId)
}

Wyświetl plik

@ -52,7 +52,7 @@ public final class BubbleUtil {
}
NotificationPrivacyPreference privacyPreference = TextSecurePreferences.getNotificationPrivacy(context);
if (!privacyPreference.isDisplayMessage()) {
if (!privacyPreference.isDisplayContact()) {
Log.i(TAG, "Bubbles are not available when notification privacy settings are enabled.");
return false;
}