Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ import javax.inject.Singleton
import kotlin.math.max

/**
* Handles notifications in [NotificationPrivacy.ShowNameAndContent] mode.
* Handles notifications in [NotificationPrivacy.ShowNameAndContent]/[NotificationPrivacy.ShowNameOnly] mode.
*
* Shows one per-thread notification with the sender's name, avatar, and full message body,
* Shows one per-thread notification with the sender's name, avatar, and full message body if turned on,
* using [NotificationCompat.MessagingStyle]. Reactions are also included.
*/
@Singleton
class FullNotificationHandler @Inject constructor(
class FullAndNameOnlyNotificationHandler @Inject constructor(
@ApplicationContext context: Context,
threadDb: ThreadDatabase,
private val mmsSmsDatabase: MmsSmsDatabase,
Expand Down Expand Up @@ -269,17 +269,25 @@ class FullNotificationHandler @Inject constructor(
ArrayList<NotificationCompat.MessagingStyle.Message>(newMessages.size + newReactions.size)
val personCache = arrayMapOf<Address, Person>()

val nameOnlyMessageContent = if (prefs[NotificationPreferences.PRIVACY] == NotificationPrivacy.ShowNameOnly) {
context.resources.getQuantityText(R.plurals.messageNew, 1)
} else {
null
}

for (msg in newMessages) {
val text = nameOnlyMessageContent ?: MentionUtilities.parseAndSubstituteMentions(
recipientRepository = recipientRepository,
input = nameOnlyMessageContent ?: messageFormatter.formatMessageBodyForNotification(
context,
msg,
threadRecipient
),
context = context
).text

messages += NotificationCompat.MessagingStyle.Message(
MentionUtilities.parseAndSubstituteMentions(
recipientRepository = recipientRepository,
input = messageFormatter.formatMessageBodyForNotification(
context,
msg,
threadRecipient
),
context = context
).text,
text,
msg.dateSent,
msg.toPerson(personCache)
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import javax.inject.Singleton
* Reactive notification processor that replaces the poll-based DefaultMessageNotifier.
*
* Watches the user's notification privacy preference and delegates to the appropriate handler:
* - [NotificationPrivacy.ShowNameAndContent] → [FullNotificationHandler]
* - [NotificationPrivacy.ShowNameOnly] → [NameOnlyNotificationHandler]
* - [NotificationPrivacy.ShowNameAndContent] → [FullAndNameOnlyNotificationHandler]
* - [NotificationPrivacy.ShowNameOnly] → [FullAndNameOnlyNotificationHandler]
* - [NotificationPrivacy.ShowNoNameOrContent] → [NoNameOrContentNotificationHandler]
*
* Key behaviours:
Expand All @@ -27,8 +27,7 @@ import javax.inject.Singleton
@Singleton
class NotificationProcessor @Inject constructor(
private val prefs: PreferenceStorage,
private val fullHandler: FullNotificationHandler,
private val nameOnlyHandler: NameOnlyNotificationHandler,
private val fullHandler: FullAndNameOnlyNotificationHandler,
private val noNameOrContentHandler: NoNameOrContentNotificationHandler,
) : AuthAwareComponent {

Expand All @@ -37,8 +36,7 @@ class NotificationProcessor @Inject constructor(
.collectLatest { privacy ->
Log.d(TAG, "Start processing notification for $privacy")
when (privacy) {
NotificationPrivacy.ShowNameAndContent -> fullHandler.process()
NotificationPrivacy.ShowNameOnly -> nameOnlyHandler.process()
NotificationPrivacy.ShowNameOnly, NotificationPrivacy.ShowNameAndContent -> fullHandler.process()
NotificationPrivacy.ShowNoNameOrContent -> noNameOrContentHandler.process()
}
}
Expand Down