Skip to content

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Dec 5, 2024

🔗 Issue Link

Fixes https://linear.app/stream/issue/IOS-559/thread-reply-footnote-view-not-shown-in-reply-show-in-channel

🎯 Goal

Fixes messages thread reply footnote view not shown when the parent message is not in cache.

🛠 Implementation

Problem

The issue is that in order to render the MessageRepliesView, we require a parentMessage. We get the parentMessage from the dataStore, but if the parent message is from an old page, it will return nil since it won't be in the local DB.

We can't change the parentMessage parameter to an optional since that would be a breaking change, and changing the Factory protocol could even lead to a silent breaking change for our customers.

Solution

1st try: Breaking Change

This one is tricky to solve without breaking changes. First, I tried to force a breaking change by making the function in the Factory @unavailable. But this is not possible. It is only supported by @objc protocols. Since we have default implementations of the factory, creating a real breaking change would be silent for customers, so this is not an option.

2nd try: Hack-ish Workaround

The first solution I did without breaking change was to provide the message reply as the parent message as well. Then, check if they had the same ID, and treat it as if parentMessage was nil. You can see the implementation here.

The problem with this approach is that it is very hacky and unexpected. I customer would need to know about this hack if they wanted to customize the view.

3rd try: Final Solution

The solution I found the best was to create a Lazy view of the existing MessageRepliesView. Whenever the parent message does not exist in the local cache, we fetch it and then display the view. From here on, it will be in the local cache until we logout, so it won't be always fetching.

This approach requires the least changes on our side and no changes on the customer side. The con, is whenever this case happens, it means additional requests will be made just to display a footnote view. Ideally, this request would only be executed only when opening the Thread View, but unfortunatly, until we have v5, there's no alternative.

🧪 Testing

  1. Open a Channel
  2. Load old pages
  3. Create a Thread Reply and check "Send also in channel"
  4. Logout
  5. Open the same Channel
  6. The "Thread Reply" footnote should be shown in reply created in 3.

🎨 Changes

Below is the fix demo. The thread reply view takes a bit of time to load since it is lazy-loaded and requires performing a request to show it.

Fix
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-12-05.at.18.52.50.mp4

☑️ Checklist

  • I have signed the Stream CLA (required)
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Affected documentation updated (docusaurus, tutorial, CMS (task created)

…to be fetched

This solution requires the least amount of changes and there is also no breaking change
@nuno-vieira nuno-vieira added the bug label Dec 5, 2024
@nuno-vieira nuno-vieira requested a review from a team as a code owner December 5, 2024 19:09
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Dec 5, 2024

SDK Size

title develop branch diff status
StreamChatSwiftUI 7.47 MB 7.53 MB +66 KB 🟢

Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea and solution, it's the best we can do atm ✅ Left one suggestion, let me know what you think.

self.factory = factory
self.channel = channel
self.message = message
parentMessageObserver.controller.synchronize()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we do this only onAppear? init can be called many times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode 15 was not happy with the current implementation, so I moved to onAppear, but this requires changing from Group, to use a VStack

Copy link

github-actions bot commented Dec 6, 2024

2 Errors
🚫 Please use more than one word.
f81cf5d
🚫 Please remove period from end of commit subject line.
f81cf5d

Generated by 🚫 Danger

Copy link

sonarqubecloud bot commented Dec 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
41.1% Coverage on New Code (required ≥ 70%)

See analysis details on SonarQube Cloud

@nuno-vieira nuno-vieira merged commit 2350e93 into develop Dec 6, 2024
10 of 12 checks passed
@nuno-vieira nuno-vieira deleted the fix/thread-reply-footer-not-shown-if-parentMessage-is-nil branch December 6, 2024 16:14
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants