private async Task RemoveFromBlackListAsync(long id)
        {
            try
            {
                BTProgressHUD.Show("UnBlocked Contacts", maskType: ProgressHUD.MaskType.Black);
                var model = new userdetails
                {
                    BlockUserID = id
                };

                var result = await new SettingService().PostUnBlockUserInterest(model);
                if (result.Status == 1)
                {
                    ChatConversationRepository.UpdateUnBlock(chatConversation.ChatId);
                    new UIAlertView("Blocked Contacts", result.Message, null, "OK", null).Show();
                    BTProgressHUD.Dismiss();
                }
                else
                {
                    new UIAlertView("Blocked Contacts", result.Message, null, "OK", null).Show();
                    BTProgressHUD.Dismiss();
                }

                BTProgressHUD.Dismiss();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                BTProgressHUD.Dismiss();
            }
        }
Example #2
0
 private void _objChatSignalRService_OnGetUpdateStatus(object sender, ChatMessageViewModel e)
 {
     try
     {
         if (e.ChatMessageId != 0)
         {
             var chatmessage = ChatMessageRepository.CheckMessage(e.ChatMessageId);
             if (chatmessage != null)
             {
                 var savedMessages    = ChatMessageRepository.updateChatMessage(e);
                 var chatConversation = ChatConversationRepository.GetConversationIdbyChatId(savedMessages.ChatId);
                 if (chatConversation != null)
                 {
                     Activity.RunOnUiThread(() =>
                     {
                         MessageReceived(chatConversation, "OldChat");
                     });
                 }
             }
         }
     }
     catch (Java.Lang.Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
Example #3
0
        private async void RemoveFromBlackListAsync(long id)
        {
            CommonHelper.ShowProgressBar(context);

            var model = new userdetails
            {
                BlockUserID = id
            };

            var result = await new SettingService().PostUnBlockUserInterest(model);

            if (result.Status == 1)
            {
                ChatConversationRepository.UpdateBlock(id, false);

                CommonHelper.DismissProgressBar(context);
                Toast.MakeText(context, result.Message, ToastLength.Long).Show();
            }
            else
            {
                CommonHelper.DismissProgressBar(context);
                Toast.MakeText(context, result.Message, ToastLength.Long).Show();
            }
            CommonHelper.DismissProgressBar(context);
        }
Example #4
0
        private async void LoaderAsyncfromserver()
        {
            try
            {
                await Task.Run(async() =>
                {
                    var result = await new ChatService().getChatAll(new UserRequestViewModel {
                        UserId = CommonHelper.GetUserId()
                    });

                    if (result.Status == 1)
                    {
                        var chatlist = JsonConvert.DeserializeObject <List <ChatModel> >(result.Response.ToString());
                        Console.Write(result.Status);
                        ChatConversationRepository.SaveChatConversationFromServer(chatlist);
                        Activity.RunOnUiThread(() =>
                        {
                            LoadLocalChats();
                        });
                    }
                });
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
        public async void BlockContact(long id)
        {
            BTProgressHUD.Show("Block Contact", maskType: ProgressHUD.MaskType.Black);
            var model = new userdetails
            {
                BlockUserID = id
            };

            var result = await new SettingService().PostBlockUserInterest(model);

            if (result.Status == 1)
            {
                lblBlockUser.Text = "UnBlock";
                ChatConversationRepository.UpdateBlock(contactViewModel.ChatConvId);
                BTProgressHUD.Dismiss();
                new UIAlertView("Block Contact", result.Message, null, "OK", null).Show();
            }
            else
            {
                BTProgressHUD.Dismiss();
                new UIAlertView("Block Contact", result.Message, null, "OK", null).Show();
            }

            BTProgressHUD.Dismiss();
        }
Example #6
0
        public void getUserDetails()
        {
            var chatConversationResponce = ChatConversationRepository.GetConversationbyContactId(contactViewModel.ContactId);

            if (chatConversationResponce.success)
            {
                chatConversation = chatConversationResponce.chatConversation;
            }
            if (contactViewModel != null)
            {
                ContactName = ContactRepository.GetContactbyUserId(contactViewModel.ContactId).name;
                contactId   = contactViewModel.ContactId;
                Title       = ContactName;

                var titleView = new UILabel(new CGRect(0, 0, 100, 60));
                titleView.Text      = ContactName;
                titleView.TextColor = UIColor.White;
                var ShowUserProfileViewController = new UITapGestureRecognizer(() =>
                {
                    var viewController = (UserProfileViewController)Storyboard.InstantiateViewController("UserProfileViewController");
                    viewController.contactViewModel = contactViewModel;
                    NavigationController.PushViewController(viewController, true);
                });
                titleView.UserInteractionEnabled = true;
                titleView.AddGestureRecognizer(ShowUserProfileViewController);
                NavigationItem.TitleView = titleView;
            }
        }
Example #7
0
        private async void _objChatSignalRService_OnMessageReceived(object sender, ChatMessageViewModel e)
        {
            try
            {
                if (e.ChatMessageId != 0)
                {
                    var chatmessage = ChatMessageRepository.CheckMessage(e.ChatMessageId);
                    if (chatmessage == null)
                    {
                        var savedMessages    = ChatMessageRepository.SaveChatMessage(e, e.ChatId);
                        var chatConversation = ChatConversationRepository.GetConversationIdbyChatId(savedMessages.ChatId);
                        if (e.Attachments.Count > 0)
                        {
                            savedMessages.MessageText = (string.IsNullOrEmpty(savedMessages.MessageText))? e.Attachments[e.Attachments.Count - 1].Type : savedMessages.MessageText;
                        }
                        chatConversation = ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, savedMessages.MessageText, "");
                        if (chatConversation != null)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                MessageReceived(chatConversation, "OldChat");
                            });
                        }

                        await _objChatSignalRService.SendUpdate(chatConversation.ContactId.ToString(), e, "ChatList");
                    }
                }
            }
            catch (Java.Lang.Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Example #8
0
 private void _objChatSignalRService_OnGetGroupCreateStatusRecieved(object sender, GroupResponseViewModel e)
 {
     try
     {
         if (e.GroupId != 0)
         {
             GroupRepository.SaveGroupCreated(e);
             ChatModel cm = new ChatModel();
             cm.ChatId         = e.ChatModel.ChatId;
             cm.GroupId        = e.ChatModel.GroupId;
             cm.Message        = e.ChatModel.Message;
             cm.LastActiveTime = e.ChatModel.LastActiveTime;
             ChatConversation chatConversation = ChatConversationRepository.SaveGroupConverstionNewFromServer(cm);
             if (chatConversation != null)
             {
                 Activity.RunOnUiThread(() =>
                 {
                     MessageReceived(chatConversation, "NewChat");
                 });
             }
         }
     }
     catch (Java.Lang.Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
        private void LoadLocalChats()
        {
            Chats = ChatConversationRepository.GetAllChat().ToList();

            if (Chats.Count > 0)
            {
                tblChatList.TableFooterView = new UIView();

                chatsource = new ChatListViewControllerSource(Chats, this);

                tblChatList.Source    = chatsource;
                tblChatList.RowHeight = 60;
                tblChatList.ReloadData();
            }
        }
Example #10
0
        public void loadLocalData()
        {
            var BlockedContactList = ChatConversationRepository.GetAllBlockList();

            if (BlockedContactList != null && BlockedContactList.Count > 0)
            {
                mAdapter = new BlockedContactListAdapter(BlockedContactList, this);
                // mAdapter.ListReload += ListReload;
                mRecyclerView.SetAdapter(mAdapter);
                mAdapter.NotifyDataSetChanged();
            }
            else
            {
                Toast.MakeText(this, "No contact found", ToastLength.Long).Show();
            }
        }
Example #11
0
 private async void _objChatSignalRService_OnGroupMessageReceived(object sender, GroupMessageResponseViewModel e)
 {
     try
     {
         if (e.MessageId != 0)
         {
             var chatmessage = GroupRepository.CheckGroupChatMessage(e.MessageId, e.GroupId);
             if (chatmessage == null)
             {
                 GroupRepository.SaveGroupMessage(e, "ChatList");
                 var chatConversation = ChatConversationRepository.GetConversationbyGroupId(e.GroupId);
                 if (e.Attachments.Count > 0)
                 {
                     e.Message = (string.IsNullOrEmpty(e.Message)) ? e.Attachments[e.Attachments.Count - 1].Type : e.Message;
                 }
                 chatConversation = ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, e.Message, e.SenderProfileName);
                 if (chatConversation != null)
                 {
                     Activity.RunOnUiThread(() =>
                     {
                         MessageReceived(chatConversation, "OldChat");
                     });
                 }
                 //else
                 //{
                 //    Activity.RunOnUiThread(() =>
                 //    {
                 //        //chatConversation = new ChatConversation();
                 //        //chatConversation.ChatId = e.ChatId;
                 //        //chatConversation.ContactId = e.ContactId;
                 //        //chatConversation.CreatedDate = e.MessageTime;
                 //        //chatConversation.
                 //        //MessageReceived(chatConversation, "NewChat");
                 //    });
                 //}
                 GroupMessageStatusViewModel _model = new GroupMessageStatusViewModel();
                 _model.GroupMessageId = e.MessageId;
                 await _objChatSignalRService.SendGroupMessageUpdate(e.SenderId.ToString(), _model, "ChatList");
             }
         }
     }
     catch (Java.Lang.Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
Example #12
0
 private void LoadLocalChats()
 {
     try
     {
         Chats = ChatConversationRepository.GetAllChat();
         if (Chats.Count > 0)
         {
             _adapter = new ChatListAdapter(this.Context, Chats);
             _adapter.PrivateChatItemClick += _adapter_ItemClick;
             _adapter.GroupChatItemClick   += _adapter_GroupChatItemClick;
             mRecyclerView.SetAdapter(_adapter);
             _adapter.NotifyDataSetChanged();
         }
     }
     catch (Exception ex)
     { Crashes.TrackError(ex); }
 }
Example #13
0
        private async Task LoadBlockedContactListAsync()
        {
            try
            {
                BlockedContactList = ChatConversationRepository.GetAllBlockList();

                if (BlockedContactList != null && BlockedContactList.Count > 0)
                {
                    tblBlockedUserList.TableFooterView = new UIView();

                    blockedContactsViewControllerSource = new BlockedContactsViewControllerSource(BlockedContactList);

                    tblBlockedUserList.Source    = blockedContactsViewControllerSource;
                    tblBlockedUserList.RowHeight = 50;
                    tblBlockedUserList.ReloadData();
                }
            }
            catch (Exception ex)
            {
                new UIAlertView("Blocked Contacts", ex.ToString(), null, "OK", null).Show();
            }
        }
        private async void _objChatSignalRService_OnGroupMessageReceived(object sender, GroupMessageResponseViewModel e)
        {
            try
            {
                if (e.MessageId != 0)
                {
                    var chatmessage = GroupRepository.CheckGroupChatMessage(e.MessageId, e.GroupId);
                    if (chatmessage == null)
                    {
                        GroupRepository.SaveGroupMessage(e, "ChatList");
                        var chatConversationResponse = ChatConversationRepository.GetConversationbyGroupId(e.GroupId);
                        if (chatConversationResponse.success)
                        {
                            if (e.Attachments.Count > 0)
                            {
                                e.Message = (string.IsNullOrEmpty(e.Message)) ? e.Attachments[e.Attachments.Count - 1].Type : e.Message;
                            }
                            chatConversationResponse.chatConversation = ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, e.Message, e.SenderProfileName);
                            if (chatConversationResponse.chatConversation != null)
                            {
                                InvokeOnMainThread(() =>
                                {
                                    MessageReceived(chatConversationResponse.chatConversation, "OldChat");
                                });
                            }
                        }

                        GroupMessageStatusViewModel _model = new GroupMessageStatusViewModel();
                        _model.GroupMessageId = e.MessageId;
                        await _objChatSignalRService.SendGroupMessageUpdate(e.SenderId.ToString(), _model, "ChatList");
                    }
                }
            }
            catch (Exception ex)
            {
                //Crashes.TrackError(ex);
            }
        }
        public async void BlockContact(long id)
        {
            CommonHelper.ShowProgressBar(this);
            var model = new userdetails
            {
                BlockUserID = id
            };

            var result = await new SettingService().PostBlockUserInterest(model);

            if (result.Status == 1)
            {
                txtBlockContact.Text = "UnBlock";
                ChatConversationRepository.UpdateBlock(ContactObject.ChatConvId, true);
                CommonHelper.DismissProgressBar(this);
                Toast.MakeText(this, result.Message, ToastLength.Long).Show();
            }
            else
            {
                CommonHelper.DismissProgressBar(this);
                Toast.MakeText(this, result.Message, ToastLength.Long).Show();
            }
            CommonHelper.DismissProgressBar(this);
        }
        public async void ButtonSendChatMessage(string sMessageText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sMessageText))
                {
                    var chatModel = new ChatMessageViewModel
                    {
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        ContactId   = contactId,
                        Message     = sMessageText.Trim(' ', '\n'),
                        IsRead      = false,
                        IsRecieved  = false,
                        IsSend      = false,
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };


                    var chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                    if (chatConversationResponse.success)
                    {
                        if (chatConversationResponse.chatConversation != null)
                        {
                            var message = ChatMessageRepository.SaveChatMessage(chatModel, chatConversationResponse.chatConversation.ChatId);
                            chatModel.MobiledatabaseId = message.id;
                            chatModel.ChatId           = chatConversationResponse.chatConversation.ChatId;
                            chatModel.IsRead           = false;
                            chatModel.IsRecieved       = false;
                            chatModel.IsSend           = false;
                            var msg = new Message
                            {
                                Type = MessageType.Outgoing,
                                Text = sMessageText.Trim()
                            };

                            messages.Add(msg);
                            tableView.InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(messages.Count - 1, 0) }, UITableViewRowAnimation.None);
                            ScrollToBottom(true);
                        }
                    }
                    lstAttachments = new List <AttachmentViewModel>();
                    try
                    {
                        var result = await new ChatService().PostChat(chatModel);

                        if (result.Status == 2 || result.Status == 1)
                        {
                            var ChatResponse = JsonConvert.DeserializeObject <PostChatResponseViewModel>(result.Response.ToString());

                            if (chatConversationResponse.chatConversation == null)
                            {
                                ChatConversationRepository.SaveConverstionNewFromServer(ChatResponse.Chat);
                                chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                                if (chatConversationResponse.success)
                                {
                                    ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                    var savedMessages = ChatMessageRepository.SaveChatMessage(ChatResponse.ChatMessage, chatConversationResponse.chatConversation.ChatId);
                                }
                                LoadLocalLatestMessages();
                                Console.WriteLine("CHAT POSTED : " + result);
                            }
                            else
                            {
                                chatConversationResponse = ChatConversationRepository.GetConversationbyContactId(contactId);
                                if (chatConversationResponse.success)
                                {
                                    ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, ChatResponse.ChatMessage.Message, "");
                                }
                                var savedMessages = ChatMessageRepository.updateChatMessage(ChatResponse.ChatMessage);
                                LoadLocalLatestMessages();
                                await _objChatSignalRService.Send(chatConversationResponse.chatConversation.ContactId.ToString(), ChatResponse.ChatMessage);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
        public void UpdateCell(ChatConversation chatConverstions)
        {
            var chat = ChatConversationRepository.GetConversationIdbyChatId(Convert.ToInt32(chatConverstions.ChatId));

            CommonHelper.SetCircularImage(ProfileImage);

            if (chat != null)
            {
                if (chat.IsGroup == false)
                {
                    var contact = ContactRepository.GetContactbyUserId((long)chat.ContactId);
                    if (contact != null)
                    {
                        if (!string.IsNullOrEmpty(contact.contactPicUrl))
                        {
                            ProfileImage.SetImage(new NSUrl(contact.contactPicUrl), UIImage.FromBundle("default_profile.png"));
                        }
                        else
                        {
                            ProfileImage.Image = new UIImage("default_profile.png");
                        }

                        lblChatUserName.Text = contact.screenName;

                        if (chatConverstions.LastMessageDate.HasValue)
                        {
                            if (Convert.ToDateTime(chatConverstions.LastMessageDate).Date == DateTime.UtcNow.ToLocalTime().Date)
                            {
                                lblChatLastTime.Text = Convert.ToDateTime(chatConverstions.LastMessageDate).ToString("hh:mm tt");
                            }
                            else
                            {
                                lblChatLastTime.Text = Convert.ToDateTime(chatConverstions.LastMessageDate).Date.ToString("MM/dd/yyyy");
                            }
                        }
                        if (!string.IsNullOrEmpty(chatConverstions.LastMessage))
                        {
                            lblChatLastMessage.Text = chatConverstions.LastMessage;
                        }
                        else
                        {
                            lblChatLastMessage.Text = "";
                        }

                        int count = ChatMessageRepository.getChatMessageUnRead(chatConverstions.ChatId);

                        if (count > 0)
                        {
                            lblMessageCount.Hidden = false;
                            lblMessageCount.SetTitle(count.ToString(), UIControlState.Normal);
                        }
                        else
                        {
                            lblMessageCount.Hidden = true;
                        }
                    }
                }
                else
                {
                    var group = GroupRepository.GetGroupByID((long)chat.GroupId);
                    if (group != null)
                    {
                        if (!string.IsNullOrEmpty(group.GroupPictureUrl))
                        {
                            ProfileImage.SetImage(new NSUrl(group.GroupPictureUrl), UIImage.FromBundle("grouplist.png"));
                        }
                        else
                        {
                            ProfileImage.Image = new UIImage("grouplist.png");
                        }

                        lblChatUserName.Text = group.GroupName;

                        if (chatConverstions.LastMessageDate.HasValue)
                        {
                            if (Convert.ToDateTime(chatConverstions.LastMessageDate).Date == DateTime.UtcNow.ToLocalTime().Date)
                            {
                                lblChatLastTime.Text = Convert.ToDateTime(chatConverstions.LastMessageDate).ToString("hh:mm tt");
                            }
                            else
                            {
                                lblChatLastTime.Text = Convert.ToDateTime(chatConverstions.LastMessageDate).Date.ToString("MM/dd/yyyy");
                            }
                        }
                        if (!string.IsNullOrEmpty(chatConverstions.LastMessage))
                        {
                            lblChatLastMessage.Text = chatConverstions.LastMessage;
                        }
                        else
                        {
                            lblChatLastMessage.Text = "";
                        }

                        if (!string.IsNullOrEmpty(chatConverstions.LastMessage))
                        {
                            lblChatLastMessage.Text = chatConverstions.SenderName + " : " + chatConverstions.LastMessage;
                        }
                        else
                        {
                            var GroupUser = ContactRepository.GetContactbyUserId(chatConverstions.OwnerId);
                            if (GroupUser != null)
                            {
                                lblChatLastMessage.Text = "Created by " + GroupUser.screenName;
                            }
                            else
                            {
                                lblChatLastMessage.Text = "Created by me";
                            }
                        }

                        int countGroupUnread = GroupRepository.getGroupMessageUnRead((long)chatConverstions.GroupId);

                        if (countGroupUnread > 0)
                        {
                            lblMessageCount.Hidden = false;
                            lblMessageCount.SetTitle(countGroupUnread.ToString(), UIControlState.Normal);
                        }
                        else
                        {
                            lblMessageCount.Hidden = true;
                        }
                    }
                }
            }
        }
        public async void ButtonSendChatMessage(string sMessageText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sMessageText))
                {
                    var GroupTempSaveMessage = new GroupMessageResponseViewModel
                    {
                        GroupId     = contactViewModel.GroupId,
                        Message     = sMessageText.Trim(' ', '\n'),
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        SenderId    = CommonHelper.GetUserId(),
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };

                    var message   = GroupRepository.SaveGroupMessage(GroupTempSaveMessage, "Private");
                    var GroupSend = new GroupMessageRequestViewModel
                    {
                        GroupId          = contactViewModel.GroupId,
                        Message          = sMessageText.Trim(' ', '\n'),
                        Attachments      = lstAttachments ?? new List <AttachmentViewModel>(),
                        MobileDatabaseId = message.id
                    };


                    lstAttachments = new List <AttachmentViewModel>();
                    try
                    {
                        var result = await new GroupChatService().PostGroupMessageService(GroupSend);

                        if (result.Status == 1)
                        {
                            var GroupMessagelist = JsonConvert.DeserializeObject <GroupMessageResponseViewModel>(result.Response.ToString());
                            Console.WriteLine("posted successfully in grp");

                            var chatConversationResponce = ChatConversationRepository.GetConversationbyGroupId(GroupMessagelist.GroupId);
                            if (chatConversationResponce.success)
                            {
                                ChatConversationRepository.UpdateChatLastMessage(chatConversationResponce.chatConversation.id, GroupMessagelist.Message, GroupMessagelist.SenderProfileName);
                            }
                            var savedItem = GroupRepository.UpdateGroupMessage(GroupMessagelist);
                            await _objChatSignalRService.SendGroup(GroupMessagelist, GroupMessagelist.GroupId);

                            LoadLocalLatestMessages();
                        }
                        else
                        {
                            Console.WriteLine("post failed in grp");
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
        public async void ButtonSendChatMessage()
        {
            try
            {
                if (!string.IsNullOrEmpty(txtChatSendMessage.Text) || lstAttachments.Count > 0)
                {
                    txtChatSendMessage.Text = txtChatSendMessage.Text.Trim(' ', '\n');

                    var chatModel = new ChatMessageViewModel
                    {
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        ContactId   = contactId,
                        Message     = txtChatSendMessage.Text,
                        IsRead      = false,
                        IsRecieved  = false,
                        IsSend      = false,
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };


                    chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);
                    if (chatConversation != null)
                    {
                        var message = ChatMessageRepository.SaveChatMessage(chatModel, chatConversation.ChatId);
                        chatModel.MobiledatabaseId = message.id;
                        chatModel.ChatId           = chatConversation.ChatId;
                        chatModel.IsRead           = false;
                        chatModel.IsRecieved       = false;
                        chatModel.IsSend           = false;
                        mAdapter.add(message);
                        mAdapter.NotifyDataSetChanged();
                        mRecyclerView.ScrollToPosition(mAdapter.ItemCount - 1);
                        txtChatSendMessage.Text = "";
                    }
                    lstAttachments          = new List <AttachmentViewModel>();
                    txtChatSendMessage.Text = "";
                    try
                    {
                        var result = await new ChatService().PostChat(chatModel);

                        if (result.Status == 2 || result.Status == 1)
                        {
                            var ChatResponse = JsonConvert.DeserializeObject <PostChatResponseViewModel>(result.Response.ToString());

                            if (chatConversation == null)
                            {
                                ChatConversationRepository.SaveConverstionNewFromServer(ChatResponse.Chat);
                                chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);

                                ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                var savedMessages = ChatMessageRepository.SaveChatMessage(ChatResponse.ChatMessage, chatConversation.ChatId);

                                LoadLocalLatestMessages();
                                txtChatSendMessage.Text = "";
                                Console.WriteLine("CHAT POSTED : " + result);
                            }
                            else
                            {
                                chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId);

                                ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, "");

                                var savedMessages = ChatMessageRepository.updateChatMessage(ChatResponse.ChatMessage);
                                LoadLocalLatestMessages();
                                await _objChatSignalRService.Send(chatConversation.ContactId.ToString(), ChatResponse.ChatMessage);
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

                SetContentView(Resource.Layout.ChatMessagelayout);
                var requiredPermissions = new String[]
                {
                    Manifest.Permission.Internet,
                    Manifest.Permission.WriteExternalStorage,
                    Manifest.Permission.ReadExternalStorage,
                    Manifest.Permission.Camera,
                    Manifest.Permission.ReadContacts
                };
                ActivityCompat.RequestPermissions(this, requiredPermissions, REQUEST_LOCATION);

                var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.app_bar);
                SetSupportActionBar(toolbar);
                //SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                //SupportActionBar.SetHomeButtonEnabled(true);
                //SupportActionBar.SetDisplayUseLogoEnabled(true);
                ////SupportActionBar.SetIcon(Resource.Drawable.logo512_512);
                LinearLayout    li_toolbarDetails   = FindViewById <LinearLayout>(Resource.Id.li_toolbarDetails);
                CircleImageView IV_Userlogo         = FindViewById <CircleImageView>(Resource.Id.iv_customforUserlogo);
                CircleImageView _IVarrow_back_white = FindViewById <CircleImageView>(Resource.Id.iv_arrow_back_white);
                TextView        toolbar_title       = FindViewById <TextView>(Resource.Id.toolbar_title);
                li_toolbarDetails.Click   += Li_toolbarDetails_Click;
                IV_Userlogo.Click         += IV_Userlogo_Click;
                toolbar_title.Click       += Toolbar_title_Click;
                _IVarrow_back_white.Click += _IVarrow_back_white_Click;



                // Create your application here
                ContactObject = JsonConvert.DeserializeObject <ContactViewModel>(Intent.GetStringExtra("ContactObject"));
                if (ContactObject != null)
                {
                    ContactName        = ContactRepository.GetContactbyUserId(ContactObject.ContactId).name;
                    contactId          = ContactObject.ContactId;
                    toolbar_title.Text = ContactName;
                }

                if (ContactObject.ProfileImageUrl != null && ContactObject.ProfileImageUrl != "")
                {
                    Picasso.With(this)
                    .Load(ContactObject.ProfileImageUrl)
                    .Resize(100, 100)
                    .CenterCrop().Placeholder(Resource.Drawable.default_profile)
                    .Into(IV_Userlogo);
                }
                else
                {
                    IV_Userlogo.SetBackgroundResource(Resource.Drawable.default_profile);
                }

                txtChatSendMessage              = FindViewById <EditText>(Resource.Id.txtSendMessage);
                btnAttachment                   = (Button)FindViewById(Resource.Id.btnextra_msg);
                btnSendButton                   = FindViewById <Button>(Resource.Id.btnsend_msg);
                ButtonLayout                    = FindViewById <LinearLayout>(Resource.Id.linearLayout3);
                txtChatSendMessage.TextChanged += TxtChatSendMessage_TextChanged;

                mySwipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swiperefresh);
                var refreshListEvent = new SwipeRefreshLayoutPrivateMessage(this);
                mySwipeRefreshLayout.SetOnRefreshListener(refreshListEvent);
                refreshListEvent.LoadMoreEvent += RefreshListEvent_LoadMoreEvent;

                mRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
                if (mRecyclerView != null)
                {
                    mRecyclerView.HasFixedSize = true;
                    var layoutManager = new LinearLayoutManager(this);
                    mRecyclerView.SetLayoutManager(layoutManager);
                }

                imgCamera_msg = FindViewById <ImageView>(Resource.Id.imgCamera_msg);

                chatConversation = ChatConversationRepository.GetConversationbyContactId(ContactObject.ContactId);

                btnSendButton.Click += btnSendButton_Click;
                btnAttachment.Click += BtnAttachment_Click;
                imgCamera_msg.Click += ImgCamera_msg_Click;
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }