private static void UpdateLastIdMessage(List <MessageData> chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages)
                {
                    var typeModel = MainWindowActivity.MAdapter.GetTypeModel(messageInfo);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.PageId, messageInfo, typeModel);


                    message.ModelType = typeModel;

                    var checker = MainWindowActivity?.MAdapter.DifferList?.FirstOrDefault(a => a.MesData.Id == message.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData = message;

                        if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        {
                            var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.ChatList.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GlobalContext.LastChatTab.MAdapter.ChatList.FirstOrDefault(x => x.PageId == message.PageId));
                                if (index > -1)
                                {
                                    if (typeModel == MessageModelType.RightGif)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendGifFile);
                                    }
                                    else if (typeModel == MessageModelType.RightText)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage);
                                    }
                                    else if (typeModel == MessageModelType.RightSticker)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile);
                                    }
                                    else if (typeModel == MessageModelType.RightContact)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber);
                                    }
                                    else if (typeModel == MessageModelType.RightFile)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendFile);
                                    }
                                    else if (typeModel == MessageModelType.RightVideo)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile);
                                    }
                                    else if (typeModel == MessageModelType.RightImage)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendImageFile);
                                    }
                                    else if (typeModel == MessageModelType.RightAudio)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile);
                                    }

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab?.MAdapter?.ChatList.Move(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });
                                }
                            }
                            else
                            {
                                GlobalContext?.RunOnUiThread(() =>
                                {
                                    try
                                    {
                                        if (PageData != null)
                                        {
                                            GlobalContext?.LastChatTab.MAdapter.ChatList.Insert(0, PageData);
                                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(PageData));
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                });
                            }
                        }
                        else
                        {
                            var updaterUser = GlobalContext?.LastPageChatsTab?.MAdapter?.LastPageList.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastPageChatsTab.MAdapter.LastPageList.IndexOf(GlobalContext.LastPageChatsTab.MAdapter.LastPageList.FirstOrDefault(x => x.PageId == message.PageId));
                                if (index > -1)
                                {
                                    if (typeModel == MessageModelType.RightGif)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendGifFile);
                                    }
                                    else if (typeModel == MessageModelType.RightText)
                                    {
                                        updaterUser.LastMessage.Text = !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage);
                                    }
                                    else if (typeModel == MessageModelType.RightSticker)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile);
                                    }
                                    else if (typeModel == MessageModelType.RightContact)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber);
                                    }
                                    else if (typeModel == MessageModelType.RightFile)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendFile);
                                    }
                                    else if (typeModel == MessageModelType.RightVideo)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile);
                                    }
                                    else if (typeModel == MessageModelType.RightImage)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendImageFile);
                                    }
                                    else if (typeModel == MessageModelType.RightAudio)
                                    {
                                        updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile);
                                    }

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastPageChatsTab?.MAdapter?.LastPageList.Move(index, 0);
                                            GlobalContext?.LastPageChatsTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastPageChatsTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });
                                }
                            }
                            else
                            {
                                GlobalContext?.RunOnUiThread(() =>
                                {
                                    try
                                    {
                                        if (DataProfilePage != null)
                                        {
                                            GlobalContext?.LastPageChatsTab?.MAdapter.LastPageList.Insert(0, DataProfilePage);
                                            GlobalContext?.LastPageChatsTab?.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastPageChatsTab?.MRecycler.ScrollToPosition(GlobalContext.LastPageChatsTab.MAdapter.LastPageList.IndexOf(DataProfilePage));
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                });
                            }
                        }

                        GlobalContext?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightVideo)
                                {
                                    MainWindowActivity.Update_One_Messeges(checker.MesData);
                                }

                                if (SettingsPrefFragment.SSoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        });
                    }

                    PageData        = null;
                    DataProfilePage = null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #2
