Fix partial text messages not being saved for each room with RTE enabled

This commit is contained in:
aringenbach
2023-05-03 14:57:36 +02:00
parent bc68b26f6a
commit cc4a2cbca2
10 changed files with 75 additions and 15 deletions
+1 -1
View File
@@ -360,7 +360,7 @@ static const CGFloat kCellVisibilityMinimumHeight = 8.0;
{
// Retrieve the potential message partially typed during last room display.
// Note: We have to wait for viewDidAppear before updating growingTextView (viewWillAppear is too early)
inputToolbarView.attributedTextMessage = roomDataSource.partialAttributedTextMessage;
[inputToolbarView setPartialContent:roomDataSource.partialAttributedTextMessage];
}
if (!hasAppearedOnce)
+7 -2
View File
@@ -693,7 +693,7 @@ static CGSize kThreadListBarButtonItemImageSize;
{
// Retrieve the potential message partially typed during last room display.
// Note: We have to wait for viewDidAppear before updating growingTextView (viewWillAppear is too early)
self.inputToolbarView.attributedTextMessage = self.roomDataSource.partialAttributedTextMessage;
[self.inputToolbarView setPartialContent:self.roomDataSource.partialAttributedTextMessage];
}
[self setMaximisedToolbarIsHiddenIfNeeded: NO];
@@ -5293,6 +5293,11 @@ static CGSize kThreadListBarButtonItemImageSize;
}];
}
- (void)roomInputToolbarView:(MXKRoomInputToolbarView *)toolbarView shouldStorePartialContent:(NSAttributedString *)partialAttributedTextMessage
{
self.roomDataSource.partialAttributedTextMessage = partialAttributedTextMessage;
}
#pragma mark - MXKRoomMemberDetailsViewControllerDelegate
- (void)roomMemberDetailsViewController:(MXKRoomMemberDetailsViewController *)roomMemberDetailsViewController startChatWithMemberId:(NSString *)matrixId completion:(void (^)(void))completion
@@ -6135,7 +6140,7 @@ static CGSize kThreadListBarButtonItemImageSize;
if (self.saveProgressTextInput)
{
// Restore the potential message partially typed before jump to last unread messages.
self.inputToolbarView.attributedTextMessage = roomDataSource.partialAttributedTextMessage;
[self.inputToolbarView setPartialContent:roomDataSource.partialAttributedTextMessage];
}
};
@@ -96,11 +96,17 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
// Note: this is only interactive in plain text mode. If RTE is enabled,
// APIs from the composer view model should be used.
get {
guard !self.textFormattingEnabled else { return nil }
guard !self.textFormattingEnabled else {
MXLog.failure("[WysiwygInputToolbarView] Trying to get attributedTextMessage in RTE mode")
return nil
}
return self.wysiwygViewModel.textView.attributedText
}
set {
guard !self.textFormattingEnabled else { return }
guard !self.textFormattingEnabled else {
MXLog.failure("[WysiwygInputToolbarView] Trying to set attributedTextMessage in RTE mode")
return
}
self.wysiwygViewModel.textView.attributedText = newValue
}
}
@@ -174,6 +180,16 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
showKeyboard()
}
}
override func setPartialContent(_ attributedTextMessage: NSAttributedString) {
let content: String
if #available(iOS 15.0, *) {
content = PillsFormatter.stringByReplacingPills(in: attributedTextMessage, mode: .markdown)
} else {
content = attributedTextMessage.string
}
self.wysiwygViewModel.setMarkdownContent(content)
}
func showKeyboard() {
self.viewModel.showKeyboard()
@@ -191,7 +207,7 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
}
func mention(_ member: MXRoomMember) {
self.wysiwygViewModel.setMention(link: MXTools.permalinkToUser(withUserId: member.userId),
self.wysiwygViewModel.setMention(url: MXTools.permalinkToUser(withUserId: member.userId),
name: member.displayname,
mentionType: .user)
}
@@ -281,12 +297,31 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
},
wysiwygViewModel.$plainTextContent
.dropFirst()
.removeDuplicates()
.sink { [weak self] value in
guard let self else { return }
self.textMessage = value.string
.dropFirst()
.sink { [weak self] attributed in
// Note: filter out `plainTextMode` being off, as switching to RTE will trigger this
// publisher with empty content. This avoids saving the partial text message
// or trying to compute suggestion from this empty content.
guard let self, wysiwygViewModel.plainTextMode else { return }
self.textMessage = attributed.string
self.toolbarViewDelegate?.roomInputToolbarViewDidChangeTextMessage(self)
self.toolbarViewDelegate?.roomInputToolbarView?(self, shouldStorePartialContent: attributed)
},
wysiwygViewModel.$attributedContent
.removeDuplicates(by: {
$0.text == $1.text
})
.dropFirst()
.sink { [weak self] _ in
// Note: filter out `plainTextMode` being on, as switching to plain text mode will trigger this
// publisher with empty content. This avoids saving the partial text message
// or trying to compute suggestion from this empty content.
guard let self, !self.wysiwygViewModel.plainTextMode else { return }
let markdown = self.wysiwygViewModel.content.markdown
let attributed = NSAttributedString(string: markdown, attributes: [.font: self.defaultFont])
self.toolbarViewDelegate?.roomInputToolbarView?(self, shouldStorePartialContent: attributed)
}
]