How to store RadChat messages in Database and retrieve the data to display in chat window ?

1 Answer 39 Views
Chat (Conversational UI) General Discussions ListBox Window
Ayush
Top achievements
Rank 1
Ayush asked on 21 Dec 2021, 06:16 AM
I am working on Conversational UI and made a chat application , where we can chat with multiple users by maintaining a dictionary .&nbsp; Key is the user and value is the ChatViewModel having a ObservableCollection&lt;MessageBase&gt; and Author. Its is working properly but I want to store the messages in the database and When we select another to chat with , the previous messages stored in database will be display in the chatwindow and we can continue chatting. &nbsp; <br />

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 23 Dec 2021, 08:43 AM

Hello Ayush,

The RadChat control provide the chat UI and an interface to add/remove messages using ItemsSource or with the AddMessage() and RemovedMessage() methods. There is no built-in support for database connections, but you can use the already provided interface to achieve your requirement. Based on your requirement and preferences, you can use different approaches, but all will include the currently available API of RadChat.

For example, based on your current setup with the view model and the Message collection, you can try the following approach. Subscribe to the CollectionChanged event of the Message collection. Each time a message is added or removed, the event will fire, which you can use to update the database. When you load the control and need to fetch messages from the database, you can get the using EF or other ORM and then add them to the Messages collection.

I hope this information helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Chat (Conversational UI) General Discussions ListBox Window
Asked by
Ayush
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or