diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 4be1db5503..15be456e0b 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -1047,10 +1047,13 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a val cItem = r.chatItem.chatItem chatModel.addChatItem(cInfo, cItem) val file = cItem.file - if (cItem.content.msgContent is MsgContent.MCImage && file != null && file.fileSize <= MAX_IMAGE_SIZE_AUTO_RCV && appPrefs.privacyAcceptImages.get()) { - withApi { receiveFile(file.fileId) } - } else if (cItem.content.msgContent is MsgContent.MCVoice && file != null && file.fileSize <= MAX_VOICE_SIZE_AUTO_RCV && file.fileSize > MAX_VOICE_SIZE_FOR_SENDING && appPrefs.privacyAcceptImages.get()) { - withApi { receiveFile(file.fileId) } // TODO check inlineFileMode != IFMSent + val mc = cItem.content.msgContent + if (file != null && file.fileSize <= MAX_IMAGE_SIZE_AUTO_RCV) { + val acceptImages = appPrefs.privacyAcceptImages.get() + if ((mc is MsgContent.MCImage && acceptImages) + || (mc is MsgContent.MCVoice && ((file.fileSize > MAX_VOICE_SIZE_FOR_SENDING && acceptImages) || cInfo is ChatInfo.Group))) { + withApi { receiveFile(file.fileId) } // TODO check inlineFileMode != IFMSent + } } if (cItem.showNotification && (!SimplexApp.context.isAppOnForeground || chatModel.chatId.value != cInfo.id)) { ntfManager.notifyMessageReceived(cInfo, cItem) diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index d889c0d150..4c19ac25ed 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -972,20 +972,15 @@ func processReceivedMsg(_ res: ChatResponse) async { let cInfo = aChatItem.chatInfo let cItem = aChatItem.chatItem m.addChatItem(cInfo, cItem) - if case .image = cItem.content.msgContent, - let file = cItem.file, - file.fileSize <= MAX_IMAGE_SIZE, - UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_ACCEPT_IMAGES) { - Task { - await receiveFile(fileId: file.fileId) - } - } else if case .voice = cItem.content.msgContent, // TODO check inlineFileMode != IFMSent - let file = cItem.file, - file.fileSize <= MAX_IMAGE_SIZE, - file.fileSize > MAX_VOICE_MESSAGE_SIZE_INLINE_SEND, - UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_ACCEPT_IMAGES) { - Task { - await receiveFile(fileId: file.fileId) + if let file = cItem.file, + let mc = cItem.content.msgContent, + file.fileSize <= MAX_IMAGE_SIZE { + let acceptImages = UserDefaults.standard.bool(forKey: DEFAULT_PRIVACY_ACCEPT_IMAGES) + if (mc.isImage && acceptImages) + || (mc.isVoice && ((file.fileSize > MAX_VOICE_MESSAGE_SIZE_INLINE_SEND && acceptImages) || cInfo.chatType == .group)) { + Task { + await receiveFile(fileId: file.fileId) // TODO check inlineFileMode != IFMSent + } } } if cItem.showNotification { diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 64a61e2a57..4db7223105 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -1806,6 +1806,13 @@ public enum MsgContent { } } + public var isImage: Bool { + switch self { + case .image: return true + default: return false + } + } + var cmdString: String { switch self { case let .text(text): return "text \(text)" diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index cc3d576041..de5ca2ed1c 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -344,7 +344,7 @@ processChatCommand = \case if isVoice mc && not (groupFeatureAllowed GFVoice gInfo) then pure $ chatCmdError $ "feature not allowed " <> T.unpack (groupFeatureToText GFVoice) else do - (fileInvitation_, ciFile_, ft_) <- unzipMaybe3 <$> setupSndFileTransfer gInfo (length ms) + (fileInvitation_, ciFile_, ft_) <- unzipMaybe3 <$> setupSndFileTransfer gInfo (length $ filter memberCurrent ms) (msgContainer, quotedItem_) <- prepareMsg fileInvitation_ membership msg@SndMessage {sharedMsgId} <- sendGroupMessage gInfo ms (XMsgNew msgContainer) mapM_ (sendGroupFileInline ms sharedMsgId) ft_ @@ -2243,7 +2243,7 @@ processAgentMessage (Just user@User {userId}) corrId agentConnId agentMessage = ChatItem {formattedText} <- newChatItem (CIRcvMsgContent content) ciFile_ when (enableNtfs chatSettings) $ do showMsgToast (c <> "> ") content formattedText - setActive $ ActiveC c + setActive $ ActiveC c where newChatItem ciContent ciFile_ = do ci <- saveRcvChatItem user (CDDirectRcv ct) msg msgMeta ciContent ciFile_