Added setting to hide chat message content in notifications

This commit is contained in:
Sylvain Berfini 2020-10-02 15:34:58 +02:00
parent 31bbc9a4d5
commit 4ffc6881a8
5 changed files with 43 additions and 3 deletions

View file

@ -67,11 +67,20 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
val downloadedMediaPublicListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.makePublicMediaFilesDownloaded = newValue
downloadedMediaPublic.value = newValue
}
}
val downloadedMediaPublic = MutableLiveData<Boolean>()
val hideNotificationContentListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.hideChatMessageContentInNotification = newValue
hideNotificationContent.value = newValue
}
}
val hideNotificationContent = MutableLiveData<Boolean>()
val launcherShortcutsListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.chatRoomShortcuts = newValue
@ -104,6 +113,7 @@ class ChatSettingsViewModel : GenericSettingsViewModel() {
init {
downloadedMediaPublic.value = prefs.makePublicMediaFilesDownloaded
hideNotificationContent.value = prefs.hideChatMessageContentInNotification
initAutoDownloadList()
launcherShortcuts.value = prefs.chatRoomShortcuts
hideEmptyRooms.value = prefs.hideEmptyRooms

View file

@ -107,6 +107,12 @@ class CorePreferences constructor(private val context: Context) {
config.setBool("app", "make_downloaded_images_public_in_gallery", value)
}
var hideChatMessageContentInNotification: Boolean
get() = config.getBool("app", "hide_chat_message_content_in_notification", false)
set(value) {
config.setBool("app", "hide_chat_message_content_in_notification", value)
}
var hideEmptyRooms: Boolean
get() = config.getBool("app", "hide_empty_chat_rooms", true)
set(value) {

View file

@ -46,6 +46,7 @@ import org.linphone.compatibility.Compatibility
import org.linphone.contact.Contact
import org.linphone.core.*
import org.linphone.core.tools.Log
import org.linphone.utils.AppUtils
import org.linphone.utils.FileUtils
import org.linphone.utils.ImageUtils
import org.linphone.utils.LinphoneUtils
@ -636,13 +637,26 @@ class NotificationsManager(private val context: Context) {
contact.getPerson()
} else {
val builder = Person.Builder().setName(message.sender)
val userIcon = if (message.senderAvatar != null) IconCompat.createWithBitmap(message.senderAvatar) else IconCompat.createWithResource(context, R.drawable.avatar)
val userIcon =
if (message.senderAvatar != null) {
IconCompat.createWithBitmap(message.senderAvatar)
} else {
IconCompat.createWithResource(context, R.drawable.avatar)
}
if (userIcon != null) builder.setIcon(userIcon)
builder.build()
}
val msg = NotificationCompat.MessagingStyle.Message(message.message, message.time, person)
if (message.filePath != null) msg.setData(message.fileMime, message.filePath)
val msg = if (!corePreferences.hideChatMessageContentInNotification) {
NotificationCompat.MessagingStyle.Message(message.message, message.time, person)
} else {
NotificationCompat.MessagingStyle.Message(AppUtils.getString(R.string.chat_message_notification_hidden_content), message.time, person)
}
if (message.filePath != null && !corePreferences.hideChatMessageContentInNotification) {
msg.setData(message.fileMime, message.filePath)
}
style.addMessage(msg)
}

View file

@ -99,6 +99,13 @@
linphone:listener="@{viewModel.downloadedMediaPublicListener}"
linphone:checked="@={viewModel.downloadedMediaPublic}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/chat_settings_hide_notification_content_title}"
linphone:subtitle="@{@string/chat_settings_hide_notification_content_summary}"
linphone:listener="@{viewModel.hideNotificationContentListener}"
linphone:checked="@={viewModel.hideNotificationContent}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/chat_settings_launcher_shortcuts_title}"

View file

@ -198,6 +198,7 @@
<item quantity="one">@string/chat_room_delete_one_dialog</item>
<item quantity="other">@string/chat_room_delete_many_dialog</item>
</plurals>
<string name="chat_message_notification_hidden_content">&lt;Redacted&gt;</string>
<!-- Recordings -->
<string name="recordings_empty_list">No recordings</string>
@ -412,6 +413,8 @@
<string name="chat_settings_auto_download_max_size_summary">in bytes</string>
<string name="chat_settings_downloaded_media_public_title">Make downloaded media public</string>
<string name="chat_settings_downloaded_media_public_summary">Files in ephemeral messages won\'t be, doesn\'t work with auto download feature</string>
<string name="chat_settings_hide_notification_content_title">Hide message content in notifications</string>
<string name="chat_settings_hide_notification_content_summary">Only sender name will be displayed</string>
<string name="chat_settings_launcher_shortcuts_title">Create shortcuts to chat rooms in launcher</string>
<string name="chat_settings_launcher_shortcuts_summary">Will be replaced by contacts shortcuts if enabled</string>
<string name="chat_settings_hide_empty_rooms_title">Hide empty chat rooms</string>