diff --git a/ArcaneLibs b/ArcaneLibs
-Subproject f0f37be308ce87f55c7299f08c8ce5077b057c8
+Subproject c8d11c9c6f7aa2a0eb86c24c1a7bbdad4928a3e
diff --git a/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs b/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs
new file mode 100644
index 0000000..4fd5c29
--- /dev/null
+++ b/LibMatrix.EventTypes/Common/Msc2545EmoteRoomsAccountDataEventContent.cs
@@ -0,0 +1,31 @@
+using System.Text.Json;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.EventTypes.Spec;
+
+[MatrixEvent(EventName = EventId)]
+public class Msc2545EmoteRoomsAccountDataEventContent : EventContent {
+ public const string EventId = "im.ponies.emote_rooms";
+
+ [JsonPropertyName("rooms")]
+ public Dictionary<string, Dictionary<string, EnabledEmotePackEntry>> Rooms { get; set; } = new();
+
+ // Dummy type to provide easy access to the by-spec empty content
+ public class EnabledEmotePackEntry {
+ [JsonExtensionData]
+ public Dictionary<string, object>? AdditionalData { get; set; } = [];
+
+ public T? GetAdditionalData<T>(string key) where T : class {
+ if (AdditionalData == null || !AdditionalData.TryGetValue(key, out var value))
+ return null;
+
+ if (value is T tValue)
+ return tValue;
+ if (value is JsonElement jsonElement)
+ return jsonElement.Deserialize<T>();
+
+ throw new InvalidCastException($"Value for key '{key}' ({value.GetType()}) cannot be cast to type '{typeof(T)}'. Cannot continue.");
+ }
+ }
+}
\ No newline at end of file
diff --git a/LibMatrix/Extensions/MatrixHttpClient.Single.cs b/LibMatrix/Extensions/MatrixHttpClient.Single.cs
index 26fb31f..aa188dd 100644
--- a/LibMatrix/Extensions/MatrixHttpClient.Single.cs
+++ b/LibMatrix/Extensions/MatrixHttpClient.Single.cs
@@ -55,6 +55,10 @@ public class MatrixHttpClient {
public Dictionary<string, string> AdditionalQueryParameters { get; set; } = new();
public Uri? BaseAddress { get; set; }
+ public bool RetryOnNetworkError { get; set; } = true;
+ public bool RetryOnMatrixError { get; set; } = true;
+
+ private Dictionary<HttpRequestMessage, int> _retries = [];
// default headers, not bound to client
public HttpRequestHeaders DefaultRequestHeaders { get; set; } =
@@ -151,8 +155,37 @@ public class MatrixHttpClient {
}
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) {
- var responseMessage = await SendUnhandledAsync(request, cancellationToken);
- if (responseMessage.IsSuccessStatusCode) return responseMessage;
+ _retries.TryAdd(request, 10);
+ HttpResponseMessage responseMessage;
+ try {
+ responseMessage = await SendUnhandledAsync(request, cancellationToken);
+ }
+ catch (HttpRequestException ex) {
+ if (RetryOnNetworkError) {
+ if (_retries[request]-- <= 0) throw;
+ if (ex.InnerException?.GetType().FullName == "System.Runtime.InteropServices.JavaScript.JSException")
+ Console.WriteLine("Got JSException, likely a CORS error due to a reverse proxy misconfiguration and error, retrying...");
+ else
+ Console.WriteLine(new {
+ ex.HttpRequestError,
+ ex.StatusCode,
+ ex.Data,
+ ex.Message,
+ InnerException = ex.InnerException?.ToString(),
+ InnerExceptionType = ex.InnerException?.GetType().FullName
+ }.ToJson());
+
+ await Task.Delay(Random.Shared.Next(1000, 2000), cancellationToken);
+ request.ResetSendStatus();
+ return await SendAsync(request, cancellationToken);
+ }
+ throw;
+ }
+
+ if (responseMessage.IsSuccessStatusCode) {
+ _retries.Remove(request);
+ return responseMessage;
+ }
//retry on gateway timeout
// if (responseMessage.StatusCode == HttpStatusCode.GatewayTimeout) {
@@ -192,14 +225,19 @@ public class MatrixHttpClient {
request.ResetSendStatus();
return await SendAsync(request, cancellationToken);
}
+
throw ex;
}
if (responseMessage.StatusCode == HttpStatusCode.BadGateway) {
// spread out retries
- await Task.Delay(Random.Shared.Next(1000, 2000), cancellationToken);
- request.ResetSendStatus();
- return await SendAsync(request, cancellationToken);
+ if (RetryOnNetworkError) {
+ if (_retries[request]-- <= 0) throw new InvalidDataException("Encountered invalid data:\n" + content);
+ Console.WriteLine("Got 502 Bad Gateway, retrying...");
+ await Task.Delay(Random.Shared.Next(1000, 2000), cancellationToken);
+ request.ResetSendStatus();
+ return await SendAsync(request, cancellationToken);
+ }
}
responseMessage.EnsureSuccessStatusCode();
diff --git a/LibMatrix/Helpers/RoomBuilder.cs b/LibMatrix/Helpers/RoomBuilder.cs
index 0b0b5f8..6e24103 100644
--- a/LibMatrix/Helpers/RoomBuilder.cs
+++ b/LibMatrix/Helpers/RoomBuilder.cs
@@ -83,7 +83,15 @@ public class RoomBuilder {
{ RoomPowerLevelEventContent.EventId, 100 },
{ RoomServerAclEventContent.EventId, 100 },
{ RoomTombstoneEventContent.EventId, 150 },
- { RoomPolicyServerEventContent.EventId, 100 }
+ { RoomPolicyServerEventContent.EventId, 100 },
+ { RoomPinnedEventContent.EventId, 50 },
+ // recommended extensions
+ { "im.vector.modular.widgets", 50},
+ // { "m.reaction", 0 }, // we probably don't want these to end up as room state
+ // - prevent calls
+ { "io.element.voice_broadcast_info", 50 },
+ { "org.matrix.msc3401.call", 50 },
+ { "org.matrix.msc3401.call.member", 50 },
}
};
diff --git a/LibMatrix/LibMatrix.csproj b/LibMatrix/LibMatrix.csproj
index c1049b5..c6c1dce 100644
--- a/LibMatrix/LibMatrix.csproj
+++ b/LibMatrix/LibMatrix.csproj
@@ -12,8 +12,8 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
- <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.9" />
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.9" />
<ProjectReference Include="..\LibMatrix.EventTypes\LibMatrix.EventTypes.csproj"/>
</ItemGroup>
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs
index 0077acb..58e5434 100644
--- a/LibMatrix/RoomTypes/GenericRoom.cs
+++ b/LibMatrix/RoomTypes/GenericRoom.cs
@@ -704,6 +704,18 @@ public class GenericRoom {
}
public async Task<List<string>> GetHomeserversInRoom() => (await GetMemberIdsListAsync("join")).Select(x => x.Split(':', 2)[1]).Distinct().ToList();
+
+ public async Task<bool> IsJoinedAsync() {
+ try {
+ var member = await GetStateOrNullAsync<RoomMemberEventContent>(RoomMemberEventContent.EventId, Homeserver.UserId);
+ return member?.Membership == "join";
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode == "M_NOT_FOUND") return false;
+ if (e.ErrorCode == "M_FORBIDDEN") return false;
+ throw;
+ }
+ }
}
public class RoomIdResponse {
diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs
index c984c34..52aadd2 100644
--- a/LibMatrix/Services/HomeserverProviderService.cs
+++ b/LibMatrix/Services/HomeserverProviderService.cs
@@ -17,7 +17,7 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger
if (!enableClient && !enableServer)
throw new ArgumentException("At least one of enableClient or enableServer must be true");
- return await AuthenticatedHomeserverCache.GetOrAdd($"{homeserver}{accessToken}{proxy}{impersonatedMxid}", async () => {
+ return await AuthenticatedHomeserverCache.GetOrAdd($"{homeserver}{accessToken}{proxy}{impersonatedMxid}{useGeneric}{enableClient}{enableServer}", async () => {
var wellKnownUris = await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableClient, enableServer);
var rhs = new RemoteHomeserver(homeserver, wellKnownUris, proxy);
diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs
index 94a3826..7d30b7b 100644
--- a/LibMatrix/Services/HomeserverResolverService.cs
+++ b/LibMatrix/Services/HomeserverResolverService.cs
@@ -9,7 +9,9 @@ using Microsoft.Extensions.Logging.Abstractions;
namespace LibMatrix.Services;
public class HomeserverResolverService {
- private readonly MatrixHttpClient _httpClient = new();
+ private readonly MatrixHttpClient _httpClient = new() {
+ RetryOnNetworkError = false
+ };
private static readonly SemaphoreCache<WellKnownUris> WellKnownCache = new();
diff --git a/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj b/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj
index 92da98f..1e61742 100644
--- a/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj
+++ b/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj
@@ -9,8 +9,8 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
- <PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
+ <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
</ItemGroup>
<ItemGroup>
diff --git a/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs b/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
index fdc7717..1339f23 100644
--- a/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
+++ b/Utilities/LibMatrix.DevTestBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs
@@ -42,7 +42,7 @@ public class ServerRoomSizeCalulator : IHostedService {
var roomSize = stateList.Count;
if (roomSize > 10000) await File.AppendAllLinesAsync("large_rooms.txt", new[] { $"{{ \"{room.RoomId}\", {roomSize} }}," }, cancellationToken);
- var roomHs = room.RoomId.Split(":")[1];
+ var roomHs = await room.GetOriginHomeserverAsync();
if (totalRoomSize.ContainsKey(roomHs))
totalRoomSize[roomHs] += roomSize;
else
diff --git a/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj b/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
index 8a0107b..9225e74 100644
--- a/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
+++ b/Utilities/LibMatrix.DevTestBot/LibMatrix.DevTestBot.csproj
@@ -1,36 +1,36 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>net9.0</TargetFramework>
- <LangVersion>preview</LangVersion>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- <PublishAot>false</PublishAot>
- <InvariantGlobalization>true</InvariantGlobalization>
- <RootNamespace>LibMatrix.ExampleBot</RootNamespace>
- <!-- <PublishTrimmed>true</PublishTrimmed>-->
- <!-- <PublishReadyToRun>true</PublishReadyToRun>-->
- <!-- <PublishSingleFile>true</PublishSingleFile>-->
- <!-- <PublishReadyToRunShowWarnings>true</PublishReadyToRunShowWarnings>-->
- <!-- <PublishTrimmedShowLinkerSizeComparison>true</PublishTrimmedShowLinkerSizeComparison>-->
- <!-- <PublishTrimmedShowLinkerSizeComparisonWarnings>true</PublishTrimmedShowLinkerSizeComparisonWarnings>-->
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.0-preview.20250806-011111" Condition="'$(Configuration)' == 'Release'" />
- <ProjectReference Include="..\..\ArcaneLibs\ArcaneLibs.StringNormalisation\ArcaneLibs.StringNormalisation.csproj" Condition="'$(Configuration)' == 'Debug'"/>
- <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/>
- <ProjectReference Include="..\LibMatrix.Utilities.Bot\LibMatrix.Utilities.Bot.csproj" />
- </ItemGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
- </ItemGroup>
-
- <ItemGroup>
- <Content Include="appsettings*.json">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </Content>
- </ItemGroup>
-</Project>
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net9.0</TargetFramework>
+ <LangVersion>preview</LangVersion>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <PublishAot>false</PublishAot>
+ <InvariantGlobalization>true</InvariantGlobalization>
+ <RootNamespace>LibMatrix.ExampleBot</RootNamespace>
+ <!-- <PublishTrimmed>true</PublishTrimmed>-->
+ <!-- <PublishReadyToRun>true</PublishReadyToRun>-->
+ <!-- <PublishSingleFile>true</PublishSingleFile>-->
+ <!-- <PublishReadyToRunShowWarnings>true</PublishReadyToRunShowWarnings>-->
+ <!-- <PublishTrimmedShowLinkerSizeComparison>true</PublishTrimmedShowLinkerSizeComparison>-->
+ <!-- <PublishTrimmedShowLinkerSizeComparisonWarnings>true</PublishTrimmedShowLinkerSizeComparisonWarnings>-->
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.0-preview.20250806-011111" Condition="'$(Configuration)' == 'Release'"/>
+ <ProjectReference Include="..\..\ArcaneLibs\ArcaneLibs.StringNormalisation\ArcaneLibs.StringNormalisation.csproj" Condition="'$(Configuration)' == 'Debug'"/>
+ <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/>
+ <ProjectReference Include="..\LibMatrix.Utilities.Bot\LibMatrix.Utilities.Bot.csproj"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <Content Include="appsettings*.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+</Project>
diff --git a/Utilities/LibMatrix.E2eeTestKit/LibMatrix.E2eeTestKit.csproj b/Utilities/LibMatrix.E2eeTestKit/LibMatrix.E2eeTestKit.csproj
index 0da4c48..100e1de 100644
--- a/Utilities/LibMatrix.E2eeTestKit/LibMatrix.E2eeTestKit.csproj
+++ b/Utilities/LibMatrix.E2eeTestKit/LibMatrix.E2eeTestKit.csproj
@@ -1,23 +1,23 @@
-<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
-
- <PropertyGroup>
- <TargetFramework>net9.0</TargetFramework>
- <Nullable>enable</Nullable>
- <ImplicitUsings>enable</ImplicitUsings>
- <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.8" />
- <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.8" PrivateAssets="all" />
- </ItemGroup>
-
- <ItemGroup>
- <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
- </ItemGroup>
-
- <ItemGroup>
- <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj" />
- </ItemGroup>
-
-</Project>
+<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
+
+ <PropertyGroup>
+ <TargetFramework>net9.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.9"/>
+ <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.9" PrivateAssets="all"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/>
+ </ItemGroup>
+
+</Project>
diff --git a/Utilities/LibMatrix.TestDataGenerator/LibMatrix.TestDataGenerator.csproj b/Utilities/LibMatrix.TestDataGenerator/LibMatrix.TestDataGenerator.csproj
index 93de8ab..0eea87a 100644
--- a/Utilities/LibMatrix.TestDataGenerator/LibMatrix.TestDataGenerator.csproj
+++ b/Utilities/LibMatrix.TestDataGenerator/LibMatrix.TestDataGenerator.csproj
@@ -17,7 +17,7 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings*.json">
diff --git a/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj b/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
index 615808d..bd4adc5 100644
--- a/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
+++ b/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
@@ -12,9 +12,9 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
- <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
- <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.9" />
+ <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.9" />
</ItemGroup>
|