SfChat deleting comma when sent

Hello,

The SfChat function is deleting commas when sent. None of our bound values change the text value nor does the convertor. 


<sfChat:SfChat x:Name="sfChat" AttachmentButtonClicked="sfChat_AttachmentButtonClicked" ShowAttachmentButton="False" CanAutoScrollToBottom="True" PropertyChanged="sfChat_PropertyChanged" ShowMessageInputView="True" BackgroundColor="{StaticResource PrimaryBackgroundColor}" Padding="0,0,0,20" VerticalOptions="FillAndExpand"

                        IsVisible="{Binding IsChatVisible}" ItemsSource="{Binding Conversation.Conversations, Mode=TwoWay}" ItemsSourceConverter="{StaticResource MessageConverter}"

                        SendMessage="sfChat_SendMessage" ShowIncomingMessageAvatar="False" ShowOutgoingMessageAvatar="False" MessageShape="RoundedRectangle"

                        ShowIncomingMessageAuthorName="False" ShowTypingIndicator="False" ShowOutgoingMessageAuthorName="False" ShowIncomingMessageTimestamp="False" ShowOutgoingMessageTimestamp="False" AttachmentButtonTemplate="{StaticResource NoBadgeAttachmentButton}">

                   </sfChat:SfChat>


Thanks,

David


3 Replies

SV Suja Venkatesan Syncfusion Team September 16, 2022 01:43 PM UTC

Hi David,


We would like to let you know that we are unable to replicate the reported scenario on our end. We have checked the reported scenario in simple SfChat sample with provided code snippet. Could you please share the details with code snippets of converter which you assigned to ItemsSourceConveter with SfChat and Xamarin.Forms version?  The sample we have used to check the reported issue available in the attachment. Please have a look at this sample and let us know if missed any customization you have done in your application or revert to us the modified sample to replicate the reported scenario on our end.


Additional Information:

Tested device:  Android: Physical device- Redmi Note 8 pro(Android 11.0- API 30) 

                             iOS: Visual Studio Simulator-iPhone 12 pro Max(iOS 14.5)


Regards,

Suja


Attachment: repos_ee1c756e.zip


DB David Bauer September 16, 2022 03:32 PM UTC

Hello Suja,


I was breaking through the code and it appears the text displays in the chat prior to the converter being called and all of the values have the comma in them. 


Here are the model values:

 public class MessageModel

    {

        public MessageModel()

        {

        }


        public string message { get; set; }

        private List<Stream> attachmentStreams = new List<Stream>();

        public List<Stream> AttachmentStreams

        {

            get

            {

                return attachmentStreams;

            }

            set

            {

                attachmentStreams = value;

            }

        }

        private List<string> attachmentUrls = new List<string>();

        public List<string> AttachmentUrls

        {

            get => attachmentUrls;

            set

            {

                value = attachmentUrls;

            }

        }

        public List<Attachments> Attachments

        {

            set

            {

                foreach (var attachment in value)

                {

                    AttachmentUrls.Add(attachment.attachment_url);

                    //attachmentStreams.Add(HelperAPIs.GetStreamFromUrl(attachment.attachment_url));

                }

            }

        }

        public bool fromSupport { get; set; }

        public DateTime createdAt { get; set; }

        public string user => fromSupport ? "Me" : "EveryDose";

        public Author person { get; set; }

        public string Type { get; set; }

    }


    public class Conversation : ViewModelBase

    {

        public Conversation()

        {

        }

        public long id { get; set; }

        private ObservableCollection<MessageModel> conversations;

        public ObservableCollection<MessageModel> Conversations

        {

            get

            {

                return conversations;

            }

            set

            {

                conversations = value;

                RaisePropertyChanged("Conversations");

            }

        }

    }


Here is the ItemsSourceConveter:


    public class MessageConverter : IChatMessageConverter

    {

        /// <summary>

        /// Converts given data object to a chat message.

        /// </summary>

        /// <param name="data">The data object to be converted as a chat message.</param>

        /// <param name="chat">Instance of <see cref="SfChat"/>. </param>

        /// <returns>Returns the data object as a chat message.</returns>

        public IMessage ConvertToChatMessage(object data, SfChat chat)

        {

            var item = data as MessageModel;


            if ((item.AttachmentStreams != null && item.AttachmentStreams.Count > 0) || (item.AttachmentUrls != null && item.AttachmentUrls.Count > 0))

            {

                var message = new ImageMessage();

                if (item.AttachmentStreams.Count > 0)

                {

                    message.Source = ImageSource.FromStream(() => item.AttachmentStreams[0]);

                }

                else

                {

                    message.Source = ImageSource.FromUri(new Uri(item.AttachmentUrls[0]));

                }

                message.Text = item.message;

                message.Data = item;

                //message.Aspect = Aspect.AspectFit;

                message.Size = new Size(300, 300);


                if (!item.fromSupport)

                    message.Author = chat.CurrentUser;

                return message;

            }

            else

            {

                var message = new ImageMessage();

                message.Text = item.message;

                message.Data = item;


                if (!item.fromSupport)

                    message.Author = chat.CurrentUser;

                return message;

            }



        }


        public object ConvertToData(object chatMessage, SfChat chat)

        {

            var message = new MessageModel();

            var item = chatMessage as TextMessage;


            message.message = item.Text;

            message.person = chat.CurrentUser;

            //if (message.Suggestions != null)

            //{

            // message.Suggestions = chat.Suggestions;

            //}

            return message;

        }

    }


Thanks,

David



SV Suja Venkatesan Syncfusion Team September 19, 2022 02:49 PM UTC

Hi David,


We regret to let you know that we are unable to replicate the reported scenario on our end. We have checked the code snippets which you have provided in your previous update. In ConvertToChatMessage method in MessageConverter class you have created all messages as image message only, we didn’t find any code snippets releated TextMessage conversion. We have prepared a sample with provided and attached it here for your reference. Please have a look at this sample and let us know if missed any customization you have done in your application or revert us with modified sample to replicate the reported scenario on our end. Could you please confirm the platform(Xamarin.Forms.Android,Xamarin.Forms.iOS or Xamarin.Forms.UWP) in which you are facing the reported scenario with SfChat and Xamarin.Forms version?
It will be more helpful for us to provide a timely solution.


Regards,

Suja


Attachment: GettingStarted_7c3b98e1.zip

Loader.
Up arrow icon