about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Shared')
-rw-r--r--MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor2
-rw-r--r--MatrixRoomUtils.Web/Shared/InlineUserItem.razor63
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor27
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor.css10
-rw-r--r--MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor42
-rw-r--r--MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor11
-rw-r--r--MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor21
-rw-r--r--MatrixRoomUtils.Web/Shared/UserListItem.razor4
8 files changed, 164 insertions, 16 deletions
diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
index 42f2c09..03a7145 100644
--- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
@@ -24,7 +24,7 @@
     [Parameter]
     public UserInfo User { get; set; } = null!;
 
-    private string _avatarUrl { get; set; }
+    private string? _avatarUrl { get; set; }
     private int _roomCount { get; set; } = 0;
 
     protected override async Task OnInitializedAsync()
diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
new file mode 100644
index 0000000..56131c8
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
@@ -0,0 +1,63 @@
+@using MatrixRoomUtils.Core.Responses
+<div style="background-color: #ffffff11; border-radius: 0.5em; height: 1em; display: inline-block; vertical-align: middle;" alt="@UserId">
+    <img style="@(ChildContent != null ? "vertical-align: baseline;" : "vertical-align: top;") width: 1em; height: 1em; border-radius: 50%;" src="@ProfileAvatar"/>
+    <span style="position: relative; top: -5px;">@ProfileName</span>
+
+    <div style="display: inline-block;">
+        @if (ChildContent != null)
+        {
+            @ChildContent
+        }
+    </div>
+
+</div>
+
+@code {
+
+    [Parameter]
+    public RenderFragment? ChildContent { get; set; }
+
+    [Parameter]
+    public ProfileResponse User { get; set; }
+
+    [Parameter]
+    public string UserId { get; set; }
+
+    [Parameter]
+    public string? ProfileAvatar { get; set; } = null;
+    
+    [Parameter]
+    public string? ProfileName { get; set; } = null;
+
+
+    private static SemaphoreSlim _semaphoreSlim = new(128);
+
+    protected override async Task OnInitializedAsync()
+    {
+        await base.OnInitializedAsync();
+        await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+
+        await _semaphoreSlim.WaitAsync();
+
+        var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure();
+
+        if (User == null)
+        {
+            if (UserId == null)
+            {
+                throw new ArgumentNullException(nameof(UserId));
+            }
+            User = await hs.GetProfile(UserId);
+        }
+        else
+        {
+            // UserId = User.;
+        }
+        
+        ProfileAvatar ??= RuntimeCache.CurrentHomeServer.ResolveMediaUri(User.AvatarUrl);
+        ProfileName ??= User.DisplayName;
+
+        _semaphoreSlim.Release();
+    }
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 4990b3c..fb28c3c 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -1,11 +1,11 @@
 @using MatrixRoomUtils.Core.Authentication
 @using System.Text.Json
 @using MatrixRoomUtils.Core.Extensions
-<div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content; @(hasDangerousRoomVersion ? "border: red 4px solid;" : hasOldRoomVersion ? "border: #FF0 1px solid;" : "")">
+<div class="roomListItem" style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content; @(hasDangerousRoomVersion ? "border: red 4px solid;" : hasOldRoomVersion ? "border: #FF0 1px solid;" : "")">
     @if (ShowOwnProfile)
     {
-        <img style="@(ChildContent != null ? "vertical-align: baseline;":"") width: 32px; height:  32px; border-radius: 50%; @(hasCustomProfileAvatar ? "border-color: red; border-width: 3px; border-style: dashed;" : "")" src="@profileAvatar"/>
-        <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px; @(hasCustomProfileName ? "background-color: red;" : "")">@profileName</span>
+        <img class="imageUnloaded @(string.IsNullOrWhiteSpace(profileAvatar) ? "" : "imageLoaded")" style="@(ChildContent != null ? "vertical-align: baseline;":"") width: 32px; height: 32px; border-radius: 50%; @(hasCustomProfileAvatar ? "border-color: red; border-width: 3px; border-style: dashed;" : "")" src="@(profileAvatar ?? "/icon-192.png")" @onload="Callback"/>
+        <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px; @(hasCustomProfileName ? "background-color: red;" : "")">@(profileName ?? "Loading...")</span>
         <span style="vertical-align: middle; padding-right: 8px; padding-left: 0px;">-></span>
     }
     <img style="@(ChildContent != null ? "vertical-align: baseline;":"") width: 32px; height:  32px; border-radius: 50%;" src="@roomIcon"/>
@@ -34,10 +34,10 @@
     public bool ShowOwnProfile { get; set; } = false;
 
     private string roomName { get; set; } = "Loading...";
-    private string roomIcon { get; set; } = "/icon-192.png";
+    private string? roomIcon { get; set; } = "/icon-192.png";
 
-    private string profileAvatar { get; set; } = "/icon-192.png";
-    private string profileName { get; set; } = "Loading...";
+    private string? profileAvatar { get; set; }
+    private string? profileName { get; set; }
     private bool hasCustomProfileAvatar { get; set; } = false;
     private bool hasCustomProfileName { get; set; } = false;
     
@@ -53,8 +53,8 @@
         await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
         
         await _semaphoreSlim.WaitAsync();
-        
-        var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure();
+
+        var hs = RuntimeCache.CurrentHomeServer; //await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure();
         
         if (Room == null)
         {
@@ -69,11 +69,7 @@
             RoomId = Room.RoomId;
         }
 
-        roomName = await Room.GetNameAsync();
-        if (roomName == null)
-        {
-            roomName = "Unnamed room: " + RoomId;
-        }
+        roomName = await Room.GetNameAsync() ?? "Unnamed room: " + RoomId;
 
         var ce = await Room.GetCreateEventAsync();
         if (ce != null)
@@ -143,4 +139,9 @@
             await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
     }
 
