hide secrets in notifications, closes #416 (#424)

* terminal: hide secrets in notifications #416

* ios: hide secrets in notifications

* android: hide secrets in notifications
This commit is contained in:
Evgeny Poberezkin
2022-03-13 20:13:47 +00:00
committed by GitHub
parent 806f417e99
commit 1f539fc8be
4 changed files with 42 additions and 22 deletions
@@ -36,7 +36,7 @@ class NtfManager(val context: Context) {
val notification = NotificationCompat.Builder(context, MessageChannel)
.setContentTitle(cInfo.displayName)
.setContentText(cItem.content.text)
.setContentText(hideSecrets(cItem))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setGroup(MessageGroup)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
@@ -62,6 +62,19 @@ class NtfManager(val context: Context) {
}
}
private fun hideSecrets(cItem: ChatItem): String {
val md = cItem.formattedText
return if (md == null) {
cItem.content.text
} else {
var res = ""
for (ft in md) {
res += if (ft.format is Format.Secret) "..." else ft.text
}
res
}
}
private fun getMsgPendingIntent(cInfo: ChatInfo) : PendingIntent{
Log.d(TAG, "getMsgPendingIntent ${cInfo.id}")
val uniqueInt = (System.currentTimeMillis() and 0xfffffff).toInt()
+17 -1
View File
@@ -162,11 +162,27 @@ class NtfManager: NSObject, UNUserNotificationCenterDelegate, ObservableObject {
addNotification(
categoryIdentifier: ntfCategoryMessageReceived,
title: "\(cInfo.chatViewName):",
body: cItem.content.text,
body: hideSecrets(cItem),
targetContentIdentifier: cInfo.id
// userInfo: ["chatId": cInfo.id, "chatItemId": cItem.id]
)
}
func hideSecrets(_ cItem: ChatItem) -> String {
if let md = cItem.formattedText {
var res = ""
for ft in md {
if case .secret = ft.format {
res = res + "..."
} else {
res = res + ft.text
}
}
return res
} else {
return cItem.content.text
}
}
private func addNotification(categoryIdentifier: String, title: String, subtitle: String? = nil, body: String? = nil,
targetContentIdentifier: String? = nil, userInfo: [AnyHashable : Any] = [:]) {
@@ -1,16 +0,0 @@
{
"object": {
"pins": [
{
"package": "CodeScanner",
"repositoryURL": "https://github.com/twostraws/CodeScanner",
"state": {
"branch": null,
"revision": "c27a66149b7483fe42e2ec6aad61d5c3fffe522d",
"version": "2.1.1"
}
}
]
},
"version": 1
}