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/InlineUserItem.razor9
-rw-r--r--MatrixRoomUtils.Web/Shared/NavMenu.razor10
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomList.razor3
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor3
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor52
-rw-r--r--MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor3
-rw-r--r--MatrixRoomUtils.Web/Shared/UserListItem.razor3
7 files changed, 63 insertions, 20 deletions
diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
index 3aea0e0..7bc88e5 100644
--- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor
@@ -2,6 +2,7 @@
 @using LibMatrix.EventTypes.Spec.State
 @using LibMatrix.Helpers
 @using LibMatrix.Homeservers
+@using LibMatrix.Responses
 <div style="background-color: #ffffff11; border-radius: 0.5em; height: 1em; display: inline-block; vertical-align: middle;" alt="@UserId">
     <img style="@(ChildContent is not null ? "vertical-align: baseline;" : "vertical-align: top;") width: 1em; height: 1em; border-radius: 50%;" src="@ProfileAvatar"/>
     <span style="position: relative; top: -5px;">@ProfileName</span>
@@ -20,10 +21,10 @@
     public RenderFragment? ChildContent { get; set; }
 
     [Parameter]
-    public ProfileResponseEventContent User { get; set; }
+    public UserProfileResponse? User { get; set; }
 
     [Parameter]
-    public ProfileResponseEventContent MemberEvent { get; set; }
+    public RoomMemberEventContent? MemberEvent { get; set; }
 
     [Parameter]
     public string? UserId { get; set; }
