From 3558ba25896876b0c546f4c2decbb0671187745b Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 14 Nov 2025 10:48:26 +0100 Subject: StateEvent -> MatrixEvent --- .../Services/PaginationTokenResolverService.cs | 4 +-- .../Services/RoomStore.cs | 36 +++++++++++----------- .../Services/UserStore.cs | 9 +++--- 3 files changed, 24 insertions(+), 25 deletions(-) (limited to 'Utilities/LibMatrix.HomeserverEmulator/Services') diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs index 0603a2d..7324bd8 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/PaginationTokenResolverService.cs @@ -35,7 +35,7 @@ public class PaginationTokenResolverService(ILogger ResolveTokenToEvent(string token, RoomStore.Room room) { + public Task 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); @@ -43,7 +43,7 @@ public class PaginationTokenResolverService(ILogger x.EventId == token); if (evt is not null) return Task.FromResult(evt); logger.LogTrace("ResolveTokenToEvent({token}, Room({room})): event not in requested room...", token, room.RoomId); - return Task.FromResult(null); + return Task.FromResult(null); } else { // we have a sync token diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs index b6fe7c2..232863f 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs @@ -51,7 +51,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 MatrixEvent() { Type = RoomCreateEventContent.EventId, RawContent = new() }; @@ -78,7 +78,7 @@ public class RoomStore { } if (!string.IsNullOrWhiteSpace(request.Name)) - room.SetStateInternal(new StateEvent() { + room.SetStateInternal(new MatrixEvent() { Type = RoomNameEventContent.EventId, TypedContent = new RoomNameEventContent() { Name = request.Name @@ -86,7 +86,7 @@ public class RoomStore { }); if (!string.IsNullOrWhiteSpace(request.RoomAliasName)) - room.SetStateInternal(new StateEvent() { + room.SetStateInternal(new MatrixEvent() { Type = RoomCanonicalAliasEventContent.EventId, TypedContent = new RoomCanonicalAliasEventContent() { Alias = $"#{request.RoomAliasName}:localhost" @@ -112,10 +112,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) { @@ -129,9 +129,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; @@ -140,7 +140,7 @@ public class RoomStore { // we dont want to do this as it's rebuilt when the state is accessed // if (args.Action == NotifyCollectionChangedAction.Add) { - // foreach (StateEventResponse state in args.NewItems) { + // foreach (MatrixEventResponse state in args.NewItems) { // if (state.StateKey is not null) // // we want state to be deduplicated by type and key, and we want the latest state to be the one that is returned // RebuildState(); @@ -154,7 +154,7 @@ public class RoomStore { } } - public ObservableDictionary> AccountData { + public ObservableDictionary> AccountData { get => _accountData; set { if (Equals(value, _accountData)) return; @@ -164,7 +164,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 { @@ -177,8 +177,8 @@ public class RoomStore { } } - internal StateEventResponse SetStateInternal(StateEvent request, string? senderId = null, UserStore.User? user = null) { - var state = request as StateEventResponse ?? new StateEventResponse() { + internal MatrixEventResponse SetStateInternal(MatrixEvent request, string? senderId = null, UserStore.User? user = null) { + var state = request as MatrixEventResponse ?? new MatrixEventResponse() { Type = request.Type, StateKey = request.StateKey ?? "", EventId = "$" + Guid.NewGuid().ToString(), @@ -195,7 +195,7 @@ public class RoomStore { return state; } - public StateEventResponse AddUser(string userId) { + public MatrixEventResponse AddUser(string userId) { var state = SetStateInternal(new() { Type = RoomMemberEventContent.EventId, StateKey = userId, @@ -245,15 +245,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) { @@ -284,7 +284,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))) diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs index 7f211e3..124a082 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs @@ -75,19 +75,18 @@ public class UserStore { UserId = $"@{localPart}:{_config.ServerName}", IsGuest = kind == "guest", AccountData = new() { - new StateEventResponse() { + new MatrixEventResponse() { Type = "im.vector.analytics", RawContent = new JsonObject() { ["pseudonymousAnalyticsOptIn"] = false }, }, - new StateEventResponse() { + new MatrixEventResponse() { Type = "im.vector.web.settings", RawContent = new JsonObject() { ["developerMode"] = true, ["alwaysShowTimestamps"] = true, ["SpotlightSearch.showNsfwPublicRooms"] = true, - } }, new() { @@ -135,7 +134,7 @@ public class UserStore { private ObservableDictionary _accessTokens; private ObservableDictionary _filters; private ObservableDictionary _profile; - private ObservableCollection _accountData; + private ObservableCollection _accountData; private ObservableDictionary _roomKeys; private ObservableDictionary _authorizedSessions; @@ -174,7 +173,7 @@ public class UserStore { } } - public ObservableCollection AccountData { + public ObservableCollection AccountData { get => _accountData; set { if (value == _accountData) return; -- cgit 1.5.1