From ae18c049338dfcb33f721eeeb0a05571e8bd87a9 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 08:02:40 +0000 Subject: Rename StateEvent to LegacyMatrixEvent --- .../Services/RoomStore.cs | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'Tests/LibMatrix.HomeserverEmulator/Services/RoomStore.cs') 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 _timeline; - private ObservableDictionary> _accountData; + private ObservableCollection _timeline; + private ObservableDictionary> _accountData; private ObservableDictionary _readMarkers; - private FrozenSet _stateCache; + private FrozenSet _stateCache; private int _timelineHash; public Room(string roomId) { @@ -146,9 +146,9 @@ public class RoomStore { public string RoomId { get; set; } - public FrozenSet State => _timelineHash == _timeline.GetHashCode() ? _stateCache : RebuildState(); + public FrozenSet State => _timelineHash == _timeline.GetHashCode() ? _stateCache : RebuildState(); - public ObservableCollection Timeline { + public ObservableCollection Timeline { get => _timeline; set { if (Equals(value, _timeline)) return; @@ -171,7 +171,7 @@ public class RoomStore { } } - public ObservableDictionary> AccountData { + public ObservableDictionary> AccountData { get => _accountData; set { if (Equals(value, _accountData)) return; @@ -181,7 +181,7 @@ public class RoomStore { } } - public ImmutableList JoinedMembers => + public ImmutableList JoinedMembers => State.Where(s => s is { Type: RoomMemberEventContent.EventId, TypedContent: RoomMemberEventContent { Membership: "join" } }).ToImmutableList(); public ObservableDictionary 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 RebuildState() { + private FrozenSet 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? timeline = null; + List? timeline = null; lock (_timeline) { - timeline = Timeline.OfType().ToList(); + timeline = Timeline.OfType().ToList(); } foreach (var evt in timeline) { @@ -297,7 +297,7 @@ public class RoomStore { } } - public List GetRoomsByMember(string userId) { + public List 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))) -- cgit 1.4.1