@@ -50,7 +51,7 @@
             throw new ArgumentNullException(nameof(UserId));
 
         if (MemberEvent != null) {
-            User = new ProfileResponseEventContent {
+            User = new UserProfileResponse {
                 AvatarUrl = MemberEvent.AvatarUrl,
                 DisplayName = MemberEvent.DisplayName
             };
@@ -61,7 +62,7 @@
         }
 
 
-        ProfileAvatar ??= await hsResolver.ResolveMediaUri(HomeServer.ServerName, User.AvatarUrl);
+        ProfileAvatar ??= HomeServer.ResolveMediaUri(User.AvatarUrl);
         ProfileName ??= User.DisplayName;
 
         _semaphoreSlim.Release();
diff --git a/MatrixRoomUtils.Web/Shared/NavMenu.razor b/MatrixRoomUtils.Web/Shared/NavMenu.razor
index 68b491d..daa4a52 100644
--- a/MatrixRoomUtils.Web/Shared/NavMenu.razor
+++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor
@@ -35,8 +35,14 @@
         </div>
 
         <div class="nav-item px-3">
-            <NavLink class="nav-link" href="User/Manage">
-                <span class="oi oi-plus" aria-hidden="true"></span> Manage user
+            <NavLink class="nav-link" href="User/Profile">
+                <span class="oi oi-plus" aria-hidden="true"></span> Manage profile
+            </NavLink>
+        </div>
+        
+        <div class="nav-item px-3">
+            <NavLink class="nav-link" href="User/DirectMessages">
+                <span class="oi oi-plus" aria-hidden="true"></span> Manage DMs
             </NavLink>
         </div>
 
diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor
index 705f68c..f78c7f7 100644
--- a/MatrixRoomUtils.Web/Shared/RoomList.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomList.razor
@@ -4,6 +4,7 @@
 @using ArcaneLibs.Extensions
 @using LibMatrix.EventTypes.Spec.State
 @using System.Collections.ObjectModel
+@using LibMatrix.Responses
 @using _Imports = MatrixRoomUtils.Web._Imports
 @if (!StillFetching) {
     <p>Fetching room details... @RoomsWithTypes.Sum(x => x.Value.Count) out of @Rooms.Count done!</p>
@@ -23,7 +24,7 @@ else {
     public ObservableCollection<RoomInfo> Rooms { get; set; }
 
     [Parameter]
-    public ProfileResponseEventContent? GlobalProfile { get; set; }
+    public UserProfileResponse? GlobalProfile { get; set; }
 
     [Parameter]
     public bool StillFetching { get; set; } = true;
diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index 27084cc..e2c1285 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -2,6 +2,7 @@
 @using LibMatrix
 @using LibMatrix.EventTypes.Spec.State
 @using LibMatrix.Homeservers
+@using LibMatrix.Responses
 <details>
     <summary>@roomType (@rooms.Count)</summary>
     @foreach (var room in rooms) {
@@ -29,7 +30,7 @@
     public KeyValuePair<string, List<RoomInfo>> Category { get; set; }
 
     [Parameter]
-    public ProfileResponseEventContent? GlobalProfile { get; set; }
+    public UserProfileResponse? GlobalProfile { get; set; }
 
     [CascadingParameter]
     public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!;
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 79c7f4e..a24ccad 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -3,24 +3,25 @@
 @using LibMatrix.EventTypes.Spec.State
 @using LibMatrix.Helpers
 @using LibMatrix.Homeservers
+@using LibMatrix.Responses
 @using LibMatrix.RoomTypes
 @using MatrixRoomUtils.Web.Classes.Constants
 @if (RoomInfo is not null) {
     <div class="roomListItem @(HasDangerousRoomVersion ? "dangerousRoomVersion" : HasOldRoomVersion ? "oldRoomVersion" : "")" id="@RoomInfo.Room.RoomId">
         @if (OwnMemberState != null) {
-            <img class="avatar32 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "") " @*@(ChildContent is not null ? "vcenter" : "")*@
+            <img class="avatar32 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "") @(ChildContent is not null ? "vcenter" : "")"
                  src="@(hs.ResolveMediaUri(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl) ?? "/icon-192.png")"/>
             <span class="centerVertical border75 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "")">
                 @(OwnMemberState?.DisplayName ?? GlobalProfile?.DisplayName ?? "Loading...")
             </span>
             <span class="centerVertical noLeftPadding">-></span>
         }
-        <img class="avatar32" src="@hs?.ResolveMediaUri(RoomInfo.RoomIcon)"/> @* style="@(ChildContent is not null ? "vertical-align: baseline;" : "")"*@
+        <img class="avatar32" src="@hs?.ResolveMediaUri(RoomInfo.RoomIcon)" style="@(ChildContent is not null ? "vertical-align: middle;" : "")"/>
         <div class="inlineBlock">
             <span class="centerVertical">@RoomInfo.RoomName</span>
-            @* @if (ChildContent is not null) { *@
-            @* @ChildContent *@
-            @* } *@
+            @if (ChildContent is not null) {
+                @ChildContent
+            }
         </div>
 
     </div>
@@ -31,8 +32,8 @@ else {
 
 @code {
 
-    // [Parameter]
-    // public RenderFragment? ChildContent { get; set; }
+    [Parameter]
+    public RenderFragment? ChildContent { get; set; }
 
     [Parameter]
     public RoomInfo? RoomInfo { get; set; }
@@ -44,7 +45,10 @@ else {
     public RoomMemberEventContent? OwnMemberState { get; set; }
 
     [CascadingParameter]
-    public ProfileResponseEventContent? GlobalProfile { get; set; }
+    public UserProfileResponse? GlobalProfile { get; set; }
+
+    [Parameter]
+    public bool LoadData { get; set; } = false;
 
     private bool HasOldRoomVersion { get; set; } = false;
     private bool HasDangerousRoomVersion { get; set; } = false;
@@ -57,6 +61,33 @@ else {
             Console.WriteLine(a.PropertyName);
             StateHasChanged();
         };
+
+        if (LoadData) {
+            try {
+                await RoomInfo.GetStateEvent("m.room.create");
+                if (ShowOwnProfile)
+                    OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.WhoAmI.UserId)).TypedContent as RoomMemberEventContent;
+
+                await RoomInfo.GetStateEvent("m.room.name");
+                await RoomInfo.GetStateEvent("m.room.avatar");
+            }
+            catch (MatrixException e) {
+                if (e.ErrorCode == "M_FORBIDDEN") {
+                    LoadData = false;
+                    RoomInfo.StateEvents.Add(new() {
+                        Type = "m.room.create",
+                        TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }
+                    });
+                    RoomInfo.StateEvents.Add(new() {
+                        Type = "m.room.name",
+                        TypedContent = new RoomNameEventContent() {
+                            Name = "M_FORBIDDEN: Are you a member of this room? " + RoomInfo.Room.RoomId
+                        }
+                    });
+                }
+            }
+        }
+
         await base.OnParametersSetAsync();
     }
 
@@ -69,7 +100,7 @@ else {
         if (hs is null) return;
 
         try {
-    await CheckRoomVersion();
+            await CheckRoomVersion();
     // await GetRoomInfo();
     // await LoadOwnProfile();
         }
@@ -139,4 +170,5 @@ else {
     //     }
     // }
 
-}
\ No newline at end of file
+}
+
diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
index a454103..075e402 100644
--- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
+++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor
@@ -1,5 +1,6 @@
 @using ArcaneLibs.Extensions
 @using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.Responses
 @inherits BaseTimelineItem
 
 @if (roomMemberData is not null) {
@@ -14,7 +15,7 @@
             <i>@Event.StateKey changed their display name to @(roomMemberData.DisplayName ?? Event.Sender)</i>
             break;
         case "join":
-            <i><InlineUserItem User="@(new ProfileResponseEventContent())" HomeServer="@Homeserver" UserId="@Event.StateKey"></InlineUserItem> joined</i>
+            <i><InlineUserItem User="@(new UserProfileResponse())" HomeServer="@Homeserver" UserId="@Event.StateKey"></InlineUserItem> joined</i>
             break;
         case "leave":
             <i>@Event.StateKey left</i>
diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor
index 96e8e64..167809e 100644
--- a/MatrixRoomUtils.Web/Shared/UserListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor
@@ -1,6 +1,7 @@
 @using LibMatrix.Helpers
 @using LibMatrix.EventTypes.Spec.State
 @using LibMatrix.Homeservers
+@using LibMatrix.Responses
 <div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content;">
     <img style="@(ChildContent is not null ? "vertical-align: baseline;" : "") width: 32px; height:  32px; border-radius: 50%;" src="@(string.IsNullOrWhiteSpace(User?.AvatarUrl) ? "https://api.dicebear.com/6.x/identicon/svg?seed=" + UserId : User.AvatarUrl)"/>
     <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px;">@User?.DisplayName</span>
@@ -19,7 +20,7 @@
     public RenderFragment? ChildContent { get; set; }
 
     [Parameter]
-    public ProfileResponseEventContent? User { get; set; }
+    public UserProfileResponse? User { get; set; }
 
     [Parameter]
     public string UserId { get; set; }