예제 #1
0
        public void CreateNewUser(long chatId, string password)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();

            if (databaseManager.IsStashExist(chatId))
            {
                databaseManager.ClearStash(chatId);
            }

            databaseManager.CreateUser(chatId, password);
        }
예제 #2
0
        private async Task SaveMessageToStashAsync(ITelegramUserMessage message)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();

            IUser user = databaseManager.GetUser(message.ChatId);

            if (user != null && user.IsAuthorized)
            {
                IStashMessage stashMessage = databaseManager.CreateStashMessage(message);
                await stashMessage.DownloadAsync();

                stashMessage.Encrypt(user);
                IDatabaseError databaseError = databaseManager.SaveMessageToStash(stashMessage);
                databaseError.Handle(message.ChatId);
            }
        }
예제 #3
0
        public void Handle(string[] queryArray, int messageId)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();
            IMessageManager  messageManager  = ModulesManager.GetMessageManager();

            if (queryArray.Length < MIN_PARAMETERS_COUNT)
            {
                return;
            }

            bool isChatIdParsed            = long.TryParse(queryArray[1], out long chatId);
            bool isDatabaseMessageIdParsed = long.TryParse(queryArray[2], out long databaseMessageId);

            if (!isChatIdParsed || !isDatabaseMessageIdParsed)
            {
                return;
            }

            databaseManager.DeleteStashMessage(chatId, databaseMessageId);
            messageManager.DeleteMessage(chatId, messageId);
        }
예제 #4
0
        private void GetStash(long chatId, IChatStateHandlerContext context)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();
            IMessageManager  messageManager  = ModulesManager.GetMessageManager();

            IUser user = databaseManager.GetUser(chatId);

            if (user != null && user.IsAuthorized)
            {
                ICollection <IStashMessage> messagesFromStash = databaseManager.GetMessagesFromStash(chatId);
                if (messagesFromStash.Count == 0)
                {
                    messageManager.SendTextMessageAsync(chatId, TextResponse.Get(ResponseType.EmptyStash), null);
                }
                else
                {
                    foreach (IStashMessage stashMessage in messagesFromStash)
                    {
                        stashMessage.Decrypt(user);
                        stashMessage.Send();
                    }
                }
            }
        }
예제 #5
0
        public bool LoginUser(long chatId, string password)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();

            return(databaseManager.LoginUser(chatId, password));
        }
예제 #6
0
        public void LogoutUser(long chatId)
        {
            IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager();

            databaseManager.LogoutUser(chatId);
        }