Skip to content

Commit

Permalink
Merge branch 'develop' into public-create-poll-view
Browse files Browse the repository at this point in the history
  • Loading branch information
laevandus authored Dec 9, 2024
2 parents 224a947 + 2350e93 commit a9c29c0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### 🐞 Fixed
- Fix message thread reply footnote view not shown if parent message not in cache [#681](https://github.com/GetStream/stream-chat-swiftui/pull/681)
### ⚡ Performance
- Improve message search performance [#680](https://github.com/GetStream/stream-chat-swiftui/pull/680)
### ✅ Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
)
.accessibilityElement(children: .contain)
.accessibility(identifier: "MessageRepliesView")
} else if message.showReplyInChannel, let parentId = message.parentMessageId {
/// In case the parent message is not available in the local cache, we need to fetch it from the remote server.
/// The lazy view uses the `factory.makeMessageRepliesShownInChannelView` internally once the parent message is fetched.
LazyMessageRepliesView(
factory: factory,
channel: channel,
message: message,
parentMessageController: chatClient.messageController(
cid: channel.cid,
messageId: parentId
)
)
.accessibilityElement(children: .contain)
.accessibility(identifier: "MessageRepliesView")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,45 @@ public struct MessageRepliesView<Factory: ViewFactory>: View {
}
}
}

/// Lazy view that uses the message controller to fetch the parent message before creating message replies view.
/// This is needed when the parent message is not available in the local cache.
/// Changing the `parentMessage` to `nil` in the `MessageRepliesView` would case multiple changes including breaking changes.
struct LazyMessageRepliesView<Factory: ViewFactory>: View {
@StateObject private var parentMessageObserver: ChatMessageController.ObservableObject

var factory: Factory
var channel: ChatChannel
var message: ChatMessage

init(
factory: Factory,
channel: ChatChannel,
message: ChatMessage,
parentMessageController: ChatMessageController
) {
_parentMessageObserver = StateObject(wrappedValue: parentMessageController.observableObject)
self.factory = factory
self.channel = channel
self.message = message
}

var body: some View {
VStack {
if let parentMessage = parentMessageObserver.message {
factory.makeMessageRepliesShownInChannelView(
channel: channel,
message: message,
parentMessage: parentMessage,
replyCount: parentMessage.replyCount
)
} else {
EmptyView()
}
}.onAppear {
if parentMessageObserver.message == nil {
parentMessageObserver.controller.synchronize()
}
}
}
}

0 comments on commit a9c29c0

Please sign in to comment.