This is a migrated thread and some comments may be shown as answers.

How do I stop the automatic creation of a new TextMessage when user taps on Send button?

1 Answer 96 Views
Chat (Conversational UI)
This is a migrated thread and some comments may be shown as answers.
Abraham Atsbaha
Top achievements
Rank 2
Abraham Atsbaha asked on 25 Feb 2021, 12:23 PM

 

 

I'm using RadChat control.
I use MVVM approach to bind the control's ItemSource to an ObservableCollection property in my ViewModel.

So in my xaml I have something like this:

<telerikConversationalUI:RadChat
     Author="{Binding Me}"
     ItemsSource="{Binding Messages}"
     ItemConverter="{StaticResource SimpleChatItemConverter}"
     SendMessageCommand="{Binding SendMessageTappedCommand}"
     ItemTemplateSelector="{StaticResource MyChatItemTemplateSelector}"
     ControlTemplate="{StaticResource RadChat_ControlTemplate}"
 >

 

In my ViewModel I have something like this:

public ObservableCollection<CustomMessage> Messages { set; get; }

I have CustomMessage class which contains additional properties like MessagePostedDate (which is of type DateTime, it contains the DateTime of when the message was posted)

I've also bound SendMessageCommand in RadChat control to a command (SendMessageTappedCommand) in my ViewModel.

What I've noticed is that when the Send button is tapped, the component automatically adds a new TextMessage (with Text property set to whatever the user typed) to the list, and only then does it call the SendMessageTappedCommand in my ViewModel. However, I do not want the automatic addition of a new TextMessage since I add a new CustomMessage item to Messages collection, which is bound to the RadChat control, and the SimpleChatItemConverter (which I've bound to ItemConverter of the RadChat control) converts that CustomMessage, and displays the posted date.

So the problem is everytime the user inputs a message and clicks on Send, the message ends up showing twice. First one shows up without the posted date (because a new TextMessage is automatically appended by the component), and the second message is with posted date, which was added by my SendMessageTappedCommand.

How do I stop the automatic creation of a new TextMessage when user taps on Send button?

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 01 Mar 2021, 07:28 AM

Hi Abraham,

Indeed, SendMessageCommand is raised after the message is already added to the Chat messages (I will update our documentation right away).  Still, through the ChatItemsConverter you should be able to use the custom messages you have.  I am not sure why these messages are added twice - in order to troubleshoot the issue I would need more details on the exact implementation.  Would it be possible to send me the converter, the ItemTemplateSelector as well as the used ControlTemplate, so I can try to replicate the setup on my side and test the scenario? 

I look forward to your reply.

Regards,
Yana
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/.

Tags
Chat (Conversational UI)
Asked by
Abraham Atsbaha
Top achievements
Rank 2
Answers by
Yana
Telerik team
Share this question
or