Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreviewDataFetched on every old message when a new message comes in #64

Closed
m-j-g opened this issue Aug 4, 2021 · 4 comments
Closed
Labels
question Further information is requested

Comments

@m-j-g
Copy link

m-j-g commented Aug 4, 2021

Hey guys, finally got around to playing with flyer today. It's really simple and easy to use, nice! I pretty much was just following the example except sending/receiving messages from back end.

If let's say a link was sent, It shows the link briefly and then shows the preview data when it becomes available - which is nice, this is great.

But then when a new message comes in and "messages" updates. it adds the new message to the bottom and that previous message switches back to a link and then shows the preview data again. So, it's like starting over processing every message every time a new message comes in which is kind of jarring as it jumps back and forth between a link and the preview data every time a message comes in.

I'm not sure if theres something I can do in my implementation to make messages incremental instead of a full reload? Or if this is something that needs to happen inside the library to do a diff? Let me know if I'm doing something wrong.

@m-j-g m-j-g added the question Further information is requested label Aug 4, 2021
@demchenkoalex
Copy link
Member

demchenkoalex commented Aug 5, 2021

Hi, thanks for asking. Flutter fully reloads visible messages when update happens, we can't do anything about it. Regarding the preview, as you can see in the example here https://github.com/flyerhq/flutter_chat_ui/blob/main/example/lib/main.dart#L148 or inside the Firebase lib https://github.com/flyerhq/flutter_firebase_chat_core/blob/main/example/lib/chat.dart#L167 you need to implement onPreviewDataFetched and update your message on backend so it contains filled previewData. In our Firebase implementation when we update something it immediately syncs so basically you have previewData set and our preview library works in a way that when previewData is set it will use it instead of trying to unwrap once again. In your case there is no sync probably, so maybe you can try to update messages on backend and locally and it should stop trying to fetch the preview with each update.

@zahidshaikh08
Copy link

Don't you think instead of making message.dart a StatelessWidget we can have a StatefulWidget which might solve this issue. Didn't tried just an OPINION, i don't know if it will work or not but we can try this.

Or if performance is not concerned we can even add AutomaticKeepAliveClientMixin to message.dart so that it will not loose its state while refreshing or building state again on new messages add or list change. Again it's just an OPINION didn't tried.

@demchenkoalex
Copy link
Member

@zahidshaikh08 my comment above should solve the issue, it is how we planned it work, it is how it works with Firebase.

We had stateful widget before and it didn't work, don't remember the problem exactly, but it was so bad we replaced it with stateless widget and came up with this callback/user stores data system.

Not an option to keep these in memory since this chat should work on thousands of messages.

@m-j-g
Copy link
Author

m-j-g commented Aug 9, 2021

@demchenkoalex haha I completely missed it! I didn't realize the strategy was to update firestore with the preview, I thought it was expected to do it on the fly (locally) each time. That clears it up for sure, makes sense.

@m-j-g m-j-g closed this as completed Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants