GetStream / stream-chat-swiftui

SwiftUI Chat SDK ➜ Stream Chat 💬
https://getstream.io/chat/sdk/swiftui/
Other
335 stars 80 forks source link

User mention is not highlighted unless I reload the chat #578

Closed f3dm76 closed 1 month ago

f3dm76 commented 1 month ago

What did you do?

I typed in @, picked a name from the built-un mentions picker, and sent a message. Then I tapped on the user name prefixed by @ inside the message.

What did you expect to happen?

I expected that in the message body my user mention would be highlighted with a corresponding link color. I also expected the link tap handler to be called when I tap the mention.

What happened instead?

Nothing happened - it's just a plain text. It only starts working once I go away from the chat and come back again.

GetStream Environment

GetStream Chat version: StreamChat 4.61.0, StreamChatSwiftUI 4.61.0 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: ios 18.0 Swift version: 5 Xcode version: 15.0.1 Device: sim iPhone 15 Pro Max

Additional context

I fixed it locally by adding .onChange(of: message.mentionedUsers) to LinkDetectionTextView and duplicating onAppear body inside of it. But you might have a better approach in mind

Here is a video of the bug https://github.com/user-attachments/assets/795f2036-522c-49f8-b444-f23520de216b

martinmitrevski commented 1 month ago

Hi @f3dm76,

We can't reproduce this issue on our default components (see the attached video). Are you maybe using some custom components around the text messages that might be causing this?

https://github.com/user-attachments/assets/2c53bcd9-5486-4d8a-b1a2-f5f93f671de8

Best, Martin

f3dm76 commented 1 month ago

Hey @martinmitrevski, I just removed the usage of a custom ViewFactory completely - here is all I do: streamChat = StreamChat(chatClient: chatClient) still the bug is there.

I understand that you cannot reproduce, I see indeed that it works in your chatUI example project. Does this example use actual BE? Maybe it works because there is no real life latency for message appearing?

The fact that the mentions are only checked on onAppear of a message looks incorrect - I can clearly see while debugging that it gets called with empty mentionedUsers. When adding onChange like I said, mentionedUsers come there.

martinmitrevski commented 1 month ago

The message already includes the mentioned users, therefore it's safe to check this in onAppear, there's no extra BE call to fetch them. I even tested with the network link conditioner and a very bad network, and it still works correctly.

In any case, if it works for you by adding an onChange modifier - I don't see any harm in having it.

f3dm76 commented 1 month ago

I just commented out all of the DemoAppFactory's body - and it stopped working on SC example project. onChange I added is inside SC library code, I'd like to avoid moving to a fork over such a simple matter.

f3dm76 commented 1 month ago

Hey @martinmitrevski, were you successful in reproducing the issue the way I described?

martinmitrevski commented 1 month ago

Hi @f3dm76, yes, I can reproduce it. Seems like an issue in our low-level client, we will check it. If it's not, we will apply your fix instead.

martinmitrevski commented 1 month ago

Will be fixed here: https://github.com/GetStream/stream-chat-swiftui/pull/582.