mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 05:06:58 +02:00
Fix sending command with Pills through RTE
This commit is contained in:
@@ -5190,6 +5190,27 @@ static CGSize kThreadListBarButtonItemImageSize;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)roomInputToolbarView:(MXKRoomInputToolbarView *)toolbarView sendCommand:(NSString *)commandText
|
||||
{
|
||||
// Create before sending the message in case of a discussion (direct chat)
|
||||
MXWeakify(self);
|
||||
[self createDiscussionIfNeeded:^(BOOL readyToSend) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
|
||||
if (readyToSend) {
|
||||
if (![self sendAsIRCStyleCommandIfPossible:commandText])
|
||||
{
|
||||
// Display an error for unknown command
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
|
||||
message:[VectorL10n roomCommandErrorUnknownCommand]
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n ok] style:UIAlertActionStyleDefault handler:nil]];
|
||||
[self presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)roomInputToolbarViewShowSendMediaActions:(MXKRoomInputToolbarView *)toolbarView
|
||||
{
|
||||
NSMutableArray *actionItems = [NSMutableArray new];
|
||||
|
||||
@@ -107,7 +107,7 @@ extension RoomViewController {
|
||||
"event_id": eventModified.eventId
|
||||
])
|
||||
})
|
||||
} else if !self.send(asIRCStyleCommandIfPossible: rawTextMsg) {
|
||||
} else {
|
||||
roomDataSource.sendFormattedTextMessage(rawTextMsg, html: htmlMsg) { response in
|
||||
switch response {
|
||||
case .success:
|
||||
|
||||
@@ -338,7 +338,30 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
|
||||
}
|
||||
|
||||
private func sendWysiwygMessage(content: WysiwygComposerContent) {
|
||||
delegate?.roomInputToolbarView?(self, sendFormattedTextMessage: content.html, withRawText: content.markdown)
|
||||
if content.markdown.prefix(while: { $0 == "/" }).count == 1 {
|
||||
let commandText: String
|
||||
if content.markdown.hasPrefix(MXKSlashCommand.emote.cmd) {
|
||||
// `/me` command works with markdown content
|
||||
commandText = content.markdown
|
||||
} else if #available(iOS 15.0, *) {
|
||||
// Other commands should see pills replaced by matrix identifiers
|
||||
commandText = PillsFormatter.stringByReplacingPills(in: self.wysiwygViewModel.textView.attributedText, mode: .identifier)
|
||||
} else {
|
||||
// Without Pills support, just use the raw text for command
|
||||
commandText = self.wysiwygViewModel.textView.text
|
||||
}
|
||||
|
||||
// Fix potential command failures due to trailing characters
|
||||
// or NBSP that are not properly handled by the command interpreter
|
||||
let sanitizedCommand = commandText
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.replacingOccurrences(of: String.nbsp, with: " ")
|
||||
|
||||
delegate?.roomInputToolbarView?(self, sendCommand: sanitizedCommand)
|
||||
} else {
|
||||
delegate?.roomInputToolbarView?(self, sendFormattedTextMessage: content.html, withRawText: content.markdown)
|
||||
}
|
||||
|
||||
if isMaximised {
|
||||
minimise()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user