Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trello.com/c/b82n6AMp adding cost to media/files #638

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,7 @@
938F7D562955C1DA001915CA /* XCRemoteSwiftPackageReference "MessageKit" */,
4184F16F2A33044E00D7B8B9 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
3AC76E3B2AB09118008042C4 /* XCRemoteSwiftPackageReference "Elegant-Emoji-Picker" */,
84B761662D2E79A50022DCA9 /* XCRemoteSwiftPackageReference "PopupKit" */,
);
productRefGroup = E913C8EF1FFFA51D001A83F7 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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";
Expand Down
46 changes: 31 additions & 15 deletions Adamant/Modules/Chat/ViewModel/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ final class ChatViewModel: NSObject {
}

filesPicked = oldFiles

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not add extra spaces between simple lined of code

case .failure(let error):
dialog.send(.alert(error.localizedDescription))
}
Expand Down Expand Up @@ -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: ";")
}
Copy link
Member

@just-software-dev just-software-dev Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let filesText = filesPicked?.map {
   [$0.name, $0.extenstion].compactMap { $0 }.joined(separator: ".")
}?.joined(separator: ";") ?? .empty


let feeString = AdamantBalanceFormat.full.format(
AdamantMessage.text(inputText + filesText).fee,
withCurrencySymbol: AdmWalletService.currencySymbol
)

fee = "~\(feeString)"
}
}

extension ChatViewModel: NSFetchedResultsControllerDelegate {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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
Expand Down