diff --git a/Adamant.xcodeproj/project.pbxproj b/Adamant.xcodeproj/project.pbxproj index 19cfcd91d..65627120a 100644 --- a/Adamant.xcodeproj/project.pbxproj +++ b/Adamant.xcodeproj/project.pbxproj @@ -3070,6 +3070,7 @@ 938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */, 4184F16F2A33044E00D7B8B9 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, 3AC76E3B2AB09118008042C4 /* XCRemoteSwiftPackageReference "Elegant-Emoji-Picker" */, + 84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */, ); productRefGroup = E913C8EF1FFFA51D001A83F7 /* Products */; projectDirPath = ""; @@ -4422,6 +4423,14 @@ minimumVersion = 5.0.0; }; }; + 84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/Pointwelve/PopupKit"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 3.1.1; + }; + }; 938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/MessageKit/MessageKit.git"; diff --git a/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift b/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift index 202505026..30d45f73a 100644 --- a/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift +++ b/Adamant/Modules/Chat/ViewModel/ChatViewModel.swift @@ -938,6 +938,7 @@ final class ChatViewModel: NSObject { } filesPicked = oldFiles + case .failure(let error): dialog.send(.alert(error.localizedDescription)) } @@ -1060,6 +1061,28 @@ extension ChatViewModel { self?.dateHeaderHidden = true } } + + func inputContentUpdated() { + guard !inputText.isEmpty || filesPicked != nil else { + fee = "" + return + } + + var filesText: String = "" + + if let filesPicked { + filesText = filesPicked.map { + [$0.name, $0.extenstion].compactMap { $0 }.joined(separator: ".") + }.joined(separator: ";") + } + + let feeString = AdamantBalanceFormat.full.format( + AdamantMessage.text(inputText + filesText).fee, + withCurrencySymbol: AdmWalletService.currencySymbol + ) + + fee = "~\(feeString)" + } } extension ChatViewModel: NSFetchedResultsControllerDelegate { @@ -1095,7 +1118,7 @@ private extension ChatViewModel { func setupObservers() { $inputText .removeDuplicates() - .sink { [weak self] _ in self?.inputTextUpdated() } + .sink { [weak self] _ in self?.inputContentUpdated() } .store(in: &subscriptions) chatFileService.updateFileFields @@ -1131,6 +1154,13 @@ private extension ChatViewModel { } .store(in: &subscriptions) + $filesPicked + .sink { [weak self] _ in + guard let self else { return } + inputContentUpdated() + } + .store(in: &subscriptions) + NotificationCenter.default .notifications(named: .AdamantVisibleWalletsService.visibleWallets) .sink { @MainActor [weak self] _ in self?.updateAttachmentButtonAvailability() } @@ -1429,20 +1459,6 @@ private extension ChatViewModel { } } - func inputTextUpdated() { - guard !inputText.isEmpty else { - fee = "" - return - } - - let feeString = AdamantBalanceFormat.full.format( - AdamantMessage.text(inputText).fee, - withCurrencySymbol: AdmWalletService.currencySymbol - ) - - fee = "~\(feeString)" - } - func updatePartnerInformation() { guard let publicKey = chatroom?.partner?.publicKey else { return