1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-18 09:13:15 +00:00

Updated avatar color selection logic (#2151)

* updated avatar color selection logic

* tweaks

* more tweaks

* formatting
This commit is contained in:
mp-bw
2022-10-26 12:34:54 -04:00
committed by GitHub
parent 505426cd6a
commit 5deba15373
6 changed files with 63 additions and 26 deletions

View File

@@ -5,19 +5,19 @@ namespace Bit.App.Controls
{
public interface IAvatarImageSourcePool
{
AvatarImageSource GetOrCreateAvatar(string name, string email);
AvatarImageSource GetOrCreateAvatar(string userId, string name, string email);
}
public class AvatarImageSourcePool : IAvatarImageSourcePool
{
private readonly ConcurrentDictionary<string, AvatarImageSource> _cache = new ConcurrentDictionary<string, AvatarImageSource>();
public AvatarImageSource GetOrCreateAvatar(string name, string email)
public AvatarImageSource GetOrCreateAvatar(string userId, string name, string email)
{
var key = $"{name}{email}";
var key = $"{userId}{name}{email}";
if (!_cache.TryGetValue(key, out var avatar))
{
avatar = new AvatarImageSource(name, email);
avatar = new AvatarImageSource(userId, name, email);
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.