diff options
Diffstat (limited to '')
8 files changed, 43 insertions, 43 deletions
diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomAccountDataController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomAccountDataController.cs index bac803f..64d7353 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomAccountDataController.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomAccountDataController.cs @@ -38,7 +38,7 @@ public class RoomAccountDataController(ILogger<RoomAccountDataController> logger if (!room.AccountData.ContainsKey(user.UserId)) room.AccountData[user.UserId] = new(); - room.AccountData[user.UserId].Add(new StateEventResponse() { + room.AccountData[user.UserId].Add(new LegacyMatrixEventResponse() { Type = "m.fully_read", StateKey = user.UserId, RawContent = new() { @@ -46,7 +46,7 @@ public class RoomAccountDataController(ILogger<RoomAccountDataController> logger } }); - room.AccountData[user.UserId].Add(new StateEventResponse() { + room.AccountData[user.UserId].Add(new LegacyMatrixEventResponse() { Type = "m.read", StateKey = user.UserId, RawContent = new() { @@ -54,7 +54,7 @@ public class RoomAccountDataController(ILogger<RoomAccountDataController> logger } }); - room.AccountData[user.UserId].Add(new StateEventResponse() { + room.AccountData[user.UserId].Add(new LegacyMatrixEventResponse() { Type = "m.read.private", StateKey = user.UserId, RawContent = new() { diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomMembersController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomMembersController.cs index 7d735f7..6fbe696 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomMembersController.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomMembersController.cs @@ -13,7 +13,7 @@ public class RoomMembersController( RoomStore roomStore, PaginationTokenResolverService paginationTokenResolver) : ControllerBase { [HttpGet("members")] - public async Task<List<StateEventResponse>> GetMembers(string roomId, string? at = null, string? membership = null, string? not_membership = null) { + public async Task<List<LegacyMatrixEventResponse>> GetMembers(string roomId, string? at = null, string? membership = null, string? not_membership = null) { var token = tokenService.GetAccessTokenOrNull(HttpContext); if (token == null) throw new MatrixException() { @@ -44,7 +44,7 @@ public class RoomMembersController( members = members.Where(x => (x.TypedContent as RoomMemberEventContent)?.Membership != not_membership).ToList(); if (at != null) { - StateEventResponse? evt = null; + LegacyMatrixEventResponse? evt = null; if (at.StartsWith('$')) evt = await paginationTokenResolver.ResolveTokenToEvent(at, room); diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs index 74c70a3..dfe119f 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomStateController.cs @@ -10,7 +10,7 @@ namespace LibMatrix.HomeserverEmulator.Controllers.Rooms; [Route("/_matrix/client/{version}/rooms/{roomId}/state")] public class RoomStateController(ILogger<RoomStateController> logger, TokenService tokenService, UserStore userStore, RoomStore roomStore) : ControllerBase { [HttpGet("")] - public async Task<FrozenSet<StateEventResponse>> GetState(string roomId) { + public async Task<FrozenSet<LegacyMatrixEventResponse>> GetState(string roomId) { var token = tokenService.GetAccessTokenOrNull(HttpContext); if (token == null) throw new MatrixException() { @@ -103,7 +103,7 @@ public class RoomStateController(ILogger<RoomStateController> logger, TokenServi ErrorCode = "M_NOT_FOUND", Error = "Room not found" }; - var evt = room.SetStateInternal(new StateEvent() { Type = eventType, StateKey = stateKey, RawContent = request }.ToStateEvent(user, room)); + var evt = room.SetStateInternal(new LegacyMatrixEvent() { Type = eventType, StateKey = stateKey, RawContent = request }.ToStateEvent(user, room)); evt.Type = eventType; evt.StateKey = stateKey; return new EventIdResponse() { diff --git a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomTimelineController.cs b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomTimelineController.cs index afd69d1..b545b3f 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomTimelineController.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Controllers/Rooms/RoomTimelineController.cs @@ -39,7 +39,7 @@ public class RoomTimelineController( Error = "User is not in the room" }; - var evt = new StateEvent() { + var evt = new LegacyMatrixEvent() { RawContent = content, Type = eventType }.ToStateEvent(user, room); @@ -98,7 +98,7 @@ public class RoomTimelineController( } [HttpGet("event/{eventId}")] - public async Task<StateEventResponse> GetEvent(string roomId, string eventId) { + public async Task<LegacyMatrixEventResponse> GetEvent(string roomId, string eventId) { var token = tokenService.GetAccessToken(HttpContext); var user = await userStore.GetUserByToken(token); @@ -221,7 +221,7 @@ public class RoomTimelineController( }; } - private async Task<IEnumerable<StateEventResponse>> GetRelationsInternal(string roomId, string eventId, string dir, string? from, int? limit, bool? recurse, string? to) { + private async Task<IEnumerable<LegacyMatrixEventResponse>> GetRelationsInternal(string roomId, string eventId, string dir, string? from, int? limit, bool? recurse, string? to) { var room = roomStore.GetRoomById(roomId); var evt = room.Timeline.SingleOrDefault(x => x.EventId == eventId); if (evt == null) @@ -249,7 +249,7 @@ public class RoomTimelineController( private void InternalSendMessage(RoomStore.Room room, RoomMessageEventContent content) { logger.LogInformation("Sending internal message: {content}", content.Body); - room.Timeline.Add(new StateEventResponse() { + room.Timeline.Add(new LegacyMatrixEventResponse() { Type = RoomMessageEventContent.EventId, TypedContent = content, Sender = $"@hse:{tokenService.GenerateServerName(HttpContext)}", @@ -259,7 +259,7 @@ public class RoomTimelineController( }); } - private async Task HandleHseCommand(StateEventResponse evt, RoomStore.Room room, UserStore.User user) { + private async Task HandleHseCommand(LegacyMatrixEventResponse evt, RoomStore.Room room, UserStore.User user) { try { var msgContent = evt.TypedContent as RoomMessageEventContent; var parts = msgContent.Body.Split('\n')[0].Split(" "); @@ -323,7 +323,7 @@ public class RoomTimelineController( if (Random.Shared.Next(100) > 75) { crq.CreationContent["type"] = "m.space"; foreach (var item in Random.Shared.GetItems(roomStore._rooms.ToArray(), 50)) { - crq.InitialState!.Add(new StateEvent() { + crq.InitialState!.Add(new LegacyMatrixEvent() { Type = "m.space.child", StateKey = item.RoomId, TypedContent = new SpaceChildEventContent() { @@ -358,7 +358,7 @@ public class RoomTimelineController( } } - private async Task HandleImportNhekoProfilesCommand(string[] args, StateEventResponse evt, RoomStore.Room room, UserStore.User user) { + private async Task HandleImportNhekoProfilesCommand(string[] args, LegacyMatrixEventResponse evt, RoomStore.Room room, UserStore.User user) { var msgContent = evt.TypedContent as RoomMessageEventContent; var parts = msgContent.Body.Split('\n'); @@ -396,7 +396,7 @@ public class RoomTimelineController( } } - private async Task HandleImportCommand(string[] args, StateEventResponse evt, RoomStore.Room room, UserStore.User user) { + private async Task HandleImportCommand(string[] args, LegacyMatrixEventResponse evt, RoomStore.Room room, UserStore.User user) { var roomId = args[0]; var profile = args[1]; diff --git a/Tests/LibMatrix.HomeserverEmulator/Extensions/EventExtensions.cs b/Tests/LibMatrix.HomeserverEmulator/Extensions/EventExtensions.cs index d938b1b..a4c6aa8 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Extensions/EventExtensions.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Extensions/EventExtensions.cs @@ -3,19 +3,19 @@ using LibMatrix.HomeserverEmulator.Services; namespace LibMatrix.HomeserverEmulator.Extensions; public static class EventExtensions { - public static StateEventResponse ToStateEvent(this StateEvent stateEvent, UserStore.User user, RoomStore.Room room) { - return new StateEventResponse { - RawContent = stateEvent.RawContent, + public static LegacyMatrixEventResponse ToStateEvent(this LegacyMatrixEvent legacyMatrixEvent, UserStore.User user, RoomStore.Room room) { + return new LegacyMatrixEventResponse { + RawContent = legacyMatrixEvent.RawContent, EventId = "$" + string.Join("", Random.Shared.GetItems("abcdefghijklmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789".ToCharArray(), 100)), RoomId = room.RoomId, Sender = user.UserId, - StateKey = stateEvent.StateKey, - Type = stateEvent.Type, + StateKey = legacyMatrixEvent.StateKey, + Type = legacyMatrixEvent.Type, OriginServerTs = DateTimeOffset.Now.ToUnixTimeMilliseconds() }; } - public static List<StateEventResponse> GetCalculatedState(this IEnumerable<StateEventResponse> events) { + public static List<LegacyMatrixEventResponse> GetCalculatedState(this IEnumerable<LegacyMatrixEventResponse> events) { return events.Where(s => s.StateKey != null) .OrderByDescending(s => s.OriginServerTs) .DistinctBy(x => (x.Type, x.StateKey)) diff --git a/Tests/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs b/Tests/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs index 0128ba6..6bc5a33 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs @@ -35,7 +35,7 @@ public class PaginationTokenResolverService(ILogger<PaginationTokenResolverServi } } - public async Task<StateEventResponse?> ResolveTokenToEvent(string token, RoomStore.Room room) { + public async Task<LegacyMatrixEventResponse?> ResolveTokenToEvent(string token, RoomStore.Room room) { if (token.StartsWith('$')) { //we have an event ID logger.LogTrace("ResolveTokenToEvent(EventId({token}), Room({room})): searching for event...", token, room.RoomId); diff --git a/Tests/LibMatrix.HomeserverEmulator/Services/RoomStore.cs b/Tests/LibMatrix.HomeserverEmulator/Services/RoomStore.cs index 5cdc3ab..e0b6552 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Services/RoomStore.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Services/RoomStore.cs @@ -69,7 +69,7 @@ public class RoomStore { public Room CreateRoom(CreateRoomRequest request, UserStore.User? user = null) { var room = new Room(roomId: $"!{Guid.NewGuid().ToString()}"); - var newCreateEvent = new StateEvent() { + var newCreateEvent = new LegacyMatrixEvent() { Type = RoomCreateEventContent.EventId, RawContent = new() { } }; @@ -95,7 +95,7 @@ public class RoomStore { } if (!string.IsNullOrWhiteSpace(request.Name)) - room.SetStateInternal(new StateEvent() { + room.SetStateInternal(new LegacyMatrixEvent() { Type = RoomNameEventContent.EventId, TypedContent = new RoomNameEventContent() { Name = request.Name @@ -103,7 +103,7 @@ public class RoomStore { }); if (!string.IsNullOrWhiteSpace(request.RoomAliasName)) - room.SetStateInternal(new StateEvent() { + room.SetStateInternal(new LegacyMatrixEvent() { Type = RoomCanonicalAliasEventContent.EventId, TypedContent = new RoomCanonicalAliasEventContent() { Alias = $"#{request.RoomAliasName}:localhost" @@ -129,10 +129,10 @@ public class RoomStore { public class Room : NotifyPropertyChanged { private CancellationTokenSource _debounceCts = new(); - private ObservableCollection<StateEventResponse> _timeline; - private ObservableDictionary<string, List<StateEventResponse>> _accountData; + private ObservableCollection<LegacyMatrixEventResponse> _timeline; + private ObservableDictionary<string, List<LegacyMatrixEventResponse>> _accountData; private ObservableDictionary<string, ReadMarkersData> _readMarkers; - private FrozenSet<StateEventResponse> _stateCache; + private FrozenSet<LegacyMatrixEventResponse> _stateCache; private int _timelineHash; public Room(string roomId) { @@ -146,9 +146,9 @@ public class RoomStore { public string RoomId { get; set; } - public FrozenSet<StateEventResponse> State => _timelineHash == _timeline.GetHashCode() ? _stateCache : RebuildState(); + public FrozenSet<LegacyMatrixEventResponse> State => _timelineHash == _timeline.GetHashCode() ? _stateCache : RebuildState(); - public ObservableCollection<StateEventResponse> Timeline { + public ObservableCollection<LegacyMatrixEventResponse> Timeline { get => _timeline; set { if (Equals(value, _timeline)) return; @@ -171,7 +171,7 @@ public class RoomStore { } } - public ObservableDictionary<string, List<StateEventResponse>> AccountData { + public ObservableDictionary<string, List<LegacyMatrixEventResponse>> AccountData { get => _accountData; set { if (Equals(value, _accountData)) return; @@ -181,7 +181,7 @@ public class RoomStore { } } - public ImmutableList<StateEventResponse> JoinedMembers => + public ImmutableList<LegacyMatrixEventResponse> JoinedMembers => State.Where(s => s is { Type: RoomMemberEventContent.EventId, TypedContent: RoomMemberEventContent { Membership: "join" } }).ToImmutableList(); public ObservableDictionary<string, ReadMarkersData> ReadMarkers { @@ -194,8 +194,8 @@ public class RoomStore { } } - internal StateEventResponse SetStateInternal(StateEvent request, string? senderId = null, UserStore.User? user = null) { - var state = request as StateEventResponse ?? new StateEventResponse() { + internal LegacyMatrixEventResponse SetStateInternal(LegacyMatrixEvent request, string? senderId = null, UserStore.User? user = null) { + var state = request as LegacyMatrixEventResponse ?? new LegacyMatrixEventResponse() { Type = request.Type, StateKey = request.StateKey ?? "", EventId = "$" + Guid.NewGuid().ToString(), @@ -212,7 +212,7 @@ public class RoomStore { return state; } - public StateEventResponse AddUser(string userId) { + public LegacyMatrixEventResponse AddUser(string userId) { var state = SetStateInternal(new() { Type = RoomMemberEventContent.EventId, StateKey = userId, @@ -258,15 +258,15 @@ public class RoomStore { private SemaphoreSlim stateRebuildSemaphore = new(1, 1); - private FrozenSet<StateEventResponse> RebuildState() { + private FrozenSet<LegacyMatrixEventResponse> RebuildState() { stateRebuildSemaphore.Wait(); while (true) try { Console.WriteLine($"Rebuilding state for room {RoomId}"); // ReSharper disable once RedundantEnumerableCastCall - This sometimes happens when the collection is modified during enumeration - List<StateEventResponse>? timeline = null; + List<LegacyMatrixEventResponse>? timeline = null; lock (_timeline) { - timeline = Timeline.OfType<StateEventResponse>().ToList(); + timeline = Timeline.OfType<LegacyMatrixEventResponse>().ToList(); } foreach (var evt in timeline) { @@ -297,7 +297,7 @@ public class RoomStore { } } - public List<StateEventResponse> GetRoomsByMember(string userId) { + public List<LegacyMatrixEventResponse> GetRoomsByMember(string userId) { // return _rooms // // .Where(r => r.State.Any(s => s.Type == RoomMemberEventContent.EventId && s.StateKey == userId)) // .Select(r => (Room: r, MemberEvent: r.State.SingleOrDefault(s => s.Type == RoomMemberEventContent.EventId && s.StateKey == userId))) diff --git a/Tests/LibMatrix.HomeserverEmulator/Services/UserStore.cs b/Tests/LibMatrix.HomeserverEmulator/Services/UserStore.cs index 4ce9f92..7b2c07c 100644 --- a/Tests/LibMatrix.HomeserverEmulator/Services/UserStore.cs +++ b/Tests/LibMatrix.HomeserverEmulator/Services/UserStore.cs @@ -71,13 +71,13 @@ public class UserStore { var user = new User() { UserId = userId, AccountData = new() { - new StateEventResponse() { + new LegacyMatrixEventResponse() { Type = "im.vector.analytics", RawContent = new JsonObject() { ["pseudonymousAnalyticsOptIn"] = false }, }, - new StateEventResponse() { + new LegacyMatrixEventResponse() { Type = "im.vector.web.settings", RawContent = new JsonObject() { ["developerMode"] = true @@ -116,7 +116,7 @@ public class UserStore { private ObservableDictionary<string, SessionInfo> _accessTokens; private ObservableDictionary<string, SyncFilter> _filters; private ObservableDictionary<string, object> _profile; - private ObservableCollection<StateEventResponse> _accountData; + private ObservableCollection<LegacyMatrixEventResponse> _accountData; private ObservableDictionary<string, RoomKeysResponse> _roomKeys; private ObservableDictionary<string, AuthorizedSession> _authorizedSessions; @@ -155,7 +155,7 @@ public class UserStore { } } - public ObservableCollection<StateEventResponse> AccountData { + public ObservableCollection<LegacyMatrixEventResponse> AccountData { get => _accountData; set { if (value == _accountData) return; |