mirror of
https://github.com/bitwarden/mobile.git
synced 2024-09-27 03:52:57 +02:00
6102a0c115
* [SG-912] Modify the mobile app to retrieve the user's avatar color (#2277) * work: baseline * fix: dont use profile for store * fiix: use userid in key * fix: lookup on AccountView list create * fix my own bad advice + tweaks * Autosync the updated translations (#2279) * fix my own bad advice + tweaks * fiix: use userid in key * [PS-1352] Fix ignore diacritics in search (#2044) * Fix ignore diacritics in search This change updates the search function to ignore diacritical marks in search results. Marks are stripped from both the search input and results. * Removed logs, added null or whitespace validation and improved formatting * [PS-2145] add rainsee browser series support (#2272) * fix: lookup on AccountView list create * Autosync the updated translations (#2279) * fix my own bad advice + tweaks * fix: single state grab is cool
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace Bit.App.Controls
|
|
{
|
|
public interface IAvatarImageSourcePool
|
|
{
|
|
AvatarImageSource GetOrCreateAvatar(string userId, string name, string email, string color);
|
|
}
|
|
|
|
public class AvatarImageSourcePool : IAvatarImageSourcePool
|
|
{
|
|
private readonly ConcurrentDictionary<string, AvatarImageSource> _cache = new ConcurrentDictionary<string, AvatarImageSource>();
|
|
|
|
public AvatarImageSource GetOrCreateAvatar(string userId, string name, string email, string color)
|
|
{
|
|
var key = $"{userId}{name}{email}{color}";
|
|
if (!_cache.TryGetValue(key, out var avatar))
|
|
{
|
|
avatar = new AvatarImageSource(userId, name, email, color);
|
|
if (!_cache.TryAdd(key, avatar)
|
|
&&
|
|
!_cache.TryGetValue(key, out avatar)) // If add fails another thread created the avatar in between the first try get and the try add.
|
|
{
|
|
// if add and get after fails, then something wrong is going on with this method.
|
|
throw new InvalidOperationException("Something is wrong creating the avatar image");
|
|
}
|
|
}
|
|
return avatar;
|
|
}
|
|
}
|
|
}
|
|
|