Update composer library to 1.3.0 and apply changes

This commit is contained in:
aringenbach
2023-03-21 10:26:37 +01:00
parent 24df7ca032
commit 37a8aa5734
5 changed files with 66 additions and 46 deletions
+42 -33
View File
@@ -14,6 +14,7 @@
// limitations under the License.
//
import HTMLParser
import UIKit
import WysiwygComposer
@@ -38,6 +39,9 @@ extension RoomViewController {
newAttributedString.appendString(" ")
} else if roomMember.userId == self.mainSession.myUser.userId {
newAttributedString.appendString("/me ")
newAttributedString.addAttribute(.font,
value: inputToolbarView.textDefaultFont,
range: .init(location: 0, length: newAttributedString.length))
} else {
if #available(iOS 15.0, *) {
newAttributedString.append(PillsFormatter.mentionPill(withRoomMember: roomMember,
@@ -155,24 +159,7 @@ extension RoomViewController {
@objc func togglePlainTextMode() {
RiotSettings.shared.enableWysiwygTextFormatting.toggle()
guard let wysiwygInputToolbar else { return }
// Switching from plain -> RTE, replace Pills by valid markdown links for parsing.
if !wysiwygInputToolbar.textFormattingEnabled, #available(iOS 15.0, *),
let attributedText = wysiwygInputToolbar.attributedTextMessage {
wysiwygInputToolbar.attributedTextMessage = NSAttributedString(string: PillsFormatter.stringByReplacingPills(in: attributedText, mode: .markdown))
}
wysiwygInputToolbar.textFormattingEnabled.toggle()
// Switching from RTE -> plain, replace markdown links with Pills.
if !wysiwygInputToolbar.textFormattingEnabled, #available(iOS 15.0, *),
let attributedText = wysiwygInputToolbar.attributedTextMessage {
wysiwygInputToolbar.attributedTextMessage = PillsFormatter.insertPills(in: attributedText,
roomState: self.roomDataSource.roomState,
font: self.inputToolbarView.textDefaultFont)
}
wysiwygInputToolbar?.textFormattingEnabled.toggle()
}
@objc func didChangeMaximisedState(_ isMaximised: Bool) {
@@ -270,21 +257,6 @@ extension RoomViewController {
composerLinkActionBridgePresenter = presenter
presenter.present(from: self, animated: true)
}
@objc func didRequestAttachmentStringForLink(_ link: String, andDisplayName: String) -> NSAttributedString? {
guard #available(iOS 15.0, *),
let userId = PillsFormatter.userIdFromPermalink(link),
let roomState = self.roomDataSource.roomState,
let member = PillsFormatter.roomMember(withUserId: userId,
roomState: roomState,
andLatestRoomState: nil) else {
return nil
}
return PillsFormatter.mentionPill(withRoomMember: member,
isHighlighted: false,
font: inputToolbarView.textDefaultFont)
}
@objc func showWaitingOtherParticipantHeader() {
let controller = VectorHostingController(rootView: RoomWaitingForMembers())
@@ -395,6 +367,43 @@ extension RoomViewController: ComposerLinkActionBridgePresenterDelegate {
}
}
// MARK: - PermalinkReplacer
extension RoomViewController: PermalinkReplacer {
public func replacementForLink(_ url: String, text: String) -> NSAttributedString? {
guard #available(iOS 15.0, *),
let userId = PillsFormatter.userIdFromPermalink(url),
let roomState = roomDataSource.roomState,
let member = PillsFormatter.roomMember(withUserId: userId,
roomState: roomState,
andLatestRoomState: nil) else {
return nil
}
return PillsFormatter.mentionPill(withRoomMember: member,
isHighlighted: false,
font: inputToolbarView.textDefaultFont)
}
public func postProcessMarkdown(in attributedString: NSAttributedString) -> NSAttributedString {
guard #available(iOS 15.0, *),
let roomState = roomDataSource.roomState else {
return attributedString
}
return PillsFormatter.insertPills(in: attributedString,
roomState: roomState,
font: inputToolbarView.textDefaultFont)
}
public func restoreMarkdown(in attributedString: NSAttributedString) -> String {
if #available(iOS 15.0, *) {
return PillsFormatter.stringByReplacingPills(in: attributedString, mode: .markdown)
} else {
return attributedString.string
}
}
}
// MARK: - VoiceBroadcast
extension RoomViewController {
@objc func stopUncompletedVoiceBroadcastIfNeeded() {