public void CreateNewUser(long chatId, string password) { IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager(); if (databaseManager.IsStashExist(chatId)) { databaseManager.ClearStash(chatId); } databaseManager.CreateUser(chatId, password); }
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); } }
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); }
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(); } } } }
public bool LoginUser(long chatId, string password) { IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager(); return(databaseManager.LoginUser(chatId, password)); }
public void LogoutUser(long chatId) { IDatabaseManager databaseManager = ModulesManager.GetDatabaseManager(); databaseManager.LogoutUser(chatId); }