Exemplo n.º 1
0
        public void AddToQueue(SubscriberRecord customer)
        {
            if (ConnectionManager.HasCustomerConnection(customer))
            {
                TelegramClient.SendTextMessageAsync(customer.ChatId, "You are already connected.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
                return;
            }

            if (WaitingQueueRepo.HasWaiter(customer))
            {
                TelegramClient.SendTextMessageAsync(customer.ChatId, $"You're Number {WaitingQueueRepo.GetPosition(customer)} In Queue.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
                return;
            }

            if (!WaitingQueueRepo.Any())
            {
                if (!ConnectionManager.TryConnect(customer))
                {
                    WaitingQueueRepo.Enqueue(customer);
                    TelegramClient.SendTextMessageAsync(customer.ChatId, $"You're Number {WaitingQueueRepo.GetPosition(customer)} In Queue.",
                                                        replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
                }
            }
            else
            {
                WaitingQueueRepo.Enqueue(customer);
                TelegramClient.SendTextMessageAsync(customer.ChatId, $"You're Number {WaitingQueueRepo.GetPosition(customer)} In Queue.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
            }
        }
Exemplo n.º 2
0
 public IReplyMarkup GetCustomerReplyKeyboardMarkup(SubscriberRecord customer)
 {
     if (ConnectionRepo.FindPartyChatId(customer) != default(long))
     {
         return(Keyboards.Connected);
     }
     else if (WaitingQueueRepo.HasWaiter(customer))
     {
         return(Keyboards.InQueue);
     }
     else
     {
         return(Keyboards.NotConnected);
     }
 }
Exemplo n.º 3
0
        public void Cancel(SubscriberRecord customer)
        {
            if (!WaitingQueueRepo.HasWaiter(customer))
            {
                TelegramClient.SendTextMessageAsync(customer.ChatId, "You're not In Queue.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
                return;
            }

            var removedPosition = WaitingQueueRepo.GetPosition(customer);

            WaitingQueueRepo.Remove(customer);
            TelegramClient.SendTextMessageAsync(customer.ChatId, "You're not In Queue Anymore.",
                                                replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));

            var waiters = WaitingQueueRepo.GetAll().ToList();
            var waitersToNotifyChatIds = waiters.Skip(removedPosition - 1);

            foreach (var chatId in waitersToNotifyChatIds)
            {
                TelegramClient.SendTextMessageAsync(chatId, $"You're Number {waiters.IndexOf(chatId) + 1} In Queue.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
            }
        }