public async Task <RocketChatUserDto[]> GetUsersByEmailAsync(GetRocketChatUsersByEmailInputDto input)
        {
            var cacheKeys = input.Emails.Select(CalculateUserKey).ToArray();

            var cachedUsers = await UserCache.GetManyAsync(cacheKeys);

            var users           = cachedUsers.Select(x => x.Value).OfType <RocketChatUserDto>().ToList().ToList();
            var missingUserKeys = cacheKeys
                                  .Where(x => !users.Any(i => i.Emails != null && i.Emails.Any(e => string.Equals(e.Address, x, StringComparison.OrdinalIgnoreCase))))
                                  .ToArray();

            if (missingUserKeys.Any())
            {
                var query = new GetRocketChatUsersByEmailInputDto
                {
                    Emails = missingUserKeys
                };

                var missingUsers = await GetUsersByEmailFromApiAsync(query);

                var cacheItems = missingUsers
                                 .Select(x => new KeyValuePair <string, RocketChatUserDto>(CalculateUserKey(GetVerifiedOrFirstEmail(x)), x))
                                 .ToArray();

                await UserCache.SetManyAsync(cacheItems);

                users.AddRange(missingUsers);
            }

            return(users.ToArray());
        }
        async Task <RocketChatUserDto[]> GetUsersByEmailFromApiAsync(GetRocketChatUsersByEmailInputDto input)
        {
            // TODO: Create a proper filter query. For now it's easier to just fetch all users
            using (var client = HttpClientFactory.CreateClient("RocketChat"))
            {
                await Authenticator.AuthenticateAsync(client);

                var response = await client.GetFromJsonAsync <UserListResponse>("api/v1/users.list");

                return(response.Users
                       .Where(user => user.Emails != null &&
                              user.Emails.Any(email => input.Emails.Contains(email.Address, StringComparer.OrdinalIgnoreCase)))
                       .ToArray());
            }
        }