Skip to content

[trello.com/c/lwOnjxPQ] clear draft before send message #845

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

Merged
merged 4 commits into from
May 8, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CommonKit
protocol ChatPreservationProtocol: AnyObject, Sendable {
var updateNotifier: ObservableSender<Void> { get }
var forceUpdateNotifier: ObservableSender<Void> { get }
func clearPreservedMessagesForSingleChat(address: String)
func getPreservedMessageFor(address: String) -> String?
func getReplyMessage(address: String) -> MessageModel?
func preserveChatState(message: String?, replyMessage: MessageModel?, files: [FileResult]?, forAddress address: String, isForsedUpdate: Bool)
Expand Down
1 change: 1 addition & 0 deletions Adamant/Modules/Chat/ViewModel/ChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ final class ChatViewModel: NSObject {

func sendMessage(text: String) {
guard let partnerAddress = chatroom?.partner?.address else { return }
chatPreservation.clearPreservedMessagesForSingleChat(address: partnerAddress)

guard chatroom?.partner?.isDummy != true else {
dialog.send(.dummy(partnerAddress))
Expand Down
13 changes: 9 additions & 4 deletions Adamant/ServiceProtocols/ChatPreservation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ final class ChatPreservation: ChatPreservationProtocol, @unchecked Sendable {
NotificationCenter.default
.notifications(named: .AdamantAccountService.userLoggedOut)
.sink { [weak self] _ in
self?.clearPreservedMessages()
self?.clearAllPreservedMessages()
}
.store(in: &notificationsSet)
}

// MARK: Notification actions

private func clearPreservedMessages() {
private func clearAllPreservedMessages() {
preservedMessages = [:]
preservedReplayMessage = [:]
preservedFiles = [:]

updateNotifier.send()
}

func clearPreservedMessagesForSingleChat(address: String) {
preservedMessages.removeValue(forKey: address)
preservedReplayMessage.removeValue(forKey: address)
preservedFiles.removeValue(forKey: address)
}


func preserveChatState(
message: String?,
Expand Down
Loading