diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt b/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt index f5b54fd8eb..d95da55ccc 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt @@ -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() diff --git a/apps/ios/Shared/Model/NtfManager.swift b/apps/ios/Shared/Model/NtfManager.swift index 3f0bbca448..5d53cb31a9 100644 --- a/apps/ios/Shared/Model/NtfManager.swift +++ b/apps/ios/Shared/Model/NtfManager.swift @@ -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] = [:]) { diff --git a/apps/ios/SimpleX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apps/ios/SimpleX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 9d4b1de373..0000000000 --- a/apps/ios/SimpleX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -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 -} diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index c633f23d60..a685be571e 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -990,19 +990,19 @@ processAgentMessage (Just user@User {userId, profile}) agentConnId agentMessage newContentMessage :: Contact -> MsgContainer -> Message -> MsgMeta -> m () newContentMessage ct@Contact {localDisplayName = c} mc msg msgMeta = do let content = mcContent mc - ci <- saveRcvChatItem user (CDDirectRcv ct) msg msgMeta (CIRcvMsgContent content) + ci@ChatItem {formattedText} <- saveRcvChatItem user (CDDirectRcv ct) msg msgMeta (CIRcvMsgContent content) toView . CRNewChatItem $ AChatItem SCTDirect SMDRcv (DirectChat ct) ci checkIntegrity msgMeta $ toView . CRMsgIntegrityError - showToast (c <> "> ") $ msgContentText content + showMsgToast (c <> "> ") content formattedText setActive $ ActiveC c newGroupContentMessage :: GroupInfo -> GroupMember -> MsgContainer -> Message -> MsgMeta -> m () newGroupContentMessage gInfo m@GroupMember {localDisplayName = c} mc msg msgMeta = do let content = mcContent mc - ci <- saveRcvChatItem user (CDGroupRcv gInfo m) msg msgMeta (CIRcvMsgContent content) + ci@ChatItem {formattedText} <- saveRcvChatItem user (CDGroupRcv gInfo m) msg msgMeta (CIRcvMsgContent content) groupMsgToView gInfo ci msgMeta let g = groupName' gInfo - showToast ("#" <> g <> " " <> c <> "> ") $ msgContentText content + showMsgToast ("#" <> g <> " " <> c <> "> ") content formattedText setActive $ ActiveG g processFileInvitation :: Contact -> FileInvitation -> Message -> MsgMeta -> m () @@ -1471,6 +1471,13 @@ getCreateActiveUser st = do getWithPrompt :: String -> IO String getWithPrompt s = putStr (s <> ": ") >> hFlush stdout >> getLine +showMsgToast :: (MonadUnliftIO m, MonadReader ChatController m) => Text -> MsgContent -> Maybe MarkdownList -> m () +showMsgToast from mc md_ = showToast from $ maybe (msgContentText mc) (mconcat . map hideSecret) md_ + where + hideSecret :: FormattedText -> Text + hideSecret FormattedText {format = Just Secret} = "..." + hideSecret FormattedText {text} = text + showToast :: (MonadUnliftIO m, MonadReader ChatController m) => Text -> Text -> m () showToast title text = atomically . (`writeTBQueue` Notification {title, text}) =<< asks notifyQ