Esempio n. 1
0
        // Process awaitable message from user
        public async Task ProcessAwaitableMessage(TelegramAwaitable awaitable, TelegramWebhookUpdate result)
        {
            // Reply on awaitable
            SendMessageObject sendMessage = new SendMessageObject();

            sendMessage.chat_id = result.message.chat.id.ToString();
            sendMessage.text    = "Reply from ProcessAwaitableMessage method, need to implement this method.";

            await SendTextMessage(sendMessage);

            // TODO: Implement logics under /event call



            // Update awaitable message in database
            UpdateAwaitableMessage(result);
        }
Esempio n. 2
0
        // Send text message to telegram user
        public async Task <ActionResult> SendTextMessage(SendMessageObject message)
        {
            // Target URI
            string url    = telegramSecretUrl + "sendMessage?chat_id=" + message.chat_id + "&text=" + message.text;
            string result = string.Empty;

            // HttpClient
            using (HttpClient client = new HttpClient())
                using (HttpResponseMessage response = await client.GetAsync(url))
                    using (HttpContent content = response.Content)
                    {
                        // Read the string
                        result = await content.ReadAsStringAsync();
                    }

            return(Content(result));
        }
 private void Update()
 {
     if (ui != null)
     {
         if (refreshJoinList)
         {
             refreshJoinList = false;
             foreach (string command in commands)
             {
                 ui.SendMessage("WriteCommand", command);
             }
         }
     }
     if (_queue.Count > 0)
     {
         SendMessageObject messageObject = _queue.Dequeue();
         gamecontroller.SendMessage(messageObject.messajeName, messageObject.messageParam);
     }
 }
Esempio n. 4
0
        // Process initial message from user
        public async Task ProcessInitialMessage(TelegramWebhookUpdate result)
        {
            if (result.message.text == "/event")
            {
                SendMessageObject sendMessage = new SendMessageObject();
                sendMessage.chat_id = result.message.chat.id.ToString();
                sendMessage.text    = "Welcome " + result.message.chat.first_name + " on .NET BOT self help service. Please send your location to know more about events.";

                // Insert awaitable in database
                InsertAwaitableMessage(result);

                await SendTextMessage(sendMessage);
            }
            else if (result.message.text == "/hello")
            {
                SendMessageObject sendMessage = new SendMessageObject();
                sendMessage.chat_id = result.message.chat.id.ToString();
                sendMessage.text    = "Hi " + result.message.chat.first_name + ", I'm a .NET BOT. Just send me /help to begin.";

                await SendTextMessage(sendMessage);
            }
            else if (result.message.text == "/help")
            {
                SendMessageObject sendMessage = new SendMessageObject();
                sendMessage.chat_id = result.message.chat.id.ToString();
                sendMessage.text    = "Nice to meet you " + result.message.chat.first_name + ", i can help you to find events around you. Just send me /event to begin.";

                await SendTextMessage(sendMessage);
            }
            else
            {
                SendMessageObject sendMessage = new SendMessageObject();
                sendMessage.chat_id = result.message.chat.id.ToString();
                sendMessage.text    = ":( I don't get this. Send /help to begin.";

                await SendTextMessage(sendMessage);
            }
        }
