From 03313562d21d5db9bf6a14ebbeab80e06c883d3a Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 24 Jan 2024 02:31:56 +0100 Subject: MRU->RMU, fixes, cleanup --- MatrixRoomUtils.LibDMSpace/DMSpaceConfiguration.cs | 12 ---- MatrixRoomUtils.LibDMSpace/DMSpaceRoom.cs | 83 ---------------------- .../MatrixRoomUtils.LibDMSpace.csproj | 15 ---- .../StateEvents/DMRoomInfo.cs | 14 ---- .../StateEvents/DMSpaceInfo.cs | 14 ---- 5 files changed, 138 deletions(-) delete mode 100644 MatrixRoomUtils.LibDMSpace/DMSpaceConfiguration.cs delete mode 100644 MatrixRoomUtils.LibDMSpace/DMSpaceRoom.cs delete mode 100644 MatrixRoomUtils.LibDMSpace/MatrixRoomUtils.LibDMSpace.csproj delete mode 100644 MatrixRoomUtils.LibDMSpace/StateEvents/DMRoomInfo.cs delete mode 100644 MatrixRoomUtils.LibDMSpace/StateEvents/DMSpaceInfo.cs (limited to 'MatrixRoomUtils.LibDMSpace') diff --git a/MatrixRoomUtils.LibDMSpace/DMSpaceConfiguration.cs b/MatrixRoomUtils.LibDMSpace/DMSpaceConfiguration.cs deleted file mode 100644 index dcb7098..0000000 --- a/MatrixRoomUtils.LibDMSpace/DMSpaceConfiguration.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace MatrixRoomUtils.LibDMSpace; - -//gay.rory.dm_space -public class DMSpaceConfiguration { - public const string EventId = "gay.rory.dm_space"; - - [JsonPropertyName("dm_space_id")] - public string? DMSpaceId { get; set; } - -} diff --git a/MatrixRoomUtils.LibDMSpace/DMSpaceRoom.cs b/MatrixRoomUtils.LibDMSpace/DMSpaceRoom.cs deleted file mode 100644 index 1cf7064..0000000 --- a/MatrixRoomUtils.LibDMSpace/DMSpaceRoom.cs +++ /dev/null @@ -1,83 +0,0 @@ -using ArcaneLibs.Extensions; -using LibMatrix; -using LibMatrix.Homeservers; -using LibMatrix.RoomTypes; -using MatrixRoomUtils.LibDMSpace.StateEvents; - -namespace MatrixRoomUtils.LibDMSpace; - -public class DMSpaceRoom(AuthenticatedHomeserverGeneric homeserver, string roomId) : SpaceRoom(homeserver, roomId) { - private readonly GenericRoom _room; - - public async Task GetDmSpaceInfo() { - return await GetStateOrNullAsync(DMSpaceInfo.EventId); - } - - public async IAsyncEnumerable GetChildrenAsync(bool includeRemoved = false) { - var rooms = new List(); - var state = GetFullStateAsync(); - await foreach (var stateEvent in state) { - if (stateEvent!.Type != "m.space.child") continue; - if (stateEvent.RawContent!.ToJson() != "{}" || includeRemoved) - yield return homeserver.GetRoom(stateEvent.StateKey); - } - } - - public async Task AddChildAsync(GenericRoom room) { - var members = room.GetMembersEnumerableAsync(true); - Dictionary memberCountByHs = new(); - await foreach (var member in members) { - var server = member.StateKey.Split(':')[1]; - if (memberCountByHs.ContainsKey(server)) memberCountByHs[server]++; - else memberCountByHs[server] = 1; - } - - var resp = await SendStateEventAsync("m.space.child", room.RoomId, new { - via = memberCountByHs - .OrderByDescending(x => x.Value) - .Select(x => x.Key) - .Take(10) - }); - return resp; - } - - public async Task ImportNativeDMs() { - var dmSpaceInfo = await GetDmSpaceInfo(); - if (dmSpaceInfo is null) throw new NullReferenceException("DM Space is not configured!"); - if (dmSpaceInfo.LayerByUser) - await ImportNativeDMsIntoLayers(); - else await ImportNativeDMsWithoutLayers(); - } - - #region Import Native DMs - - private async Task ImportNativeDMsWithoutLayers() { - var mdirect = await homeserver.GetAccountDataAsync>>("m.direct"); - foreach (var (userId, dmRooms) in mdirect) { - foreach (var roomid in dmRooms) { - var dri = new DMRoomInfo() { - RemoteUsers = new() { - userId - } - }; - // Add all DM room members - var members = homeserver.GetRoom(roomid).GetMembersEnumerableAsync(); - await foreach (var member in members) - if (member.StateKey != userId) - dri.RemoteUsers.Add(member.StateKey); - // Remove members of DM space - members = GetMembersEnumerableAsync(); - await foreach (var member in members) - if (dri.RemoteUsers.Contains(member.StateKey)) - dri.RemoteUsers.Remove(member.StateKey); - await SendStateEventAsync(DMRoomInfo.EventId, roomid, dri); - } - } - } - - private async Task ImportNativeDMsIntoLayers() { - var mdirect = await homeserver.GetAccountDataAsync>>("m.direct"); - } - - #endregion -} diff --git a/MatrixRoomUtils.LibDMSpace/MatrixRoomUtils.LibDMSpace.csproj b/MatrixRoomUtils.LibDMSpace/MatrixRoomUtils.LibDMSpace.csproj deleted file mode 100644 index 72c1666..0000000 --- a/MatrixRoomUtils.LibDMSpace/MatrixRoomUtils.LibDMSpace.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net8.0 - enable - enable - true - preview - true - - - - - - diff --git a/MatrixRoomUtils.LibDMSpace/StateEvents/DMRoomInfo.cs b/MatrixRoomUtils.LibDMSpace/StateEvents/DMRoomInfo.cs deleted file mode 100644 index 716a3ac..0000000 --- a/MatrixRoomUtils.LibDMSpace/StateEvents/DMRoomInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.EventTypes; -using LibMatrix.Interfaces; - -namespace MatrixRoomUtils.LibDMSpace.StateEvents; - -[MatrixEvent(EventName = EventId)] -public class DMRoomInfo : TimelineEventContent { - public const string EventId = "gay.rory.dm_room_info"; - [JsonPropertyName("remote_users")] - public List RemoteUsers { get; set; } - - -} diff --git a/MatrixRoomUtils.LibDMSpace/StateEvents/DMSpaceInfo.cs b/MatrixRoomUtils.LibDMSpace/StateEvents/DMSpaceInfo.cs deleted file mode 100644 index 26e2b90..0000000 --- a/MatrixRoomUtils.LibDMSpace/StateEvents/DMSpaceInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.EventTypes; -using LibMatrix.Interfaces; - -namespace MatrixRoomUtils.LibDMSpace.StateEvents; - -[MatrixEvent(EventName = EventId)] -public class DMSpaceInfo : TimelineEventContent { - public const string EventId = "gay.rory.dm_space_info"; - - [JsonPropertyName("is_layered")] - public bool LayerByUser { get; set; } - -} -- cgit 1.5.1