+    private void Callback(ProgressEventArgs obj)
+    {
+        Console.WriteLine("prog: " + obj.ToJson(indent: false));
+    }
+
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css b/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css
new file mode 100644
index 0000000..8b9a9f6
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css
@@ -0,0 +1,10 @@
+/*.imageUnloaded {*/
+/*    scale: 3;*/
+/*    opacity: 0.5;*/
+/*    transition: scale 0.5s ease-in-out;*/
+/*}*/
+
+.imageLoaded {
+     opacity: 1;
+     scale: 1;
+ }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
new file mode 100644
index 0000000..3803d38
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
@@ -0,0 +1,42 @@
+@using MatrixRoomUtils.Core.Extensions
+@if (Event.ContentAsJsonNode["membership"]!.GetValue<string>() == "ban")
+{
+    <i>@Event.StateKey was banned</i>
+}
+else if (Event.ContentAsJsonNode["membership"]!.GetValue<string>() == "invite")
+{
+    <i>@Event.StateKey was invited</i>
+}
+else if (Event.ContentAsJsonNode["membership"]!.GetValue<string>() == "join")
+{
+    @if (Event.ReplacesState != null)
+    {
+        <i>@Event.StateKey changed their display name to @(Event.ContentAsJsonNode["displayname"]!.GetValue<string>())</i>
+    }
+    else
+    {
+        <i><InlineUserItem UserId="@Event.StateKey"></InlineUserItem> joined</i>
+    }
+}
+else if (Event.ContentAsJsonNode["membership"]!.GetValue<string>() == "leave")
+{
+    <i>@Event.StateKey left</i>
+}
+else if (Event.ContentAsJsonNode["membership"]!.GetValue<string>() == "knock")
+{
+    <i>@Event.StateKey knocked</i>
+}
+else
+{
+    <i>@Event.StateKey has an unknown state:</i>
+    <pre>
+        @Event.ToJson()
+    </pre>
+}
+
+@code {
+
+    [Parameter]
+    public StateEvent Event { get; set; }
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor
new file mode 100644
index 0000000..8d688ea
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor
@@ -0,0 +1,11 @@
+@using MatrixRoomUtils.Core.Extensions
+<pre>
+    @ObjectExtensions.ToJson(Event.Content, indent: false)
+</pre>
+
+@code {
+
+    [Parameter]
+    public StateEventResponse Event { get; set; }
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor
new file mode 100644
index 0000000..f78bdc9
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor
@@ -0,0 +1,21 @@
+@using MatrixRoomUtils.Core.Extensions
+<div>
+
+    <details style="display: inline;">
+        <summary>
+            <i style="color: red;">
+                Unknown event type: <pre style="display: inline;">@Event.Type</pre>
+            </i>
+        </summary>
+        <pre>
+           @Event.ToJson()
+        </pre>
+    </details>
+</div>
+
+@code {
+
+    [Parameter]
+    public StateEvent Event { get; set; }
+
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor
index ae1fcd1..d357b0d 100644
--- a/MatrixRoomUtils.Web/Shared/UserListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor
@@ -23,8 +23,8 @@
     [Parameter]
     public string UserId { get; set; }
 
-    private string profileAvatar { get; set; } = "/icon-192.png";
-    private string profileName { get; set; } = "Loading...";
+    private string? profileAvatar { get; set; } = "/icon-192.png";
+    private string? profileName { get; set; } = "Loading...";
 
 
     private static SemaphoreSlim _semaphoreSlim = new(128);