Persistent chat message with Akavache in Xamarin.forms

116 views Asked by At

I am new to Xamarin Forms. I am building a chat App with Xamarin Forms and Signalr and I want to make the chat messages persistent just like WhatsApp. I'm using Akavache, but I don't seem to be succeeding. I have this code snippet in my ChatPage ViewModel

if(ChatMessageList.Count != 0)
    {
       var _messages = BlobCache.LocalMachine.GetObject<ChatMessage>("Messages");

       ChatMessage chatMessage = new ChatMessage() { Message = _messages.Subscribe(x => 
 chatmessage.Message = x.Message).ToString(), IsOwnMessage = isMe, IsSystemMessage = false, 
        ActionTime = _messages.Subscribe(x => chatmessage.ActionTime = x.ActionTime).ToString() };

        ChatMessageList.Add(chatMessage);

        MessagingCenter.Send(this, "SCROLL_BOTTOM");
      }
      else
      {
           ChatMessage chatMessage = new ChatMessage() { Message = message, IsOwnMessage = isMe, 
           IsSystemMessage = false, ActionTime = DateTime.Now.ToString("hh:mm tt") };

                ChatMessageList.Add(chatmessage);                    

           BlobCache.LocalMachine.InsertObject<ChatMessage>("Messages", chatMessage);
        }

Now the chat messages are in system codes. Are can I go about this, please.

0

There are 0 answers