Skip to content

Commit 791ce67

Browse files
committed
reply view will now render as plain pills
instead of rendering nothing
1 parent dbb59a4 commit 791ce67

File tree

7 files changed

+100
-21
lines changed

7 files changed

+100
-21
lines changed

ElementX/Sources/Screens/Timeline/TimelineModels.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ struct TimelineViewState: BindableState {
117117
/// A closure that updates the associated pill context
118118
var pillContextUpdater: (@MainActor (PillContext) -> Void)?
119119

120+
/// A closure that returns the associated room name give its id
121+
var roomNameForIDResolver: (@MainActor (String) -> String?)?
122+
123+
/// A closure that returns the associated room name give its alias
124+
var roomNameForAliasResolver: (@MainActor (String) -> String?)?
125+
120126
var emojiProvider: EmojiProviderProtocol
121127
}
122128

ElementX/Sources/Screens/Timeline/TimelineViewModel.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
121121
self?.pillContextUpdater(pillContext)
122122
}
123123

124+
state.roomNameForIDResolver = { [weak self] roomID in
125+
self?.clientProxy.roomSummaryForIdentifier(roomID)?.name
126+
}
127+
128+
state.roomNameForAliasResolver = { [weak self] alias in
129+
self?.clientProxy.roomSummaryForAlias(alias)?.name
130+
}
131+
124132
state.timelineState.paginationState = timelineController.paginationState
125133
buildTimelineViews(timelineItems: timelineController.timelineItems)
126134

@@ -935,19 +943,22 @@ extension TimelineViewModel {
935943
static let mock = mock(timelineKind: .live)
936944

937945
static func mock(timelineKind: TimelineKind = .live, timelineController: MockTimelineController? = nil) -> TimelineViewModel {
938-
TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
939-
focussedEventID: nil,
940-
timelineController: timelineController ?? MockTimelineController(timelineKind: timelineKind),
941-
mediaProvider: MediaProviderMock(configuration: .init()),
942-
mediaPlayerProvider: MediaPlayerProviderMock(),
943-
voiceMessageMediaManager: VoiceMessageMediaManagerMock(),
944-
userIndicatorController: ServiceLocator.shared.userIndicatorController,
945-
appMediator: AppMediatorMock.default,
946-
appSettings: ServiceLocator.shared.settings,
947-
analyticsService: ServiceLocator.shared.analytics,
948-
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
949-
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
950-
clientProxy: ClientProxyMock(.init()))
946+
let clientProxyMock = ClientProxyMock(.init())
947+
clientProxyMock.roomSummaryForAliasReturnValue = .mock(id: "!room:matrix.org", name: "Room")
948+
clientProxyMock.roomSummaryForIdentifierReturnValue = .mock(id: "!room:matrix.org", name: "Room", canonicalAlias: "#room:matrix.org")
949+
return TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
950+
focussedEventID: nil,
951+
timelineController: timelineController ?? MockTimelineController(timelineKind: timelineKind),
952+
mediaProvider: MediaProviderMock(configuration: .init()),
953+
mediaPlayerProvider: MediaPlayerProviderMock(),
954+
voiceMessageMediaManager: VoiceMessageMediaManagerMock(),
955+
userIndicatorController: ServiceLocator.shared.userIndicatorController,
956+
appMediator: AppMediatorMock.default,
957+
appSettings: ServiceLocator.shared.settings,
958+
analyticsService: ServiceLocator.shared.analytics,
959+
emojiProvider: EmojiProvider(appSettings: ServiceLocator.shared.settings),
960+
timelineControllerFactory: TimelineControllerFactoryMock(.init()),
961+
clientProxy: clientProxyMock)
951962
}
952963
}
953964

ElementX/Sources/Screens/Timeline/View/Replies/TimelineReplyView.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ struct TimelineReplyView: View {
200200
if attributes[.MatrixAllUsersMention] as? Bool == true {
201201
attributedString.replaceCharacters(in: range, with: PillUtilities.atRoom)
202202
}
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+
}
203225
}
204226
return attributedString.string
205227
}
@@ -221,6 +243,30 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
221243
return attributedString
222244
}()
223245

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+
224270
static var previewItems: [TimelineReplyView] {
225271
[
226272
TimelineReplyView(placement: .timeline, timelineItemReplyDetails: .notLoaded(eventID: "")),
@@ -301,6 +347,22 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
301347
timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Bob"),
302348
eventID: "123",
303349
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))))),
304366
TimelineReplyView(placement: .timeline,
305367
timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Bob"),
306368
eventID: "123",
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)