forked from upstream-mirrors/quik
changes to make new message notifications silent if any of the recipients of the new message are not in user's contacts. new setting on settings->notifications page
This commit is contained in:
@@ -52,6 +52,7 @@ import dev.octoshrimpy.quik.receiver.MarkReadReceiver
|
||||
import dev.octoshrimpy.quik.receiver.MarkSeenReceiver
|
||||
import dev.octoshrimpy.quik.receiver.RemoteMessagingReceiver
|
||||
import dev.octoshrimpy.quik.receiver.SpeakThreadsReceiver
|
||||
import dev.octoshrimpy.quik.repository.ContactRepository
|
||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||
import dev.octoshrimpy.quik.util.GlideApp
|
||||
@@ -70,7 +71,8 @@ class NotificationManagerImpl @Inject constructor(
|
||||
private val prefs: Preferences,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val permissions: PermissionManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val contactRepo: ContactRepository,
|
||||
) : dev.octoshrimpy.quik.manager.NotificationManager {
|
||||
|
||||
companion object {
|
||||
@@ -145,12 +147,28 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(contentPI)
|
||||
.setDeleteIntent(seenPI)
|
||||
.setSound(ringtone)
|
||||
.setLights(Color.WHITE, 500, 2000)
|
||||
.setWhen(conversation.lastMessage?.date ?: System.currentTimeMillis())
|
||||
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
|
||||
// Tell the notification if it's a group message
|
||||
// if preference set to silence notifications if no recipients in contacts
|
||||
if (prefs.silentNotContact.get() && run {
|
||||
val msgRecipientNumbers = conversation.recipients.map { it.address }
|
||||
|
||||
// true if any message recipients are in device's contacts
|
||||
!contactRepo
|
||||
.getUnmanagedAllContacts()
|
||||
.flatMap { it.numbers }
|
||||
.map { it.address }
|
||||
.any { contactNumber ->
|
||||
msgRecipientNumbers.any { phoneNumberUtils.compare(contactNumber, it) }
|
||||
}
|
||||
})
|
||||
notification.setSilent(true)
|
||||
else
|
||||
notification.setSound(ringtone)
|
||||
|
||||
// Tell the notification if it's a group message
|
||||
val messagingStyle = NotificationCompat.MessagingStyle("Me")
|
||||
if (conversation.recipients.size >= 2) {
|
||||
messagingStyle.isGroupConversation = true
|
||||
|
||||
Reference in New Issue
Block a user