@@ -200,6 +200,28 @@ struct TimelineReplyView: View {
200
200
if attributes [ . MatrixAllUsersMention] as? Bool == true {
201
201
attributedString. replaceCharacters ( in: range, with: PillUtilities . atRoom)
202
202
}
203
+
204
+ if let roomAlias = attributes [ . MatrixRoomAlias] as? String {
205
+ let roomName = context. viewState. roomNameForAliasResolver ? ( roomAlias)
206
+ attributedString. replaceCharacters ( in: range, with: PillUtilities . roomPillDisplayText ( roomName: roomName, rawRoomText: roomAlias) )
207
+ }
208
+
209
+ if let roomID = attributes [ . MatrixRoomID] as? String {
210
+ let roomName = context. viewState. roomNameForIDResolver ? ( roomID)
211
+ attributedString. replaceCharacters ( in: range, with: PillUtilities . roomPillDisplayText ( roomName: roomName, rawRoomText: roomID) )
212
+ }
213
+
214
+ if let eventOnRoomID = attributes [ . MatrixEventOnRoomID] as? EventOnRoomIDAttribute . Value {
215
+ let roomID = eventOnRoomID. roomID
216
+ let roomName = context. viewState. roomNameForIDResolver ? ( roomID)
217
+ attributedString. replaceCharacters ( in: range, with: PillUtilities . eventPillDisplayText ( roomName: roomName, rawRoomText: roomID) )
218
+ }
219
+
220
+ if let eventOnRoomAlias = attributes [ . MatrixEventOnRoomAlias] as? EventOnRoomAliasAttribute . Value {
221
+ let roomAlias = eventOnRoomAlias. alias
222
+ let roomName = context. viewState. roomNameForAliasResolver ? ( roomAlias)
223
+ attributedString. replaceCharacters ( in: range, with: PillUtilities . eventPillDisplayText ( roomName: roomName, rawRoomText: eventOnRoomAlias. alias) )
224
+ }
203
225
}
204
226
return attributedString. string
205
227
}
@@ -221,6 +243,30 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
221
243
return attributedString
222
244
} ( )
223
245
246
+ static let attributedStringWithRoomAliasMention = {
247
+ var attributedString = AttributedString ( " to be replaced " )
248
+ attributedString. roomAlias = " #room:matrix.org "
249
+ return attributedString
250
+ } ( )
251
+
252
+ static let attributedStringWithRoomIDMention = {
253
+ var attributedString = AttributedString ( " to be replaced " )
254
+ attributedString. roomID = " !room:matrix.org "
255
+ return attributedString
256
+ } ( )
257
+
258
+ static let attributedStringWithEventOnRoomIDMention = {
259
+ var attributedString = AttributedString ( " to be replaced " )
260
+ attributedString. eventOnRoomID = . init( roomID: " !room:matrix.org " , eventID: " $event " )
261
+ return attributedString
262
+ } ( )
263
+
264
+ static let attributedStringWithEventOnRoomAliasMention = {
265
+ var attributedString = AttributedString ( " to be replaced " )
266
+ attributedString. eventOnRoomAlias = . init( alias: " #room:matrix.org " , eventID: " $event " )
267
+ return attributedString
268
+ } ( )
269
+
224
270
static var previewItems : [ TimelineReplyView ] {
225
271
[
226
272
TimelineReplyView ( placement: . timeline, timelineItemReplyDetails: . notLoaded( eventID: " " ) ) ,
@@ -301,6 +347,22 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
301
347
timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
302
348
eventID: " 123 " ,
303
349
eventContent: . message( . notice( . init( body: " " , formattedBody: attributedStringWithAtRoomMention) ) ) ) ) ,
350
+ TimelineReplyView ( placement: . timeline,
351
+ timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
352
+ eventID: " 123 " ,
353
+ eventContent: . message( . notice( . init( body: " " , formattedBody: attributedStringWithRoomAliasMention) ) ) ) ) ,
354
+ TimelineReplyView ( placement: . timeline,
355
+ timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
356
+ eventID: " 123 " ,
357
+ eventContent: . message( . notice( . init( body: " " , formattedBody: attributedStringWithRoomIDMention) ) ) ) ) ,
358
+ TimelineReplyView ( placement: . timeline,
359
+ timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
360
+ eventID: " 123 " ,
361
+ eventContent: . message( . notice( . init( body: " " , formattedBody: attributedStringWithEventOnRoomIDMention) ) ) ) ) ,
362
+ TimelineReplyView ( placement: . timeline,
363
+ timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
364
+ eventID: " 123 " ,
365
+ eventContent: . message( . notice( . init( body: " " , formattedBody: attributedStringWithEventOnRoomAliasMention) ) ) ) ) ,
304
366
TimelineReplyView ( placement: . timeline,
305
367
timelineItemReplyDetails: . loaded( sender: . init( id: " " , displayName: " Bob " ) ,
306
368
eventID: " 123 " ,
0 commit comments