Tigran 3 anni fa
parent
commit
0e7acabf7f

+ 0 - 3
CardCollector/Commands/CallbackQuery/AuthorsMenu.cs

@@ -22,10 +22,7 @@ namespace CardCollector.Commands.CallbackQuery
             var totalCount = list.Count;
             list = list.GetRange((page - 1) * 10, list.Count >= page * 10 ? 10 : list.Count % 10);
             if (list.Count == 0)
-            {
-                User.Session.PopLast();
                 await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
-            }
             /* Заменяем сообщение меню на сообщение со списком */
             else
                 await MessageController.EditMessage(User, CallbackMessageId, Messages.choose_author,

+ 0 - 3
CardCollector/Commands/CallbackQuery/BuyAuthorPackMenu.cs

@@ -20,10 +20,7 @@ namespace CardCollector.Commands.CallbackQuery
             var totalCount = packs.Count;
             packs = packs.GetRange((page - 1) * 10, packs.Count >= page * 10 ? 10 : packs.Count % 10);
             if (packs.Count == 0)
-            {
-                User.Session.PopLast();
                 await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
-            }
             else
                 await MessageController.EditMessage(User, CallbackMessageId, Messages.choose_author,
                     Keyboard.GetShopPacksKeyboard(packs, Keyboard.GetPagePanel(page, totalCount, CommandText)));

+ 3 - 1
CardCollector/Commands/CallbackQuery/Combine.cs

@@ -15,8 +15,10 @@ namespace CardCollector.Commands.CallbackQuery
 
         public override async Task Execute()
         {
-            User.Session.State = UserState.CombineMenu;
             var combineModule = User.Session.GetModule<CombineModule>();
+            if (User.Session.State != UserState.CombineMenu)
+                combineModule.CombineList.Clear();
+            User.Session.State = UserState.CombineMenu;
             if (combineModule.SelectedSticker == null)
             {
                 var collectionModule = User.Session.GetModule<CollectionModule>();

+ 0 - 6
CardCollector/Commands/CallbackQuery/OpenAuthorPackMenu.cs

@@ -19,20 +19,14 @@ namespace CardCollector.Commands.CallbackQuery
             var packs = (await UserPacksDao.GetUserPacks(User.Id))
                 .Where(item => item.Count > 0 && item.PackId != 1).ToList();
             if (packs.Count == 0)
-            {
-                User.Session.PopLast();
                 await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.packs_count_zero, true);
-            }
             else
             {
                 var page = int.Parse(CallbackData.Split('=')[1]);
                 var totalCount = packs.Count;
                 packs = packs.GetRange((page - 1) * 10, packs.Count >= page * 10 ? 10 : packs.Count % 10);
                 if (packs.Count == 0)
-                {
-                    User.Session.PopLast();
                     await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
-                }
                 else
                     await MessageController.EditMessage(User, CallbackMessageId, Messages.choose_author,
                         await Keyboard.GetUserPacksKeyboard(packs, Keyboard.GetPagePanel(page, totalCount, CommandText)));

+ 0 - 3
CardCollector/Commands/CallbackQuery/SpecialOffers.cs

@@ -20,10 +20,7 @@ namespace CardCollector.Commands.CallbackQuery
                 .WhereAsync(async offer => offer.IsInfinite || !await SpecialOfferUsersDao.NowUsed(User.Id, offer.Id));
             var shopEntities = specialOffers.ToList();
             if (shopEntities.Count < 1)
-            {
-                User.Session.PopLast();
                 await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.offers_not_found, true);
-            }
             else
                 await MessageController.EditMessage(User, CallbackMessageId, Messages.available_offers,
                     Keyboard.SpecialOffersKeyboard(shopEntities));

+ 1 - 1
CardCollector/Commands/ChosenInlineResult/GetUnlimitedStickerAndExecuteCommand.cs

@@ -24,7 +24,7 @@ namespace CardCollector.Commands.ChosenInlineResult
             /* Выдаем пользователю 1 стикер */
             await UserStickerRelationDao.AddNew(User, sticker, 1);
             /* Выполняем стандартный сценарий команды */
-            await PrivateFactory(Update, User).Execute();
+            await PrivateFactory(Update, User).PrepareAndExecute();
         }
         
         public GetUnlimitedStickerAndExecuteCommand() { }

+ 3 - 1
CardCollector/Commands/IgnoreUpdate.cs

@@ -11,7 +11,9 @@ namespace CardCollector.Commands
         protected override bool ClearMenu => false;
         protected override bool AddToStack => false;
 
-        public override Task Execute() { return  Task.CompletedTask; }
+        public override Task PrepareAndExecute() => Task.CompletedTask;
+        public override Task Execute() => Task.CompletedTask;
+        
         protected internal override bool IsMatches(UserEntity user, Update update) => true;
     }
 }

