public bool IsReleased(object input) { if (!KeyConverter.ContainsInput(input)) { return(false); } return(MouseHardware.CurrentButtonUpEvent(KeyConverter.GetKey(input)) && MouseHardware.OldButtonDownEvent(KeyConverter.GetKey(input))); }
public async Task <KeyVm> SetNewSymmetricKeyForChat(KeyVm key, long chatId, long userId) { using (MessengerDbContext context = contextFactory.Create()) { ChatUser chatUser = await context.ChatUsers .Where(opt => opt.ChatId == chatId && opt.UserId == userId && opt.UserRole >= UserRole.Admin && !opt.Deleted && !opt.Banned) .FirstOrDefaultAsync() .ConfigureAwait(false); if (chatUser == null) { throw new UserIsNotInConversationException(); } Key chatKey = await context.Keys.FirstOrDefaultAsync(opt => opt.ChatId == chatId).ConfigureAwait(false); if (chatKey == null) { chatKey = KeyConverter.GetKey(key); chatKey.ChatId = chatId; chatKey.UserId = null; chatKey.KeyId = RandomExtensions.NextInt64(); await context.AddAsync(chatKey).ConfigureAwait(false); } else { chatKey.ChatId = chatId; chatKey.KeyData = key.Data; chatKey.Version = 1; chatKey.UserId = null; chatKey.GenerationTimeSeconds = key.GenerationTime; chatKey.ExpirationTimeSeconds = key.GenerationTime + key.Lifetime; context.Update(chatKey); } await context.SaveChangesAsync().ConfigureAwait(false); return(KeyConverter.GetKeyVm(chatKey)); } }