mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
RoomScreenViewModel is now TimelineViewModel (#3157)
Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
@@ -18,7 +18,7 @@ import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
final class MessageTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
var roomContext: RoomScreenViewModel.Context?
|
||||
var timelineContext: TimelineViewModel.Context?
|
||||
var updateClosure: (() -> Void)?
|
||||
private var pillViews = NSHashTable<UIView>.weakObjects()
|
||||
|
||||
@@ -54,7 +54,7 @@ final class MessageTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
|
||||
struct MessageText: UIViewRepresentable {
|
||||
@Environment(\.openURL) private var openURLAction
|
||||
@Environment(\.roomContext) private var viewModel
|
||||
@Environment(\.timelineContext) private var viewModel
|
||||
@State private var computedSizes = [Double: CGSize]()
|
||||
|
||||
@State var attributedString: AttributedString {
|
||||
@@ -66,7 +66,7 @@ struct MessageText: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> MessageTextView {
|
||||
// Need to use TextKit 1 for mentions
|
||||
let textView = MessageTextView(usingTextLayoutManager: false)
|
||||
textView.roomContext = viewModel
|
||||
textView.timelineContext = viewModel
|
||||
textView.updateClosure = { [weak textView] in
|
||||
guard let textView else { return }
|
||||
do {
|
||||
@@ -197,7 +197,7 @@ struct MessageText_Previews: PreviewProvider, TestablePreview {
|
||||
static var attachmentPreview: some View {
|
||||
MessageText(attributedString: attributedStringWithAttachment)
|
||||
.border(Color.purple)
|
||||
.environmentObject(RoomScreenViewModel.mock.context)
|
||||
.environmentObject(TimelineViewModel.mock.context)
|
||||
}
|
||||
|
||||
static var previews: some View {
|
||||
|
||||
@@ -21,7 +21,7 @@ import UIKit
|
||||
import WysiwygComposer
|
||||
|
||||
protocol PillAttachmentViewProviderDelegate: AnyObject {
|
||||
var roomContext: RoomScreenViewModel.Context? { get }
|
||||
var timelineContext: TimelineViewModel.Context? { get }
|
||||
|
||||
func registerPillView(_ pillView: UIView)
|
||||
func invalidateTextAttachmentsDisplay()
|
||||
@@ -56,9 +56,9 @@ final class PillAttachmentViewProvider: NSTextAttachmentViewProvider, NSSecureCo
|
||||
// The mock viewModel simulates the loading logic for testing purposes
|
||||
context = PillContext.mock(type: .loadUser(isOwn: false))
|
||||
imageProvider = MockMediaProvider()
|
||||
} else if let roomContext = delegate?.roomContext {
|
||||
context = PillContext(roomContext: roomContext, data: pillData)
|
||||
imageProvider = roomContext.imageProvider
|
||||
} else if let timelineContext = delegate?.timelineContext {
|
||||
context = PillContext(timelineContext: timelineContext, data: pillData)
|
||||
imageProvider = timelineContext.imageProvider
|
||||
} else {
|
||||
MXLog.failure("[PillAttachmentViewProvider]: missing room context")
|
||||
return
|
||||
@@ -93,21 +93,21 @@ final class PillAttachmentViewProvider: NSTextAttachmentViewProvider, NSSecureCo
|
||||
}
|
||||
|
||||
final class ComposerMentionDisplayHelper: MentionDisplayHelper {
|
||||
weak var roomContext: RoomScreenViewModel.Context?
|
||||
weak var timelineContext: TimelineViewModel.Context?
|
||||
|
||||
init(roomContext: RoomScreenViewModel.Context) {
|
||||
self.roomContext = roomContext
|
||||
init(timelineContext: TimelineViewModel.Context) {
|
||||
self.timelineContext = timelineContext
|
||||
}
|
||||
|
||||
@MainActor
|
||||
static var mock: Self {
|
||||
Self(roomContext: RoomScreenViewModel.mock.context)
|
||||
Self(timelineContext: TimelineViewModel.mock.context)
|
||||
}
|
||||
}
|
||||
|
||||
extension WysiwygTextView: PillAttachmentViewProviderDelegate {
|
||||
var roomContext: RoomScreenViewModel.Context? {
|
||||
(mentionDisplayHelper as? ComposerMentionDisplayHelper)?.roomContext
|
||||
var timelineContext: TimelineViewModel.Context? {
|
||||
(mentionDisplayHelper as? ComposerMentionDisplayHelper)?.timelineContext
|
||||
}
|
||||
|
||||
func invalidateTextAttachmentsDisplay() { }
|
||||
|
||||
@@ -28,11 +28,11 @@ final class PillContext: ObservableObject {
|
||||
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
init(roomContext: RoomScreenViewModel.Context, data: PillTextAttachmentData) {
|
||||
init(timelineContext: TimelineViewModel.Context, data: PillTextAttachmentData) {
|
||||
switch data.type {
|
||||
case let .user(id):
|
||||
let isOwnMention = id == roomContext.viewState.ownUserID
|
||||
if let profile = roomContext.viewState.members[id] {
|
||||
let isOwnMention = id == timelineContext.viewState.ownUserID
|
||||
if let profile = timelineContext.viewState.members[id] {
|
||||
var name = id
|
||||
if let displayName = profile.displayName {
|
||||
name = "@\(displayName)"
|
||||
@@ -40,7 +40,7 @@ final class PillContext: ObservableObject {
|
||||
viewState = PillViewState(isOwnMention: isOwnMention, displayText: name)
|
||||
} else {
|
||||
viewState = PillViewState(isOwnMention: isOwnMention, displayText: id)
|
||||
cancellable = roomContext.$viewState.sink { [weak self] viewState in
|
||||
cancellable = timelineContext.$viewState.sink { [weak self] viewState in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
@@ -73,7 +73,7 @@ extension PillContext {
|
||||
switch type {
|
||||
case .loadUser(let isOwn):
|
||||
pillType = .user(userID: testID)
|
||||
let viewModel = PillContext(roomContext: RoomScreenViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
let viewModel = PillContext(timelineContext: TimelineViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
viewModel.viewState = PillViewState(isOwnMention: isOwn, displayText: testID)
|
||||
Task {
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
@@ -82,12 +82,12 @@ extension PillContext {
|
||||
return viewModel
|
||||
case .loadedUser(let isOwn):
|
||||
pillType = .user(userID: "@test:test.com")
|
||||
let viewModel = PillContext(roomContext: RoomScreenViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
let viewModel = PillContext(timelineContext: TimelineViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
viewModel.viewState = PillViewState(isOwnMention: isOwn, displayText: "@Very Very Long Test Display Text")
|
||||
return viewModel
|
||||
case .allUsers:
|
||||
pillType = .allUsers
|
||||
return PillContext(roomContext: RoomScreenViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
return PillContext(timelineContext: TimelineViewModel.mock.context, data: PillTextAttachmentData(type: pillType, font: .preferredFont(forTextStyle: .body)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user