예제 #1
0
 public StateManager(
     WaitingQueueRepo waitingQueueRepo,
     ConnectionRepo connectionRepo)
 {
     WaitingQueueRepo = waitingQueueRepo;
     ConnectionRepo   = connectionRepo;
 }
예제 #2
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));
            }
        }
예제 #3
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);
     }
 }
예제 #4
0
        public WaitingManager(
            WaitingQueueRepo waitingQueueRepo,
            ConnectionManager connectionManager,
            ITelegramBotClient telegramClient,
            SubscriberRepo subscriberRepo,
            StateManager stateManager,
            ConnectionNotifier connectionNotifier)
        {
            WaitingQueueRepo  = waitingQueueRepo;
            ConnectionManager = connectionManager;
            TelegramClient    = telegramClient;
            SubscriberRepo    = subscriberRepo;
            StateManager      = stateManager;

            connectionNotifier.NotifyOnCustomerDisconnect(CustomerDisconnected);
        }
예제 #5
0
        public void CustomerDisconnected()
        {
            //TODO: Get first and if connect, then remove from queue
            var customerChatId = WaitingQueueRepo.Dequeue();

            if (customerChatId == default(long))
            {
                return;
            }

            var customer = SubscriberRepo.GetByChatId(customerChatId);

            ConnectionManager.TryConnect(customer);

            var waitersChatIds = WaitingQueueRepo.GetAll().ToList();

            foreach (var waiterChatId in waitersChatIds)
            {
                TelegramClient.SendTextMessageAsync(waiterChatId, $"You're Number {waitersChatIds.IndexOf(waiterChatId) + 1} In Queue.",
                                                    replyMarkup: StateManager.GetCustomerReplyKeyboardMarkup(customer));
            }
        }
예제 #6
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));
            }
        }