about summary refs log tree commit diff
diff options
context:
space:
mode:
m---------ArcaneLibs0
-rw-r--r--LibMatrix/Helpers/RoomBuilder.cs11
-rw-r--r--LibMatrix/Helpers/RoomUpgradeBuilder.cs24
3 files changed, 26 insertions, 9 deletions
diff --git a/ArcaneLibs b/ArcaneLibs
-Subproject 5099e9feeade98f562723e102bd58887aa2c125
+Subproject 57ca515a61ae4f428981e2a548c733095a9f010
diff --git a/LibMatrix/Helpers/RoomBuilder.cs b/LibMatrix/Helpers/RoomBuilder.cs

index 2d8d730..601f001 100644 --- a/LibMatrix/Helpers/RoomBuilder.cs +++ b/LibMatrix/Helpers/RoomBuilder.cs
@@ -35,7 +35,7 @@ public class RoomBuilder { AllowIpLiterals = false }; - public RoomEncryptionEventContent? Encryption { get; set; } + public RoomEncryptionEventContent Encryption { get; set; } = new() { }; /// <summary> /// State events to be sent *before* room access is configured. Keep this small! @@ -187,18 +187,21 @@ public class RoomBuilder { await room.Homeserver.SetRoomAliasAsync(CanonicalAlias.Alias!, room.RoomId); await room.SendStateEventAsync(RoomCanonicalAliasEventContent.EventId, CanonicalAlias); } + + if (!string.IsNullOrWhiteSpace(Encryption.Algorithm)) + await room.SendStateEventAsync(RoomEncryptionEventContent.EventId, Encryption); } private async Task SetAccessAsync(GenericRoom room) { - if(!V12PlusRoomVersions.Contains(Version)) + if (!V12PlusRoomVersions.Contains(Version)) PowerLevels.Users![room.Homeserver.WhoAmI.UserId] = OwnPowerLevel; else { PowerLevels.Users!.Remove(room.Homeserver.WhoAmI.UserId); - foreach (var additionalCreator in AdditionalCreators) - { + foreach (var additionalCreator in AdditionalCreators) { PowerLevels.Users!.Remove(additionalCreator); } } + await room.SendStateEventAsync(RoomPowerLevelEventContent.EventId, PowerLevels); if (!string.IsNullOrWhiteSpace(HistoryVisibility.HistoryVisibility)) diff --git a/LibMatrix/Helpers/RoomUpgradeBuilder.cs b/LibMatrix/Helpers/RoomUpgradeBuilder.cs
index 64ec364..f9ce62b 100644 --- a/LibMatrix/Helpers/RoomUpgradeBuilder.cs +++ b/LibMatrix/Helpers/RoomUpgradeBuilder.cs
@@ -100,7 +100,6 @@ public class RoomUpgradeBuilder : RoomBuilder { } private StateEventResponse UpgradeUnstableValues(StateEventResponse evt) { - return evt; } @@ -113,6 +112,7 @@ public class RoomUpgradeBuilder : RoomBuilder { evt.RawContent["org.matrix.msc4321.original_timestamp"] = evt.OriginServerTs; evt.RawContent["org.matrix.msc4321.original_event_id"] = evt.EventId; } + InitialState.Add(new() { Type = evt.Type, StateKey = evt.StateKey, @@ -121,11 +121,24 @@ public class RoomUpgradeBuilder : RoomBuilder { } public override async Task<GenericRoom> Create(AuthenticatedHomeserverGeneric homeserver) { + var oldRoom = homeserver.GetRoom(OldRoomId); + // prepare old room first... + if (!string.IsNullOrWhiteSpace(AliasLocalPart)) { + var aliasResult = await homeserver.ResolveRoomAliasAsync($"#{AliasLocalPart}:{homeserver.ServerName}"); + if (aliasResult?.RoomId == OldRoomId) + await homeserver.DeleteRoomAliasAsync($"#{AliasLocalPart}:{homeserver.ServerName}"); + else + throw new LibMatrixException() { + ErrorCode = LibMatrixException.ErrorCodes.M_UNSUPPORTED, + Error = $"Cannot upgrade room {OldRoomId} as it has an alias that is not the same as the one tracked by the server! Server says: {aliasResult.RoomId}" + }; + } + var room = await base.Create(homeserver); if (CanUpgrade || UpgradeOptions.ForceUpgrade) { if (UpgradeOptions.RoomUpgradeNotice != null) { var noticeContent = await UpgradeOptions.RoomUpgradeNotice(room); - await room.SendMessageEventAsync(noticeContent); + await oldRoom.SendMessageEventAsync(noticeContent); } var tombstoneContent = new RoomTombstoneEventContent { @@ -137,8 +150,9 @@ public class RoomUpgradeBuilder : RoomBuilder { foreach (var (key, value) in AdditionalTombstoneContent) tombstoneContent.AdditionalData[key] = value; - await room.SendStateEventAsync(RoomTombstoneEventContent.EventId, tombstoneContent); + await oldRoom.SendStateEventAsync(RoomTombstoneEventContent.EventId, tombstoneContent); } + return room; } @@ -152,13 +166,13 @@ public class RoomUpgradeBuilder : RoomBuilder { public Msc4321PolicyListUpgradeOptions Msc4321PolicyListUpgradeOptions { get; set; } = new(); [JsonIgnore] - public Func<GenericRoom, Task<RoomMessageEventContent>> RoomUpgradeNotice { get; set; } = async newRoom => new MessageBuilder() + public Func<GenericRoom, Task<RoomMessageEventContent>>? RoomUpgradeNotice { get; set; } = async newRoom => new MessageBuilder() .WithRoomMention() + .WithNewline() .WithBody("This room has been upgraded to a new version. This version of the room will be kept as an archive.") .WithNewline() .WithBody("You can join the new room by clicking the link below:") .WithNewline() - .WithRoomMention() .WithMention(newRoom.RoomId, await newRoom.GetNameOrFallbackAsync(), vias: (await newRoom.GetHomeserversInRoom()).ToArray(), useLinkInPlainText: true) .Build(); }