Stop storing the openURL action to fix a retain cycle.

Uses the existing timeline action instead.
This commit is contained in:
Doug
2025-09-03 12:32:11 +01:00
committed by Doug
parent af5ebf8cae
commit 86f978a439
3 changed files with 5 additions and 16 deletions
@@ -77,7 +77,6 @@ enum TimelineViewAction {
case hasSwitchedTimeline
case hasScrolled(direction: ScrollDirection)
case setOpenURLAction(OpenURLAction)
case displayPredecessorRoom
}
@@ -117,9 +116,6 @@ struct TimelineViewState: BindableState {
// It's updated from the room info, so it's faster than using the timeline
var pinnedEventIDs: Set<String> = []
/// an openURL closure which opens URLs first using the App's environment rather than skipping out to external apps
var openURL: OpenURLAction?
/// A closure providing the associated audio player state for an item in the timeline.
var audioPlayerStateProvider: (@MainActor (_ itemId: TimelineItemIdentifier) -> AudioPlayerState?)?
@@ -202,8 +202,6 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
Task { state.timelineState.isSwitchingTimelines = false }
case let .hasScrolled(direction):
actionsSubject.send(.hasScrolled(direction: direction))
case .setOpenURLAction(let action):
state.openURL = action
case .displayPredecessorRoom:
guard let predecessorID = roomProxy.predecessorRoom?.roomId else {
fatalError("Predecessor room should exist if this action is triggered.")
@@ -656,15 +654,15 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
return nil
}
private func handleJoinCommand(message: String) {
private func handleJoinCommand(message: String) async {
guard let alias = String(message.dropFirst(SlashCommand.join.rawValue.count))
.components(separatedBy: .whitespacesAndNewlines)
.first,
let urlString = try? matrixToRoomAliasPermalink(roomAlias: alias),
let url = URL(string: urlString) else {
case let .success(resolvedAlias) = await userSession.clientProxy.resolveRoomAlias(alias) else {
return
}
state.openURL?(url)
actionsSubject.send(.displayRoom(roomID: resolvedAlias.roomId, via: resolvedAlias.servers))
}
private func sendCurrentMessage(_ message: String, html: String?, mode: ComposerMode, intentionalMentions: IntentionalMentions) async {
@@ -694,7 +692,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
case .default:
switch slashCommand(message: message) {
case .join:
handleJoinCommand(message: message)
await handleJoinCommand(message: message)
case .none:
await timelineController.sendMessage(message,
html: html,
@@ -70,16 +70,11 @@ struct TimelineView: View {
/// A table view wrapper that displays the timeline of a room.
struct TimelineViewRepresentable: UIViewControllerRepresentable {
@EnvironmentObject private var viewModelContext: TimelineViewModel.Context
@Environment(\.openURL) var openURL
func makeUIViewController(context: Context) -> TimelineTableViewController {
let tableViewController = TimelineTableViewController(coordinator: context.coordinator,
isScrolledToBottom: $viewModelContext.isScrolledToBottom,
scrollToBottomPublisher: viewModelContext.viewState.timelineState.scrollToBottomPublisher)
// Needs to be dispatched on main asynchronously otherwise we get a runtime warning
DispatchQueue.main.async {
viewModelContext.send(viewAction: .setOpenURLAction(openURL))
}
return tableViewController
}