0
        public static void UpdateLastIdMessage(SendMessageObject chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages.MessageData)
                {
                    MessageData m = new MessageData
                    {
                        Id             = messageInfo.Id,
                        FromId         = messageInfo.FromId,
                        GroupId        = messageInfo.GroupId,
                        ToId           = messageInfo.ToId,
                        Text           = messageInfo.Text,
                        Media          = messageInfo.Media,
                        MediaFileName  = messageInfo.MediaFileName,
                        MediaFileNames = messageInfo.MediaFileNames,
                        Time           = messageInfo.Time,
                        Seen           = messageInfo.Seen,
                        DeletedOne     = messageInfo.DeletedOne,
                        DeletedTwo     = messageInfo.DeletedTwo,
                        SentPush       = messageInfo.SentPush,
                        NotificationId = messageInfo.NotificationId,
                        TypeTwo        = messageInfo.TypeTwo,
                        Stickers       = messageInfo.Stickers,
                        TimeText       = messageInfo.TimeText,
                        Position       = messageInfo.Position,
                        ModelType      = messageInfo.ModelType,
                        FileSize       = messageInfo.FileSize,
                        MediaDuration  = messageInfo.MediaDuration,
                        MediaIsPlaying = messageInfo.MediaIsPlaying,
                        ContactNumber  = messageInfo.ContactNumber,
                        ContactName    = messageInfo.ContactName,
                        ProductId      = messageInfo.ProductId,
                        MessageUser    = messageInfo.MessageUser,
                        Product        = messageInfo.Product,
                        MessageHashId  = messageInfo.MessageHashId,
                        Lat            = messageInfo.Lat,
                        Lng            = messageInfo.Lng,
                        SendFile       = false,
                    };

                    var typeModel = Holders.GetTypeModel(m);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.ToId, m, typeModel, true);
                    message.ModelType = typeModel;

                    AdapterModelsClassMessage checker = WindowActivity?.MAdapter?.DifferList?.FirstOrDefault(a => a.MesData.Id == messageInfo.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData  = message;
                        checker.Id       = Java.Lang.Long.ParseLong(message.Id);
                        checker.TypeView = typeModel;

                        checker.MesData.Id             = message.Id;
                        checker.MesData.FromId         = message.FromId;
                        checker.MesData.GroupId        = message.GroupId;
                        checker.MesData.ToId           = message.ToId;
                        checker.MesData.Text           = message.Text;
                        checker.MesData.Media          = message.Media;
                        checker.MesData.MediaFileName  = message.MediaFileName;
                        checker.MesData.MediaFileNames = message.MediaFileNames;
                        checker.MesData.Time           = message.Time;
                        checker.MesData.Seen           = message.Seen;
                        checker.MesData.DeletedOne     = message.DeletedOne;
                        checker.MesData.DeletedTwo     = message.DeletedTwo;
                        checker.MesData.SentPush       = message.SentPush;
                        checker.MesData.NotificationId = message.NotificationId;
                        checker.MesData.TypeTwo        = message.TypeTwo;
                        checker.MesData.Stickers       = message.Stickers;
                        checker.MesData.TimeText       = message.TimeText;
                        checker.MesData.Position       = message.Position;
                        checker.MesData.ModelType      = message.ModelType;
                        checker.MesData.FileSize       = message.FileSize;
                        checker.MesData.MediaDuration  = message.MediaDuration;
                        checker.MesData.MediaIsPlaying = message.MediaIsPlaying;
                        checker.MesData.ContactNumber  = message.ContactNumber;
                        checker.MesData.ContactName    = message.ContactName;
                        checker.MesData.ProductId      = message.ProductId;
                        checker.MesData.MessageUser    = message.MessageUser;
                        checker.MesData.Product        = message.Product;
                        checker.MesData.MessageHashId  = message.MessageHashId;
                        checker.MesData.Lat            = message.Lat;
                        checker.MesData.Lng            = message.Lng;
                        checker.MesData.SendFile       = false;

                        #region LastChat

                        //if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        //{
                        //    var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.LastChatsList?.FirstOrDefault(a => a.LastChat?.UserId == message.ToId);
                        //    if (updaterUser?.LastChat != null)
                        //    {
                        //        var index = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(GlobalContext.LastChatTab.MAdapter.LastChatsList.FirstOrDefault(x => x.LastChat?.UserId == message.ToId));
                        //        if (index > -1)
                        //        {
                        //            updaterUser.LastChat.LastMessage.LastMessageClass.Text = typeModel switch
                        //            {
                        //                MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                        //                MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                        //                MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                        //                MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                        //                MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                        //                MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                        //                MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                        //                MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                        //                MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                        //                _ => updaterUser.LastChat?.LastMessage.LastMessageClass.Text
                        //            };

                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!updaterUser.LastChat.IsPin)
                        //                    {
                        //                        var checkPin = GlobalContext.LastChatTab.MAdapter.LastChatsList.LastOrDefault(o => o.LastChat != null && o.LastChat.IsPin);
                        //                        if (checkPin != null)
                        //                        {
                        //                            var toIndex = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(checkPin) + 1;
                        //                            GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, toIndex);
                        //                            GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, toIndex);
                        //                        }
                        //                        else
                        //                        {
                        //                            if (ListUtils.FriendRequestsList.Count > 0)
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, 1);
                        //                                GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, 1);
                        //                            }
                        //                            else
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter?.LastChatsList.Move(index, 0);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });

                        //            SqLiteDatabase dbSqLite = new SqLiteDatabase();
                        //            //Update All data users to database
                        //            dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection<ChatObject> { updaterUser?.LastChat });

                        //        }
                        //    }
                        //    else
                        //    {
                        //        //insert new user
                        //        var data = ConvertData(checker.MesData);
                        //        if (data != null)
                        //        {
                        //            //wael change after add in api
                        //            data.IsMute = WoWonderTools.CheckMute(data.UserId, "user");
                        //            data.IsPin = WoWonderTools.CheckPin(data.UserId, "user");
                        //            var archiveObject = WoWonderTools.CheckArchive(data.UserId, "user");
                        //            data.IsArchive = archiveObject != null;


                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!data.IsArchive)
                        //                    {
                        //                        if (ListUtils.FriendRequestsList.Count > 0)
                        //                        {
                        //                            GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(0, new Classes.LastChatsClass()
                        //                            {
                        //                                LastChat = data,
                        //                                Type = Classes.ItemType.LastChatNewV
                        //                            });
                        //                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                        //                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(0);
                        //                        }
                        //                        else
                        //                        {
                        //                            GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(1, new Classes.LastChatsClass()
                        //                            {
                        //                                LastChat = data,
                        //                                Type = Classes.ItemType.LastChatNewV
                        //                            });
                        //                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(1);
                        //                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(1);
                        //                        }
                        //                    }
                        //                    else
                        //                    {
                        //                        if (archiveObject != null)
                        //                        {
                        //                            if (archiveObject.LastMessagesUser.LastMessage?.Id != data.LastMessage.LastMessageClass?.Id)
                        //                            {
                        //                                if (ListUtils.FriendRequestsList.Count > 0)
                        //                                {
                        //                                    GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(0, new Classes.LastChatsClass()
                        //                                    {
                        //                                        LastChat = data,
                        //                                        Type = Classes.ItemType.LastChatNewV
                        //                                    });
                        //                                    GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                        //                                    GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(0);
                        //                                }
                        //                                else
                        //                                {
                        //                                    GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(1, new Classes.LastChatsClass()
                        //                                    {
                        //                                        LastChat = data,
                        //                                        Type = Classes.ItemType.LastChatNewV
                        //                                    });
                        //                                    GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(1);
                        //                                    GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(1);
                        //                                }

                        //                                ListUtils.ArchiveList.Remove(archiveObject);

                        //                                var sqLiteDatabase = new SqLiteDatabase();
                        //                                sqLiteDatabase.InsertORDelete_Archive(archiveObject);
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });

                        //            //Update All data users to database
                        //            //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                        //            //{
                        //            //    data
                        //            //});
                        //        }
                        //    }
                        //}
                        //else
                        //{
                        //    var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.LastChatsList?.FirstOrDefault(a => a.LastMessagesUser?.UserId == message.ToId);
                        //    if (updaterUser?.LastMessagesUser != null)
                        //    {
                        //        var index = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(GlobalContext.LastChatTab.MAdapter.LastChatsList.FirstOrDefault(x => x.LastMessagesUser?.UserId == message.ToId));
                        //        if (index > -1)
                        //        {
                        //            updaterUser.LastMessagesUser.LastMessage.Text = typeModel switch
                        //            {
                        //                MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                        //                MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                        //                MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                        //                MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                        //                MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                        //                MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                        //                MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                        //                MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                        //                MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                        //                _ => updaterUser.LastMessagesUser?.LastMessage.Text
                        //            };

                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!updaterUser.LastMessagesUser.IsPin)
                        //                    {
                        //                        var checkPin = GlobalContext?.LastChatTab?.MAdapter.LastChatsList.LastOrDefault(o => o.LastMessagesUser != null && o.LastMessagesUser.IsPin);
                        //                        if (checkPin != null)
                        //                        {
                        //                            var toIndex = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(checkPin) + 1;
                        //                            GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, toIndex);
                        //                            GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, toIndex);
                        //                        }
                        //                        else
                        //                        {
                        //                            if (ListUtils.FriendRequestsList.Count > 0)
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, 1);
                        //                                GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, 1);
                        //                            }
                        //                            else
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, 0);
                        //                                GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, 0);
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });
                        //            SqLiteDatabase dbSqLite = new SqLiteDatabase();
                        //            //Update All data users to database
                        //            dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection<GetUsersListObject.User> { updaterUser.LastMessagesUser });
                        //        }
                        //    }
                        //    else
                        //    {
                        //        //insert new user
                        //        var data = ConvertDataChat(checker.MesData);
                        //        if (data != null)
                        //        {
                        //            //wael change after add in api
                        //            data.IsMute = WoWonderTools.CheckMute(data.UserId, "user");
                        //            data.IsPin = WoWonderTools.CheckPin(data.UserId, "user");
                        //            var archiveObject = WoWonderTools.CheckArchive(data.UserId, "user");
                        //            data.IsArchive = archiveObject != null;

                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!data.IsArchive)
                        //                    {
                        //                        if (ListUtils.FriendRequestsList.Count > 0)
                        //                        {
                        //                            GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Insert(0, new Classes.LastChatsClass()
                        //                            {
                        //                                LastMessagesUser = data,
                        //                                Type = Classes.ItemType.LastChatOldV
                        //                            });
                        //                            GlobalContext?.LastChatTab?.MAdapter.NotifyItemInserted(0);
                        //                            GlobalContext?.LastChatTab?.MRecycler.ScrollToPosition(0);
                        //                        }
                        //                        else
                        //                        {
                        //                            GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Insert(1, new Classes.LastChatsClass()
                        //                            {
                        //                                LastMessagesUser = data,
                        //                                Type = Classes.ItemType.LastChatOldV
                        //                            });
                        //                            GlobalContext?.LastChatTab?.MAdapter.NotifyItemInserted(1);
                        //                            GlobalContext?.LastChatTab?.MRecycler.ScrollToPosition(1);
                        //                        }
                        //                    }
                        //                    else
                        //                    {
                        //                        if (archiveObject != null)
                        //                        {
                        //                            if (archiveObject.LastMessagesUser.LastMessage?.Id != data.LastMessage.Id)
                        //                            {
                        //                                if (ListUtils.FriendRequestsList.Count > 0)
                        //                                {
                        //                                    GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Insert(0, new Classes.LastChatsClass()
                        //                                    {
                        //                                        LastMessagesUser = data,
                        //                                        Type = Classes.ItemType.LastChatOldV
                        //                                    });
                        //                                    GlobalContext?.LastChatTab?.MAdapter.NotifyItemInserted(0);
                        //                                    GlobalContext?.LastChatTab?.MRecycler.ScrollToPosition(0);
                        //                                }
                        //                                else
                        //                                {
                        //                                    GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Insert(1, new Classes.LastChatsClass()
                        //                                    {
                        //                                        LastMessagesUser = data,
                        //                                        Type = Classes.ItemType.LastChatOldV
                        //                                    });
                        //                                    GlobalContext?.LastChatTab?.MAdapter.NotifyItemInserted(1);
                        //                                    GlobalContext?.LastChatTab?.MRecycler.ScrollToPosition(1);
                        //                                }

                        //                                ListUtils.ArchiveList.Remove(archiveObject);

                        //                                var sqLiteDatabase = new SqLiteDatabase();
                        //                                sqLiteDatabase.InsertORDelete_Archive(archiveObject);
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });

                        //            //Update All data users to database
                        //            //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                        //            //{
                        //            //    data
                        //            //});
                        //        }
                        //    }
                        //}

                        #endregion

                        //checker.Media = media;
                        //Update All data users to database
                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_Or_Update_To_one_MessagesTable(checker.MesData);

                        GlobalContext.Activity?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                //if (message.ModelType == MessageModelType.RightSticker || message.ModelType == MessageModelType.RightImage || message.ModelType == MessageModelType.RightMap || message.ModelType == MessageModelType.RightVideo)
                                WindowActivity?.Update_One_Messages(checker.MesData);

                                if (UserDetails.SoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Methods.DisplayReportResultTrack(e);
                            }
                        });
                    }
                }

                DataUser     = null;
                DataUserChat = null;
                UserData     = null;
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        private static void UpdateLastIdMessage(List <MessageData> chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages)
                {
                    var typeModel = Holders.GetTypeModel(messageInfo);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.GroupId, messageInfo, typeModel);

                    message.ModelType = typeModel;
                    message.SendFile  = false;

                    var checker = MainWindowActivity?.MAdapter.DifferList?.FirstOrDefault(a => a.MesData.Id == message.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData  = message;
                        checker.Id       = Java.Lang.Long.ParseLong(message.Id);
                        checker.TypeView = typeModel;

                        checker.MesData.Id             = message.Id;
                        checker.MesData.FromId         = message.FromId;
                        checker.MesData.GroupId        = message.GroupId;
                        checker.MesData.ToId           = message.ToId;
                        checker.MesData.Text           = message.Text;
                        checker.MesData.Media          = message.Media;
                        checker.MesData.MediaFileName  = message.MediaFileName;
                        checker.MesData.MediaFileNames = message.MediaFileNames;
                        checker.MesData.Time           = message.Time;
                        checker.MesData.Seen           = message.Seen;
                        checker.MesData.DeletedOne     = message.DeletedOne;
                        checker.MesData.DeletedTwo     = message.DeletedTwo;
                        checker.MesData.SentPush       = message.SentPush;
                        checker.MesData.NotificationId = message.NotificationId;
                        checker.MesData.TypeTwo        = message.TypeTwo;
                        checker.MesData.Stickers       = message.Stickers;
                        checker.MesData.TimeText       = message.TimeText;
                        checker.MesData.Position       = message.Position;
                        checker.MesData.ModelType      = message.ModelType;
                        checker.MesData.FileSize       = message.FileSize;
                        checker.MesData.MediaDuration  = message.MediaDuration;
                        checker.MesData.MediaIsPlaying = message.MediaIsPlaying;
                        checker.MesData.ContactNumber  = message.ContactNumber;
                        checker.MesData.ContactName    = message.ContactName;
                        checker.MesData.ProductId      = message.ProductId;
                        checker.MesData.MessageUser    = message.MessageUser;
                        checker.MesData.Product        = message.Product;
                        checker.MesData.MessageHashId  = message.MessageHashId;
                        checker.MesData.Lat            = message.Lat;
                        checker.MesData.Lng            = message.Lng;
                        checker.MesData.SendFile       = false;

                        if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        {
                            var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.ChatList.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GlobalContext.LastChatTab.MAdapter.ChatList.FirstOrDefault(x => x.GroupId == message.GroupId));
                                if (index > -1)
                                {
                                    if (typeModel == MessageModelType.RightGif)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendGifFile);
                                    }
                                    else if (typeModel == MessageModelType.RightText)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage);
                                    }
                                    else if (typeModel == MessageModelType.RightSticker)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile);
                                    }
                                    else if (typeModel == MessageModelType.RightContact)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber);
                                    }
                                    else if (typeModel == MessageModelType.RightFile)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendFile);
                                    }
                                    else if (typeModel == MessageModelType.RightVideo)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile);
                                    }
                                    else if (typeModel == MessageModelType.RightImage)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendImageFile);
                                    }
                                    else if (typeModel == MessageModelType.RightAudio)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile);
                                    }
                                    else if (typeModel == MessageModelType.RightMap)
                                    {
                                        updaterUser.LastMessage.LastMessageClass.Text = GlobalContext?.GetText(Resource.String.Lbl_SendLocationFile);
                                    }

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab?.MAdapter?.ChatList.Move(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });
                                }
                            }
                            else
                            {
                                GlobalContext?.RunOnUiThread(() =>
                                {
                                    try
                                    {
                                        if (GroupData != null)
                                        {
                                            GlobalContext?.LastChatTab.MAdapter.ChatList.Insert(0, GroupData);
                                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GroupData));
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                });
                            }
                        }
                        else
                        {
                            var updaterUser = GlobalContext?.LastGroupChatsTab?.MAdapter?.LastGroupList.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastGroupChatsTab.MAdapter.LastGroupList.IndexOf(GlobalContext.LastGroupChatsTab.MAdapter.LastGroupList.FirstOrDefault(x => x.GroupId == message.GroupId));
                                if (index > -1)
                                {
                                    //if (typeModel == MessageModelType.RightGif)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendGifFile);
                                    //else if (typeModel == MessageModelType.RightText)
                                    //    updaterUser.LastMessage.Text = !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage);
                                    //else if (typeModel == MessageModelType.RightSticker)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile);
                                    //else if (typeModel == MessageModelType.RightContact)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber);
                                    //else if (typeModel == MessageModelType.RightFile)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendFile);
                                    //else if (typeModel == MessageModelType.RightVideo)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile);
                                    //else if (typeModel == MessageModelType.RightImage)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendImageFile);
                                    //else if (typeModel == MessageModelType.RightAudio)
                                    //    updaterUser.LastMessage.Text = GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile);

                                    //GlobalContext.RunOnUiThread(() =>
                                    //{
                                    //    try
                                    //    {
                                    //        GlobalContext?.LastGroupChatsTab?.MAdapter?.LastGroupList.Move(index, 0);
                                    //        GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemMoved(index, 0);
                                    //        GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                    //    }
                                    //    catch (Exception e)
                                    //    {
                                    //        Console.WriteLine(e);
                                    //    }
                                    //});
                                }
                            }
                            else
                            {
                                //GlobalContext?.RunOnUiThread(() =>
                                //{
                                //    try
                                //    {
                                //        GlobalContext?.LastGroupChatsTab?.MAdapter.LastGroupList.Insert(0, GroupData);
                                //        GlobalContext?.LastGroupChatsTab?.MAdapter.NotifyItemInserted(0);
                                //        GlobalContext?.LastGroupChatsTab?.MRecycler.ScrollToPosition(GlobalContext.LastGroupChatsTab.MAdapter.LastGroupList.IndexOf(GroupData));
                                //    }
                                //    catch (Exception e)
                                //    {
                                //        Console.WriteLine(e);
                                //    }
                                //});
                            }
                        }

                        GlobalContext?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightMap || message.ModelType != MessageModelType.RightVideo)
                                {
                                    MainWindowActivity.Update_One_Messeges(checker.MesData);
                                }

                                if (SettingsPrefFragment.SSoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        });
                    }

                    GroupData = null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private static void UpdateLastIdMessage(List <MessageData> chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages)
                {
                    var typeModel = Holders.GetTypeModel(messageInfo);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.GroupId, messageInfo, typeModel);

                    message.ModelType = typeModel;
                    message.SendFile  = false;

                    var checker = MainWindowActivity?.MAdapter.DifferList?.FirstOrDefault(a => a.MesData.Id == message.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData  = message;
                        checker.Id       = Java.Lang.Long.ParseLong(message.Id);
                        checker.TypeView = typeModel;

                        checker.MesData.Id             = message.Id;
                        checker.MesData.FromId         = message.FromId;
                        checker.MesData.GroupId        = message.GroupId;
                        checker.MesData.ToId           = message.ToId;
                        checker.MesData.Text           = message.Text;
                        checker.MesData.Media          = message.Media;
                        checker.MesData.MediaFileName  = message.MediaFileName;
                        checker.MesData.MediaFileNames = message.MediaFileNames;
                        checker.MesData.Time           = message.Time;
                        checker.MesData.Seen           = message.Seen;
                        checker.MesData.DeletedOne     = message.DeletedOne;
                        checker.MesData.DeletedTwo     = message.DeletedTwo;
                        checker.MesData.SentPush       = message.SentPush;
                        checker.MesData.NotificationId = message.NotificationId;
                        checker.MesData.TypeTwo        = message.TypeTwo;
                        checker.MesData.Stickers       = message.Stickers;
                        checker.MesData.TimeText       = message.TimeText;
                        checker.MesData.Position       = message.Position;
                        checker.MesData.ModelType      = message.ModelType;
                        checker.MesData.FileSize       = message.FileSize;
                        checker.MesData.MediaDuration  = message.MediaDuration;
                        checker.MesData.MediaIsPlaying = message.MediaIsPlaying;
                        checker.MesData.ContactNumber  = message.ContactNumber;
                        checker.MesData.ContactName    = message.ContactName;
                        checker.MesData.ProductId      = message.ProductId;
                        checker.MesData.MessageUser    = message.MessageUser;
                        checker.MesData.Product        = message.Product;
                        checker.MesData.MessageHashId  = message.MessageHashId;
                        checker.MesData.Lat            = message.Lat;
                        checker.MesData.Lng            = message.Lng;
                        checker.MesData.SendFile       = false;

                        #region LastChat

                        //if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        //{
                        //    var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.LastChatsList.FirstOrDefault(a => a.LastChat?.UserId == message.ToId);
                        //    if (updaterUser != null)
                        //    {
                        //        var index = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(GlobalContext.LastChatTab.MAdapter.LastChatsList.FirstOrDefault(x => x.LastChat?.GroupId == message.GroupId));
                        //        if (index > -1)
                        //        {
                        //            updaterUser.LastChat.LastMessage.LastMessageClass.Text = typeModel switch
                        //            {
                        //                MessageModelType.RightGif => GlobalContext?.GetText(Resource.String.Lbl_SendGifFile),
                        //                MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage),
                        //                MessageModelType.RightSticker => GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile),
                        //                MessageModelType.RightContact => GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber),
                        //                MessageModelType.RightFile => GlobalContext?.GetText(Resource.String.Lbl_SendFile),
                        //                MessageModelType.RightVideo => GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile),
                        //                MessageModelType.RightImage => GlobalContext?.GetText(Resource.String.Lbl_SendImageFile),
                        //                MessageModelType.RightAudio => GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile),
                        //                MessageModelType.RightMap => GlobalContext?.GetText(Resource.String.Lbl_SendLocationFile),
                        //                _ => updaterUser.LastChat.LastMessage.LastMessageClass.Text
                        //            };

                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!updaterUser.LastMessagesUser.IsPin)
                        //                    {
                        //                        var checkPin = GlobalContext?.LastChatTab?.MAdapter.LastChatsList.LastOrDefault(o => o.LastChat != null && o.LastChat.IsPin);
                        //                        if (checkPin != null)
                        //                        {
                        //                            var toIndex = GlobalContext.LastChatTab.MAdapter.LastChatsList.IndexOf(checkPin) + 1;
                        //                            GlobalContext?.LastChatTab?.MAdapter.LastChatsList.Move(index, toIndex);
                        //                            GlobalContext?.LastChatTab?.MAdapter.NotifyItemMoved(index, toIndex);
                        //                        }
                        //                        else
                        //                        {
                        //                            if (ListUtils.GroupRequestsList.Count > 0)
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter?.LastChatsList.Move(index, 0);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                        //                            }
                        //                            else
                        //                            {
                        //                                GlobalContext?.LastChatTab?.MAdapter?.LastChatsList.Move(index, 1);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 1);
                        //                                GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });
                        //        }
                        //    }
                        //    else
                        //    {
                        //        GlobalContext?.RunOnUiThread(() =>
                        //        {
                        //            try
                        //            {
                        //                if (GroupData != null)
                        //                {
                        //                    if (ListUtils.GroupRequestsList.Count > 0)
                        //                    {
                        //                        GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(0, new Classes.LastChatsClass()
                        //                        {
                        //                            LastChat = GroupData,
                        //                            Type = Classes.ItemType.LastChatNewV
                        //                        });

                        //                        GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                        //                        GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(0);
                        //                    }
                        //                    else
                        //                    {
                        //                        GlobalContext?.LastChatTab.MAdapter.LastChatsList.Insert(1, new Classes.LastChatsClass()
                        //                        {
                        //                            LastChat = GroupData,
                        //                            Type = Classes.ItemType.LastChatNewV
                        //                        });

                        //                        GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(1);
                        //                        GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(1);
                        //                    }
                        //                }
                        //            }
                        //            catch (Exception e)
                        //            {
                        //                Methods.DisplayReportResultTrack(e);
                        //            }
                        //        });
                        //    }
                        //}
                        //else
                        //{
                        //    var updaterUser = GlobalContext?.LastGroupChatsTab?.MAdapter?.LastChatsList.FirstOrDefault(a => a.LastChat?.UserId == message.ToId);
                        //    if (updaterUser != null)
                        //    {
                        //        var index = GlobalContext.LastGroupChatsTab.MAdapter.LastChatsList.IndexOf(GlobalContext.LastGroupChatsTab.MAdapter.LastChatsList.FirstOrDefault(x => x.LastChat?.GroupId == message.GroupId));
                        //        if (index > -1)
                        //        {
                        //            updaterUser.LastChat.LastMessage.LastMessageClass.Text = typeModel switch
                        //            {
                        //                MessageModelType.RightGif => GlobalContext?.GetText(Resource.String.Lbl_SendGifFile),
                        //                MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : GlobalContext?.GetText(Resource.String.Lbl_SendMessage),
                        //                MessageModelType.RightSticker => GlobalContext?.GetText(Resource.String.Lbl_SendStickerFile),
                        //                MessageModelType.RightContact => GlobalContext?.GetText(Resource.String.Lbl_SendContactnumber),
                        //                MessageModelType.RightFile => GlobalContext?.GetText(Resource.String.Lbl_SendFile),
                        //                MessageModelType.RightVideo => GlobalContext?.GetText(Resource.String.Lbl_SendVideoFile),
                        //                MessageModelType.RightImage => GlobalContext?.GetText(Resource.String.Lbl_SendImageFile),
                        //                MessageModelType.RightAudio => GlobalContext?.GetText(Resource.String.Lbl_SendAudioFile),
                        //                MessageModelType.RightMap => GlobalContext?.GetText(Resource.String.Lbl_SendLocationFile),
                        //                _ => updaterUser.LastChat.LastMessage.LastMessageClass.Text
                        //            };

                        //            GlobalContext?.RunOnUiThread(() =>
                        //            {
                        //                try
                        //                {
                        //                    if (!updaterUser.LastMessagesUser.IsPin)
                        //                    {
                        //                        var checkPin = GlobalContext?.LastGroupChatsTab?.MAdapter.LastChatsList.LastOrDefault(o => o.LastChat != null && o.LastChat.IsPin);
                        //                        if (checkPin != null)
                        //                        {
                        //                            var toIndex = GlobalContext.LastGroupChatsTab.MAdapter.LastChatsList.IndexOf(checkPin) + 1;
                        //                            GlobalContext?.LastGroupChatsTab?.MAdapter.LastChatsList.Move(index, toIndex);
                        //                            GlobalContext?.LastGroupChatsTab?.MAdapter.NotifyItemMoved(index, toIndex);
                        //                        }
                        //                        else
                        //                        {
                        //                            if (ListUtils.GroupRequestsList.Count > 0)
                        //                            {
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.LastChatsList.Move(index, 0);
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemMoved(index, 0);
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                        //                            }
                        //                            else
                        //                            {
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.LastChatsList.Move(index, 1);
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemMoved(index, 1);
                        //                                GlobalContext?.LastGroupChatsTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                        //                            }
                        //                        }
                        //                    }
                        //                }
                        //                catch (Exception e)
                        //                {
                        //                    Methods.DisplayReportResultTrack(e);
                        //                }
                        //            });
                        //        }
                        //    }
                        //    else
                        //    {
                        //        //GlobalContext?.RunOnUiThread(() =>
                        //        //{
                        //        //    try
                        //        //    {
                        //        //        GlobalContext?.LastGroupChatsTab?.MAdapter.LastGroupList.Insert(0, GroupData);
                        //        //        GlobalContext?.LastGroupChatsTab?.MAdapter.NotifyItemInserted(0);
                        //        //        GlobalContext?.LastGroupChatsTab?.MRecycler.ScrollToPosition(GlobalContext.LastGroupChatsTab.MAdapter.LastGroupList.IndexOf(GroupData));
                        //        //    }
                        //        //    catch (Exception e)
                        //        //    {
                        //        //        Methods.DisplayReportResultTrack(e);
                        //        //    }
                        //        //});
                        //    }
                        //}

                        #endregion

                        GlobalContext.Activity?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightMap || message.ModelType != MessageModelType.RightVideo)
                                {
                                    MainWindowActivity.Update_One_Messages(checker.MesData);
                                }

                                if (UserDetails.SoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Methods.DisplayReportResultTrack(e);
                            }
                        });
                    }

                    GroupData = null;
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Пример #5
0
        public static void UpdateLastIdMessage(SendMessageObject chatMessages)
        {
            try
            {
                foreach (var messageInfo in chatMessages.MessageData)
                {
                    MessageData m = new MessageData
                    {
                        Id             = messageInfo.Id,
                        FromId         = messageInfo.FromId,
                        GroupId        = messageInfo.GroupId,
                        ToId           = messageInfo.ToId,
                        Text           = messageInfo.Text,
                        Media          = messageInfo.Media,
                        MediaFileName  = messageInfo.MediaFileName,
                        MediaFileNames = messageInfo.MediaFileNames,
                        Time           = messageInfo.Time,
                        Seen           = messageInfo.Seen,
                        DeletedOne     = messageInfo.DeletedOne,
                        DeletedTwo     = messageInfo.DeletedTwo,
                        SentPush       = messageInfo.SentPush,
                        NotificationId = messageInfo.NotificationId,
                        TypeTwo        = messageInfo.TypeTwo,
                        Stickers       = messageInfo.Stickers,
                        TimeText       = messageInfo.TimeText,
                        Position       = messageInfo.Position,
                        ModelType      = messageInfo.ModelType,
                        FileSize       = messageInfo.FileSize,
                        MediaDuration  = messageInfo.MediaDuration,
                        MediaIsPlaying = messageInfo.MediaIsPlaying,
                        ContactNumber  = messageInfo.ContactNumber,
                        ContactName    = messageInfo.ContactName,
                        ProductId      = messageInfo.ProductId,
                        MessageUser    = messageInfo.MessageUser,
                        Product        = messageInfo.Product,
                        MessageHashId  = messageInfo.MessageHashId,
                        Lat            = messageInfo.Lat,
                        Lng            = messageInfo.Lng,
                        SendFile       = false,
                    };

                    var typeModel = Holders.GetTypeModel(m);
                    if (typeModel == MessageModelType.None)
                    {
                        continue;
                    }

                    var message = WoWonderTools.MessageFilter(messageInfo.ToId, m, typeModel, true);
                    message.ModelType = typeModel;

                    AdapterModelsClassUser checker = WindowActivity?.MAdapter?.DifferList?.FirstOrDefault(a => a.MesData.Id == messageInfo.MessageHashId);
                    if (checker != null)
                    {
                        //checker.TypeView = typeModel;
                        checker.MesData  = message;
                        checker.Id       = Java.Lang.Long.ParseLong(message.Id);
                        checker.TypeView = typeModel;

                        checker.MesData.Id             = message.Id;
                        checker.MesData.FromId         = message.FromId;
                        checker.MesData.GroupId        = message.GroupId;
                        checker.MesData.ToId           = message.ToId;
                        checker.MesData.Text           = message.Text;
                        checker.MesData.Media          = message.Media;
                        checker.MesData.MediaFileName  = message.MediaFileName;
                        checker.MesData.MediaFileNames = message.MediaFileNames;
                        checker.MesData.Time           = message.Time;
                        checker.MesData.Seen           = message.Seen;
                        checker.MesData.DeletedOne     = message.DeletedOne;
                        checker.MesData.DeletedTwo     = message.DeletedTwo;
                        checker.MesData.SentPush       = message.SentPush;
                        checker.MesData.NotificationId = message.NotificationId;
                        checker.MesData.TypeTwo        = message.TypeTwo;
                        checker.MesData.Stickers       = message.Stickers;
                        checker.MesData.TimeText       = message.TimeText;
                        checker.MesData.Position       = message.Position;
                        checker.MesData.ModelType      = message.ModelType;
                        checker.MesData.FileSize       = message.FileSize;
                        checker.MesData.MediaDuration  = message.MediaDuration;
                        checker.MesData.MediaIsPlaying = message.MediaIsPlaying;
                        checker.MesData.ContactNumber  = message.ContactNumber;
                        checker.MesData.ContactName    = message.ContactName;
                        checker.MesData.ProductId      = message.ProductId;
                        checker.MesData.MessageUser    = message.MessageUser;
                        checker.MesData.Product        = message.Product;
                        checker.MesData.MessageHashId  = message.MessageHashId;
                        checker.MesData.Lat            = message.Lat;
                        checker.MesData.Lng            = message.Lng;
                        checker.MesData.SendFile       = false;

                        if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                        {
                            var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.ChatList?.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GlobalContext.LastChatTab.MAdapter.ChatList.FirstOrDefault(x => x.UserId == message.ToId));
                                if (index > -1)
                                {
                                    updaterUser.LastMessage.LastMessageClass.Text = typeModel switch
                                    {
                                        MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                                        MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                                        MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                                        MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                                        MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                                        MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                                        MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                                        MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                                        MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                                        _ => updaterUser.LastMessage.LastMessageClass.Text
                                    };

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab?.MAdapter?.ChatList.Move(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    SqLiteDatabase dbSqLite = new SqLiteDatabase();
                                    //Update All data users to database
                                    dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <ChatObject>()
                                    {
                                        updaterUser
                                    });
                                    dbSqLite.Dispose();
                                }
                            }
                            else
                            {
                                //insert new user
                                var data = ConvertData(checker.MesData);
                                if (data != null)
                                {
                                    GlobalContext?.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastChatTab.MAdapter.ChatList.Insert(0, data);
                                            GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(data));
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    //Update All data users to database
                                    //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                                    //{
                                    //    data
                                    //});
                                }
                            }
                        }
                        else
                        {
                            var updaterUser = GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser?.FirstOrDefault(a => a.UserId == message.ToId);
                            if (updaterUser != null)
                            {
                                var index = GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.FirstOrDefault(x => x.UserId == message.ToId));
                                if (index > -1)
                                {
                                    updaterUser.LastMessage.Text = typeModel switch
                                    {
                                        MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile),
                                        MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage),
                                        MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile),
                                        MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber),
                                        MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile),
                                        MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile),
                                        MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile),
                                        MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile),
                                        MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile),
                                        _ => updaterUser.LastMessage.Text
                                    };

                                    GlobalContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser.Move(index, 0);
                                            GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemMoved(index, 0);
                                            GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });
                                    SqLiteDatabase dbSqLite = new SqLiteDatabase();
                                    //Update All data users to database
                                    dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <GetUsersListObject.User>()
                                    {
                                        updaterUser
                                    });
                                    dbSqLite.Dispose();
                                }
                            }
                            else
                            {
                                //insert new user
                                var data = ConvertDataChat(checker.MesData);
                                if (data != null)
                                {
                                    GlobalContext?.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            GlobalContext?.LastMessagesTab?.MAdapter.MLastMessagesUser.Insert(0, data);
                                            GlobalContext?.LastMessagesTab?.MAdapter.NotifyItemInserted(0);
                                            GlobalContext?.LastMessagesTab?.MRecycler.ScrollToPosition(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(data));
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e);
                                        }
                                    });

                                    //Update All data users to database
                                    //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User>
                                    //{
                                    //    data
                                    //});
                                }
                            }
                        }

                        //checker.Media = media;
                        //Update All data users to database
                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_Or_Update_To_one_MessagesTable(checker.MesData);
                        dbDatabase.Dispose();

                        GlobalContext?.RunOnUiThread(() =>
                        {
                            try
                            {
                                //Update data RecyclerView Messages.
                                if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightMap || message.ModelType != MessageModelType.RightVideo)
                                {
                                    WindowActivity?.Update_One_Messages(checker.MesData);
                                }

                                if (SettingsPrefFragment.SSoundControl)
                                {
                                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        });
                    }
                }

                Datauser     = null;
                DataUserChat = null;
                UserData     = null;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }