Merge pull request #7536 from vector-im/aringenbach/7535_fix_partial_text_messages

Fix partial text messages not being saved for each room with RTE enabled
This commit is contained in:
aringenbach
2023-05-05 09:29:28 +02:00
committed by GitHub
12 changed files with 80 additions and 20 deletions
@@ -213,6 +213,15 @@ typedef enum : NSUInteger
*/
- (void)roomInputToolbarView:(MXKRoomInputToolbarView*)toolbarView updateActivityIndicator:(BOOL)isAnimating;
/**
Tells the delegate that the partial content of the composer has changed
and should be stored to allow restoring it later if needed.
@param toolbarView the room input toolbar view
@param partialAttributedTextMessage the partial content to store
*/
- (void)roomInputToolbarView:(MXKRoomInputToolbarView*)toolbarView shouldStorePartialContent:(NSAttributedString*)partialAttributedTextMessage;
@end
/**
@@ -390,6 +399,11 @@ typedef enum : NSUInteger
*/
@property (nonatomic) NSAttributedString *attributedTextMessage;
/**
Sets the partial text message to apply to the current message composer.
*/
- (void)setPartialContent:(NSAttributedString *)attributedTextMessage;
/**
Default font for the message composer.
*/
@@ -1405,4 +1405,9 @@ NSString* MXKFileSizes_description(MXKFileSizes sizes)
return NO;
}
- (void)setPartialContent:(NSAttributedString *)attributedTextMessage
{
self.attributedTextMessage = attributedTextMessage;
}
@end
+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, 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)
}
]