about summary refs log tree commit diff
path: root/Utilities/LibMatrix.HomeserverEmulator/Services
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-11-16 03:33:00 +0100
committerRory& <root@rory.gay>2024-11-16 03:33:00 +0100
commit652cabb51294064f51b6459f000c75941f412a27 (patch)
tree653448091fb00175db72806825d8712512a2c5c0 /Utilities/LibMatrix.HomeserverEmulator/Services
parentUpdate to .NET 9 (diff)
downloadLibMatrix-652cabb51294064f51b6459f000c75941f412a27.tar.xz
HSE updates
Diffstat (limited to 'Utilities/LibMatrix.HomeserverEmulator/Services')
-rw-r--r--Utilities/LibMatrix.HomeserverEmulator/Services/HSEConfiguration.cs2
-rw-r--r--Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs31
2 files changed, 29 insertions, 4 deletions
diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/HSEConfiguration.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/HSEConfiguration.cs

index 73b0d23..bcfb629 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/HSEConfiguration.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/HSEConfiguration.cs
@@ -27,6 +27,8 @@ public class HSEConfiguration { public string DataStoragePath { get; set; } public bool StoreData { get; set; } = true; + + public string ServerName { get; set; } = "localhost"; public bool UnknownSyncTokenIsInitialSync { get; set; } = true; diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs
index 4ce9f92..4684b01 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/UserStore.cs
@@ -13,9 +13,11 @@ namespace LibMatrix.HomeserverEmulator.Services; public class UserStore { public ConcurrentBag<User> _users = new(); + private readonly HSEConfiguration _config; private readonly RoomStore _roomStore; public UserStore(HSEConfiguration config, RoomStore roomStore) { + _config = config; _roomStore = roomStore; if (config.StoreData) { var dataDir = Path.Combine(HSEConfiguration.Current.DataStoragePath, "users"); @@ -64,12 +66,15 @@ public class UserStore { }; } - public async Task<User> CreateUser(string userId, Dictionary<string, object>? profile = null) { + public async Task<User> CreateUser(string userId, Dictionary<string, object>? profile = null, string kind = "user") { profile ??= new(); - if (!profile.ContainsKey("displayname")) profile.Add("displayname", userId.Split(":")[0]); + var parts = userId.Split(":"); + var localPart = parts[0].TrimStart('@'); + if (!profile.ContainsKey("displayname")) profile.Add("displayname", localPart); if (!profile.ContainsKey("avatar_url")) profile.Add("avatar_url", null); var user = new User() { - UserId = userId, + UserId = $"@{localPart}:{_config.ServerName}", + IsGuest = kind == "guest", AccountData = new() { new StateEventResponse() { Type = "im.vector.analytics", @@ -80,7 +85,22 @@ public class UserStore { new StateEventResponse() { Type = "im.vector.web.settings", RawContent = new JsonObject() { - ["developerMode"] = true + ["developerMode"] = true, + ["alwaysShowTimestamps"] = true, + ["SpotlightSearch.showNsfwPublicRooms"] = true, + + } + }, + new() { + Type = "im.vector.setting.integration_provisioning", + RawContent = new JsonObject() { + ["enabled"] = false + } + }, + new() { + Type = "m.identity_server", + RawContent = new JsonObject() { + ["base_url"] = null } }, } @@ -185,6 +205,8 @@ public class UserStore { } } + public bool IsGuest { get; set; } + public async Task SaveDebounced() { if (!HSEConfiguration.Current.StoreData) return; await _debounceCts.CancelAsync(); @@ -205,6 +227,7 @@ public class UserStore { public class SessionInfo { public string DeviceId { get; set; } = Guid.NewGuid().ToString(); + public string DeviceName { get; set; } = "Unnamed device"; public Dictionary<string, UserSyncState> SyncStates { get; set; } = new(); public class UserSyncState {