From b07d85cd068b011d8da6542278863a2a0dba19f2 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:55:13 +0200 Subject: [PATCH] FIX: saving draft did not save the pill markdown content (#3003) --- .../ComposerToolbarViewModel.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift index 72a7b265a..4ed1910fa 100644 --- a/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/ComposerToolbar/ComposerToolbarViewModel.swift @@ -310,7 +310,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } return } - plainText = context.plainComposerText.string + plainText = plainComposerContent.text htmlText = nil } @@ -349,7 +349,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } } - private func sendPlainComposerText() { + private var plainComposerContent: PlainComposerContent { let attributedString = NSMutableAttributedString(attributedString: context.plainComposerText) var shouldMakeAnotherPass = false @@ -396,9 +396,14 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool } } while shouldMakeAnotherPass - actionsSubject.send(.sendMessage(plain: attributedString.string, html: nil, + return .init(text: attributedString.string, mentionedUserIDs: userIDs, containsAtRoomMention: containsAtRoom) + } + + private func sendPlainComposerText() { + let plainComposerContent = plainComposerContent + actionsSubject.send(.sendMessage(plain: plainComposerContent.text, html: nil, mode: state.composerMode, - intentionalMentions: .init(userIDs: userIDs, atRoom: containsAtRoom))) + intentionalMentions: .init(userIDs: plainComposerContent.mentionedUserIDs, atRoom: plainComposerContent.containsAtRoomMention))) } private func processVoiceMessageAction(_ action: ComposerToolbarVoiceMessageAction) { @@ -658,3 +663,9 @@ private final class ComposerMentionReplacer: MentionReplacer { replacementForMentionClosure(url, text) } } + +private struct PlainComposerContent { + let text: String + let mentionedUserIDs: Set + let containsAtRoomMention: Bool +}