Cancel message adding to collection if api response is false

Hi,

I am using SfChat control and want to know how to cancel adding the message to the collection if my API call fails for some reason.

Currently I am looking at the documentation and it says to use the below:

public void Execute(object parameter)

   {

       (parameter as SendMessageEventArgs).Handled = true;

   }


The above works but I need to set this conditionally like the below (which doesn't seem to work) - e.g the message is always added to the local collection - even if the API call to save the message on the server returns false (it failed)


var result = await api_call_to_save_message(newMessage);

if (!result) 

{

     (parameter as SendMessageEventArgs).Handled = true;

     _dialogService.DisplayAlert('Success - Message Saved');

}

else

{

  (parameter as SendMessageEventArgs).Handled = false;

 _dialogService.DisplayAlert('Error - Message Failed To Save - do you want to try sending again?');

}


Does SfChat control have a way/event/command (using MVVM) to only add the new message to the local collection if the check is passed? Or the ability to remove the failed message from the collection?




2 Replies

DA Dan December 1, 2020 09:44 AM UTC

I have solved this by manually removing the message from the collection for now. 

But if we have a better way please let me know - maybe a feature to handle 'unsent' message or a 'retry' sending message might be useful.

Thanks.


GS Gokul Saravanan Syncfusion Team December 1, 2020 04:22 PM UTC

Hi Dan, 
 
Thanks for contacting Syncfusion support.  
 
We have checked your query ”Handle unsent messages in SfChat”. Currently we doesn’t have any support like event or command to handle unsent messages. We will validate and let you know whether the requirement can be considered as future. We will appreciate your patience until then. 
 
Thanks 
Gokul S 


Loader.
Up arrow icon