mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-06 12:28:29 +00:00
Stop storing the openURL action to fix a retain cycle.
Uses the existing timeline action instead.
This commit is contained in:
@@ -77,7 +77,6 @@ enum TimelineViewAction {
|
|||||||
case hasSwitchedTimeline
|
case hasSwitchedTimeline
|
||||||
|
|
||||||
case hasScrolled(direction: ScrollDirection)
|
case hasScrolled(direction: ScrollDirection)
|
||||||
case setOpenURLAction(OpenURLAction)
|
|
||||||
|
|
||||||
case displayPredecessorRoom
|
case displayPredecessorRoom
|
||||||
}
|
}
|
||||||
@@ -117,9 +116,6 @@ struct TimelineViewState: BindableState {
|
|||||||
// It's updated from the room info, so it's faster than using the timeline
|
// It's updated from the room info, so it's faster than using the timeline
|
||||||
var pinnedEventIDs: Set<String> = []
|
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.
|
/// A closure providing the associated audio player state for an item in the timeline.
|
||||||
var audioPlayerStateProvider: (@MainActor (_ itemId: TimelineItemIdentifier) -> AudioPlayerState?)?
|
var audioPlayerStateProvider: (@MainActor (_ itemId: TimelineItemIdentifier) -> AudioPlayerState?)?
|
||||||
|
|
||||||
|
|||||||
@@ -202,8 +202,6 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
|||||||
Task { state.timelineState.isSwitchingTimelines = false }
|
Task { state.timelineState.isSwitchingTimelines = false }
|
||||||
case let .hasScrolled(direction):
|
case let .hasScrolled(direction):
|
||||||
actionsSubject.send(.hasScrolled(direction: direction))
|
actionsSubject.send(.hasScrolled(direction: direction))
|
||||||
case .setOpenURLAction(let action):
|
|
||||||
state.openURL = action
|
|
||||||
case .displayPredecessorRoom:
|
case .displayPredecessorRoom:
|
||||||
guard let predecessorID = roomProxy.predecessorRoom?.roomId else {
|
guard let predecessorID = roomProxy.predecessorRoom?.roomId else {
|
||||||
fatalError("Predecessor room should exist if this action is triggered.")
|
fatalError("Predecessor room should exist if this action is triggered.")
|
||||||
@@ -656,15 +654,15 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleJoinCommand(message: String) {
|
private func handleJoinCommand(message: String) async {
|
||||||
guard let alias = String(message.dropFirst(SlashCommand.join.rawValue.count))
|
guard let alias = String(message.dropFirst(SlashCommand.join.rawValue.count))
|
||||||
.components(separatedBy: .whitespacesAndNewlines)
|
.components(separatedBy: .whitespacesAndNewlines)
|
||||||
.first,
|
.first,
|
||||||
let urlString = try? matrixToRoomAliasPermalink(roomAlias: alias),
|
case let .success(resolvedAlias) = await userSession.clientProxy.resolveRoomAlias(alias) else {
|
||||||
let url = URL(string: urlString) else {
|
|
||||||
return
|
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 {
|
private func sendCurrentMessage(_ message: String, html: String?, mode: ComposerMode, intentionalMentions: IntentionalMentions) async {
|
||||||
@@ -694,7 +692,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
|
|||||||
case .default:
|
case .default:
|
||||||
switch slashCommand(message: message) {
|
switch slashCommand(message: message) {
|
||||||
case .join:
|
case .join:
|
||||||
handleJoinCommand(message: message)
|
await handleJoinCommand(message: message)
|
||||||
case .none:
|
case .none:
|
||||||
await timelineController.sendMessage(message,
|
await timelineController.sendMessage(message,
|
||||||
html: html,
|
html: html,
|
||||||
|
|||||||
@@ -70,16 +70,11 @@ struct TimelineView: View {
|
|||||||
/// A table view wrapper that displays the timeline of a room.
|
/// A table view wrapper that displays the timeline of a room.
|
||||||
struct TimelineViewRepresentable: UIViewControllerRepresentable {
|
struct TimelineViewRepresentable: UIViewControllerRepresentable {
|
||||||
@EnvironmentObject private var viewModelContext: TimelineViewModel.Context
|
@EnvironmentObject private var viewModelContext: TimelineViewModel.Context
|
||||||
@Environment(\.openURL) var openURL
|
|
||||||
|
|
||||||
func makeUIViewController(context: Context) -> TimelineTableViewController {
|
func makeUIViewController(context: Context) -> TimelineTableViewController {
|
||||||
let tableViewController = TimelineTableViewController(coordinator: context.coordinator,
|
let tableViewController = TimelineTableViewController(coordinator: context.coordinator,
|
||||||
isScrolledToBottom: $viewModelContext.isScrolledToBottom,
|
isScrolledToBottom: $viewModelContext.isScrolledToBottom,
|
||||||
scrollToBottomPublisher: viewModelContext.viewState.timelineState.scrollToBottomPublisher)
|
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
|
return tableViewController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user