+ 1 - 1
CardCollector/Commands/Message/Auction.cs

@@ -21,7 +21,7 @@ namespace CardCollector.Commands.Message
             User.Session.State = UserState.AuctionMenu;
             User.Session.InitNewModule<AuctionModule>();
             /* Отображаем сообщение с фильтрами */
-            await new ShowFiltersMenu(User, Update).PrepareAndExecute();
+            await new ShowFiltersMenu(User, Update).Execute();
         }
         
         public Auction() { }

+ 1 - 1
CardCollector/Commands/Message/Collection.cs

@@ -21,7 +21,7 @@ namespace CardCollector.Commands.Message
             User.Session.State = UserState.CollectionMenu;
             User.Session.InitNewModule<CollectionModule>();
             /* Отображаем сообщение с фильтрами */
-            await new ShowFiltersMenu(User, Update).PrepareAndExecute();
+            await new ShowFiltersMenu(User, Update).Execute();
         }
         
         public Collection() { }

+ 1 - 1
CardCollector/Commands/UpdateModel.cs

@@ -21,7 +21,7 @@ namespace CardCollector.Commands
 
         public abstract Task Execute();
 
-        public async Task PrepareAndExecute()
+        public virtual async Task PrepareAndExecute()
         {
             User.Session.SetCurrentCommand(GetType());
             if (ClearMenu) User.Session.ClearMenuStack();

+ 1 - 0
CardCollector/Extensions.cs

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
 using CardCollector.DataBase.Entity;
 using CardCollector.DataBase.EntityDao;
 using CardCollector.Resources;
+using CardCollector.Session;
 using Microsoft.EntityFrameworkCore;
 using Telegram.Bot.Types.InlineQueryResults;
 

+ 0 - 1
CardCollector/Resources/Keyboard.cs

@@ -309,7 +309,6 @@ namespace CardCollector.Resources
                 keyboard.Add(new []{InlineKeyboardButton.WithCallbackData($"{Text.delete} {Text.sticker} {keyboard.Count + 1}",
                     $"{Command.delete_combine}={sticker.Md5Hash}")});
             }
-            keyboard.Add(new []{InlineKeyboardButton.WithCallbackData(Text.back, Command.back)});
             if (module.GetCombineCount() == Constants.COMBINE_COUNT)
                 keyboard.Add(new[] {InlineKeyboardButton.WithCallbackData(
                     $"{Text.combine} {module.CalculateCombinePrice()}{Text.coin}", Command.combine_stickers)});

+ 4 - 9
CardCollector/Session/Session.cs

@@ -85,20 +85,15 @@ namespace CardCollector.Session
 
         public bool TryGetPreviousMenu(out MenuInformation menu)
         {
-            if (MenuStack.TryPeek(out menu) && CurrentCommandType != menu.GetMenuType()) return true;
-            PopLast();
+            while (MenuStack.TryPeek(out menu) && CurrentCommandType == menu.GetMenuType()) {
+                MenuStack.TryPop(out _);
+            }
             return MenuStack.TryPeek(out menu);
         }
 
-        public void PopLast()
-        {
-            MenuStack.TryPop(out _);
-        }
-
         public void AddMenuToStack(UpdateModel menu)
         {
-            if (!MenuStack.TryPeek(out var current) || current.GetType() != menu.GetType())
-                MenuStack.Push(new MenuInformation(menu, State));
+            MenuStack.Push(new MenuInformation(menu, State));
         }
 
         public void SetCurrentCommand(Type commandType)