Skip to content

Commit 82dffce

Browse files
committed
Support for experimental MSC4286 to not render external payment details
Ref: matrix-org/matrix-spec-proposals#4286
1 parent f789bdc commit 82dffce

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ElementX/Sources/Other/HTMLParsing/DTHTMLElement+AttributedStringBuilder.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ public extension DTHTMLElement {
1818
// Remove any attachments to fix rendering.
1919
textAttachment = nil
2020

21+
// Handle special case for span with data-mx-external-payment-details
22+
// This could be based on Storefront.current.countryCode to show the link
23+
// content in unrestricted countries. e.g. currently USA
24+
if name == "span",
25+
let attributes = attributes as? [String: String],
26+
attributes["data-msc4286-external-payment-details"] != nil {
27+
parent.removeChildNode(self)
28+
return
29+
}
30+
2131
// If the element has plain text content show that,
2232
// otherwise prevent the tag from displaying.
2333
if let stringContent = attributedString()?.string,

UnitTests/Sources/AttributedStringBuilderTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,23 @@ class AttributedStringBuilderTests: XCTestCase {
10201020
XCTAssertEqual(link.confirmationParameters?.internalURL.absoluteString, "https://matrix.org")
10211021
XCTAssertEqual(link.confirmationParameters?.displayString, "👉️ #room:matrix.org")
10221022
}
1023-
1023+
1024+
func testMxExternalPaymentDetailsRemoved() {
1025+
let htmlString = "This is visible<span data-msc4286-external-payment-details>. But text is hidden <a href=\"https://matrix.org\">and this link too</a></span>"
1026+
1027+
guard let attributedString = attributedStringBuilder.fromHTML(htmlString) else {
1028+
XCTFail("Could not build the attributed string")
1029+
return
1030+
}
1031+
1032+
XCTAssertEqual(String(attributedString.characters), "This is visible")
1033+
1034+
for run in attributedString.runs where run.link != nil {
1035+
XCTFail("No link expected, but found one")
1036+
return
1037+
}
1038+
}
1039+
10241040
// MARK: - Private
10251041

10261042
private func checkLinkIn(attributedString: AttributedString?, expectedLink: String, expectedRuns: Int) {

0 commit comments

Comments
 (0)