@using System.Security @using System.Security.Cryptography @using Blazored.SessionStorage.JsonConverters @code { private string _mxcUri; private string _style; private Stream _stream; [Parameter] public string MxcUri { get => _mxcUri ?? ""; set { if(_mxcUri == value) return; _mxcUri = value; UriHasChanged(value); } } [Parameter] public bool Circular { get; set; } [Parameter] public int Size { get; set; } = 48; [Parameter] public string SizeUnit { get; set; } = "px"; [Parameter] public AuthenticatedHomeserverGeneric? Homeserver { get; set; } private string StyleString => $"{(Circular ? "border-radius: 50%;" : "")} width: {Size}{SizeUnit}; height: {Size}{SizeUnit}; object-fit: cover;"; private static readonly string Prefix = "mxc://"; private static readonly int PrefixLength = Prefix.Length; private async Task UriHasChanged(string value) { if (!value.StartsWith(Prefix)) { // Console.WriteLine($"UriHasChanged: {value} does not start with {Prefix}, passing as resolved URI!!!"); // ResolvedUri = value; return; } if (Homeserver is null) { Console.WriteLine("Homeserver is required for MxcAvatar"); return; } var uri = value[PrefixLength..].Split('/'); // Console.WriteLine($"UriHasChanged: {value} {uri[0]}"); var url = $"/_matrix/media/v3/download/{uri[0]}/{uri[1]}"; Console.WriteLine($"ResolvedUri: {url}"); _stream = await Homeserver.ClientHttpClient.GetStreamAsync(url); StateHasChanged(); } }