예제 #1
0
        public void Authorize()
        {
            if (!_client.Authorize())
            {
                string phone, code;
                do
                {
                    Console.Write("Enter your phone number:\n+7");
                    phone = $"7{Console.ReadLine()}";
                }while (!Validation.PhoneValidation(phone));

                _client.EnterPhoneNumber(phone);
                do
                {
                    Console.WriteLine("Enter incoming code:");
                    code = Console.ReadLine();
                }while (!_client.EnterIncomingCode(code).Result);
            }
            Console.WriteLine("Welcome");
            _client.FillAsync();
            _client.ReceivingService.OnAddUnreadMessage += (senderId, message) =>
            {
                Console.Beep();
                if (_client.DialogsService.Dialog?.Id == senderId)
                {
                    ClearAndWrite(message.ToString());
                    _client.ReceivingService.UnreadMessages.Pop();
                }
                if (_client.DialogsService.Dialog == null)
                {
                    _client.DialogsService.FillDialogList();
                }
            };
            _client.SendingService.OnSendMessage += message =>
            {
                Console.Beep();
                ClearAndWrite(message.ToString());
            };
        }