@code { [Parameter] public string? Uri { get; set { // Console.WriteLine($"New MXC uri: {value}"); if (field == value) return; field = value; UriHasChanged(value); } } [Parameter] public bool Circular { get; set; } [Parameter] public int? Width { get; set; } [Parameter] public int? Height { get; set; } [Parameter] public string? Style { get; set { field = value; StateHasChanged(); } } [Parameter] public required AuthenticatedHomeserverGeneric Homeserver { get; set; } private string? ResolvedUrl { get; set { field = value; StateHasChanged(); } } private string StyleString => $"{Style} {(Circular ? "border-radius: 50%;" : "")} {(Width.HasValue ? $"width: {Width}px;" : "")} {(Height.HasValue ? $"height: {Height}px;" : "")} object-fit: cover;"; // private static readonly string Prefix = "mxc://"; // private static readonly int PrefixLength = Prefix.Length; private async Task UriHasChanged(string? value) { try { if (string.IsNullOrWhiteSpace(value)) { ResolvedUrl = null; return; } if (Homeserver is null) { Console.WriteLine($"Homeserver is required for MxcImage! Uri: {value}, Homeserver: {Homeserver?.ToString() ?? "null"}"); return; } ResolvedUrl = await Homeserver.GetMediaUrlAsync(value); // Console.WriteLine($"[MxcImage] Resolved URL: {ResolvedUrl}"); StateHasChanged(); } catch (Exception e) { await Console.Error.WriteLineAsync($"Error resolving media URL: {e}"); } } }