Conversational UI - Load old data and scrolling

1 Answer 378 Views
Chat (Conversational UI)
Chandra
Top achievements
Rank 1
Chandra asked on 15 Jun 2021, 12:28 PM

Hi,

I am exploring RadChat for Xamarin forms and wanted to know what is the most efficient way for:

  1. saving the chat messages to a database
  2. loading existing messages for a chat

Thanks,

Abhi

1 Answer, 1 is accepted

Sort by
0
Lance | Senior Manager Technical Support
Telerik team
answered on 15 Jun 2021, 07:11 PM | edited on 16 Jun 2021, 07:21 PM

Hi Chandra,

We intentionally designed RadChat to be completely decoupled from the data source type. This means you have the freedom to do whatever you want, so whatever you feel is the most efficient for your database type or API type can be used.

You can take a look at all our ConversationalUI Demos for some preliminary guidance.

Further Training

If what you are asking is "how do I load and save data form a database?" This is outside the scope of what the Telerik UI controls can help you with. That data layer is your business logic's responsibility. The only thing the RadChat control cares about is that you have an ItemsSource (e.g. Observablecollection) to bind to.

Here are some additional resources for you to keep researching

Update - Demo

To address the concerns you mentioned in your comment, I've built you a small demo so that I could better convey what I was explaining about using OnBindingContextChanged to track when an item is scrolled into the viewport.

If you build and run the attached app, you'll see the following result at runtime. As you scroll up and down, you'll see the Debug Output window will show you the Id of the data item that was just rendered.

> Find the relevant login in LeftMessageView.xaml.cs and RightMessageView.xaml.cs.

Important: There is still a bit of work to do to tie that item-rendered knowledge into some sort of database call and pull the next items, but this is a place that you can start. If this is a business critical feature and you're stuck with the implementation, this team can help.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Chandra
Top achievements
Rank 1
commented on 16 Jun 2021, 05:38 AM | edited

Hi Lance,

Thanks for the reply I understand that data persistence and retrieval is outside of the scope of RadChat. My question specifically then is how can we implement pagination and infinite scrolling type feature in RadChat? When the user is scrolling up, how do I determine when to retrieve more data to add to the chat items. Is there any event (similar to ListView.ItemAppearing or CollectionView.Scrolled in Xamarin.Forms) that provides the index of the current item visible on the screen so that we know when to load more data?

Thanks,

Abhishek
Lance | Senior Manager Technical Support
Telerik team
commented on 16 Jun 2021, 01:57 PM

Hi Chandra, thank you for clarifying. Currently the internal list component doesn't have support for load on demand (you can see the ControlTemplate here which has the ChatListView control). We do have it on the backlog, you can add your upvote here Chat: Provide support for Load on demand (telerik.com).

As far as an ItemLoaded kind of event, it's not on the top control. However, you can implement that in your item's DataTemplate to keep track of when an item is rendered. My favorite way to achieve it is to use a custom ContentView for the DataTemplate and use the BindingContextChanged event (or override OnBindingContextChanged). That works because the chat control will change the BindingContext of the container when it is reused for a newly scrolled-in item.

Now that you have a way to keep track of exactly which data item is visible in the view port of the scroller, you can make a decision on whether to fetch more items from the data source (in either direction; older/newer) and add those items to the ObservableCollection used for the ItemsSource

Lance | Senior Manager Technical Support
Telerik team
commented on 16 Jun 2021, 07:21 PM

I have updated my answer with a runnable demo that shows you how you can track when an item is scrolled into the viewport.
Chandra
Top achievements
Rank 1
commented on 17 Jun 2021, 03:22 AM

Thanks a lot Lance for providing the information and for the demo. This will definitely help.
Tags
Chat (Conversational UI)
Asked by
Chandra
Top achievements
Rank 1
Answers by
Lance | Senior Manager Technical Support
Telerik team
Share this question
or