Esempio n. 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;

                    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);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        private static void UpdateLastIdMessage(SendMessageObject messages, UserInfoObject userData, string hashId)
        {
            try
            {
                var checker = MessagesBoxActivity.MAdapter?.MessageList?.FirstOrDefault(a => a.Id == Convert.ToInt32(hashId));
                if (checker != null)
                {
                    checker.Id          = messages.Data.Id;
                    checker.FromName    = UserDetails.FullName;
                    checker.FromAvater  = UserDetails.Avatar;
                    checker.ToName      = userData?.Fullname ?? "";
                    checker.ToAvater    = userData?.Avater ?? "";
                    checker.From        = messages.Data.From;
                    checker.To          = messages.Data.To;
                    checker.Text        = Methods.FunString.DecodeString(messages.Data.Text);
                    checker.Media       = checker.Media.Contains("upload/chat/") && !messages.Data.Media.Contains(Client.WebsiteUrl)? Client.WebsiteUrl + "/" + messages.Data.Media: messages.Data.Media;
                    checker.FromDelete  = messages.Data.FromDelete;
                    checker.ToDelete    = messages.Data.ToDelete;
                    checker.Sticker     = messages.Data.Sticker;
                    checker.CreatedAt   = messages.Data.CreatedAt;
                    checker.Seen        = messages.Data.Seen;
                    checker.Type        = "Sent";
                    checker.MessageType = messages.Data.MessageType;

                    string text = Methods.FunString.DecodeString(messages.Data.Text);

                    switch (checker.MessageType)
                    {
                    case "text":
                    {
                        text = string.IsNullOrEmpty(text) ? Application.Context.GetText(Resource.String.Lbl_SendMessage) : Methods.FunString.DecodeString(messages.Data.Text);
                        break;
                    }

                    case "media":
                    {
                        text = Application.Context.GetText(Resource.String.Lbl_SendImageFile);
                        break;
                    }

                    case "sticker" when checker.Sticker.Contains(".gif"):
                    {
                        text = Application.Context.GetText(Resource.String.Lbl_SendGifFile);
                        break;
                    }

                    case "sticker":
                    {
                        text = Application.Context.GetText(Resource.String.Lbl_SendStickerFile);
                        break;
                    }
                    }

                    var dataUser = LastChatActivity.MAdapter?.UserList?.FirstOrDefault(a => a.User.Id == messages.Data.To);
                    if (dataUser != null)
                    {
                        var index = LastChatActivity.MAdapter?.UserList?.IndexOf(LastChatActivity.MAdapter.UserList?.FirstOrDefault(x => x.User.Id == messages.Data.To));
                        if (index > -1)
                        {
                            dataUser.Text = text;

                            LastChatActivity.MAdapter?.UserList?.Move(Convert.ToInt32(index), 0);
                            LastChatActivity.MAdapter?.NotifyItemMoved(Convert.ToInt32(index), 0);

                            var data = LastChatActivity.MAdapter?.UserList?.FirstOrDefault(a => a.User.Id == dataUser.User.Id);
                            if (data != null)
                            {
                                data.Id          = dataUser.Id;
                                data.Owner       = dataUser.Owner;
                                data.User        = dataUser.User;
                                data.Seen        = dataUser.Seen;
                                data.Text        = dataUser.Text;
                                data.Media       = dataUser.Media;
                                data.Sticker     = dataUser.Sticker;
                                data.Time        = dataUser.Time;
                                data.CreatedAt   = dataUser.CreatedAt;
                                data.NewMessages = dataUser.NewMessages;
                                data.MessageType = dataUser.MessageType;

                                LastChatActivity.MAdapter.NotifyItemChanged(LastChatActivity.MAdapter.UserList.IndexOf(data));
                            }
                        }
                    }
                    else
                    {
                        if (userData != null)
                        {
                            LastChatActivity.MAdapter?.UserList?.Insert(0, new GetConversationListObject.DataConversation()
                            {
                                Id          = userData.Id,
                                Owner       = 0,
                                User        = userData,
                                Seen        = 1,
                                Text        = text,
                                Media       = checker.Media,
                                Sticker     = messages.Data.Sticker,
                                Time        = messages.Data.CreatedAt,
                                CreatedAt   = messages.Data.CreatedAt,
                                NewMessages = 0
                            });

                            LastChatActivity.MAdapter?.NotifyItemInserted(0);
                        }
                    }

                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                    GetChatConversationsObject.Messages message = new GetChatConversationsObject.Messages
                    {
                        Id          = messages.Data.Id,
                        FromName    = UserDetails.FullName,
                        FromAvater  = UserDetails.Avatar,
                        ToName      = userData?.Fullname ?? "",
                        ToAvater    = userData?.Avater ?? "",
                        From        = messages.Data.From,
                        To          = messages.Data.To,
                        Text        = Methods.FunString.DecodeString(messages.Data.Text),
                        Media       = checker.Media,
                        FromDelete  = messages.Data.FromDelete,
                        ToDelete    = messages.Data.ToDelete,
                        Sticker     = messages.Data.Sticker,
                        CreatedAt   = messages.Data.CreatedAt,
                        Seen        = messages.Data.Seen,
                        Type        = "Sent",
                        MessageType = messages.Data.MessageType,
                    };
                    //Update All data users to database
                    dbDatabase.InsertOrUpdateToOneMessages(message);
                    dbDatabase.Dispose();

                    MessagesBoxActivity.UpdateOneMessage(message);
                    MessagesBoxActivity.GetInstance()?.ChatBoxRecyclerView.ScrollToPosition(MessagesBoxActivity.MAdapter.MessageList.IndexOf(MessagesBoxActivity.MAdapter.MessageList.Last()));

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