Skip to content

Commit 0bc969a

Browse files
committed
Support for experimental MSC4286 to not render external payment details
Ref: matrix-org/matrix-spec-proposals#4286
1 parent 478d4f7 commit 0bc969a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Riot/Modules/MatrixKit/Categories/DTHTMLElement+MatrixKit.swift

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

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

RiotTests/MatrixKitTests/MXKEventFormatterTests.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,24 @@ - (void)testRenderHTMLStringWithIFrame
239239
XCTAssertFalse(hasAttachment, @"iFrame attachments should be removed as they're not included in the allowedHTMLTags array.");
240240
}
241241

242+
- (void)testMxExternalPaymentDetailsRemoved
243+
{
244+
// Given an HTML string containing a <span> with data-mx-external-payment-details.
245+
NSString *html = @"This is visible<span data-msc4286-external-payment-details>. But text is hidden <a href=\"https://matrix.org\">and this link too</a></span>";
246+
247+
// When rendering this string as an attributed string.
248+
NSAttributedString *attributedString = [eventFormatter renderHTMLString:html
249+
forEvent:anEvent
250+
withRoomState:nil
251+
andLatestRoomState:nil];
252+
253+
// Then the attributed string should have the <span> stripped and not include any attachments.
254+
XCTAssertEqualObjects(attributedString.string, @"This is visible", @"The <span data-msc4286-external-payment-details> tag content should be removed.");
255+
256+
BOOL hasAttachment = [attributedString containsAttachmentsInRange:NSMakeRange(0, attributedString.length)];
257+
XCTAssertFalse(hasAttachment, @"span attachments should be removed as they're not included in the allowedHTMLTags array.");
258+
}
259+
242260
- (void)testRenderHTMLStringWithMXReply
243261
{
244262
// Given an HTML string representing a matrix reply.

0 commit comments

Comments
 (0)