Don't renotify every single message on new message.
This commit is contained in:
parent
66d7241c03
commit
8fe196cd7a
2 changed files with 38 additions and 7 deletions
|
@ -193,8 +193,12 @@ sealed class NotificationItem(val threadRecipient: Recipient, protected val reco
|
|||
}
|
||||
|
||||
data class ThumbnailInfo(val uri: Uri? = null, val contentType: String? = null) {
|
||||
var needsShrinking = false
|
||||
private set
|
||||
|
||||
companion object {
|
||||
val NONE = ThumbnailInfo()
|
||||
val NEEDS_SHRINKING = ThumbnailInfo().apply { needsShrinking = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +212,7 @@ class MessageNotification(threadRecipient: Recipient, record: MessageRecord) : N
|
|||
override val isNewNotification: Boolean = notifiedTimestamp == 0L && !record.isEditMessage
|
||||
val hasSelfMention = record.hasSelfMention()
|
||||
|
||||
private var thumbnailInfo: ThumbnailInfo? = null
|
||||
private var thumbnailInfo: ThumbnailInfo = NotificationThumbnails.getWithoutModifying(this)
|
||||
|
||||
override fun getPrimaryTextActual(context: Context): CharSequence {
|
||||
return if (KeyCachingService.isLocked(context)) {
|
||||
|
@ -262,15 +266,13 @@ class MessageNotification(threadRecipient: Recipient, record: MessageRecord) : N
|
|||
}
|
||||
|
||||
override fun getThumbnailInfo(context: Context): ThumbnailInfo {
|
||||
if (thumbnailInfo == null) {
|
||||
thumbnailInfo = if (SignalStore.settings().messageNotificationsPrivacy.isDisplayMessage && !KeyCachingService.isLocked(context)) {
|
||||
NotificationThumbnails.get(context, this)
|
||||
} else {
|
||||
ThumbnailInfo()
|
||||
if (thumbnailInfo.needsShrinking) {
|
||||
if (SignalStore.settings().messageNotificationsPrivacy.isDisplayMessage && !KeyCachingService.isLocked(context)) {
|
||||
thumbnailInfo = NotificationThumbnails.get(context, this)
|
||||
}
|
||||
}
|
||||
|
||||
return thumbnailInfo!!
|
||||
return thumbnailInfo
|
||||
}
|
||||
|
||||
override fun canReply(context: Context): Boolean {
|
||||
|
|
|
@ -33,6 +33,35 @@ object NotificationThumbnails {
|
|||
|
||||
private val thumbnailCache = LinkedHashMap<MessageId, CachedThumbnail>(MAX_CACHE_SIZE)
|
||||
|
||||
fun getWithoutModifying(notificationItem: NotificationItem): NotificationItem.ThumbnailInfo {
|
||||
val thumbnailSlide: Slide? = notificationItem.slideDeck?.thumbnailSlide
|
||||
|
||||
if (thumbnailSlide == null || thumbnailSlide.uri == null) {
|
||||
return NotificationItem.ThumbnailInfo.NONE
|
||||
}
|
||||
|
||||
if (thumbnailSlide.fileSize > SUPPORTED_SIZE_THRESHOLD) {
|
||||
return NotificationItem.ThumbnailInfo.NONE
|
||||
}
|
||||
|
||||
if (thumbnailSlide.fileSize < TARGET_SIZE) {
|
||||
return NotificationItem.ThumbnailInfo(thumbnailSlide.publicUri, thumbnailSlide.contentType)
|
||||
}
|
||||
|
||||
val messageId = MessageId(notificationItem.id)
|
||||
val thumbnail: CachedThumbnail? = synchronized(thumbnailCache) { thumbnailCache[messageId] }
|
||||
|
||||
if (thumbnail != null) {
|
||||
return if (thumbnail != CachedThumbnail.PENDING) {
|
||||
NotificationItem.ThumbnailInfo(thumbnail.uri, thumbnail.contentType)
|
||||
} else {
|
||||
NotificationItem.ThumbnailInfo.NONE
|
||||
}
|
||||
}
|
||||
|
||||
return NotificationItem.ThumbnailInfo.NEEDS_SHRINKING
|
||||
}
|
||||
|
||||
fun get(context: Context, notificationItem: NotificationItem): NotificationItem.ThumbnailInfo {
|
||||
val thumbnailSlide: Slide? = notificationItem.slideDeck?.thumbnailSlide
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue