Fix bug with notification privacy and bubbles.

This commit is contained in:
Cody Henthorne 2021-04-15 11:35:27 -04:00
parent 3dd0a60555
commit 1457738905
2 changed files with 35 additions and 13 deletions

View file

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

View file

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