Add room alias support

This commit is contained in:
Henry Hiles 2026-05-26 18:44:27 -04:00
commit a0c2eefc1e
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
2 changed files with 37 additions and 9 deletions

View file

@ -1,3 +1,4 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/content/content.dart";
part "canonical_alias.freezed.dart";
@ -7,8 +8,10 @@ part "canonical_alias.g.dart";
abstract class CanonicalAliasContent extends Content
with _$CanonicalAliasContent {
CanonicalAliasContent._();
factory CanonicalAliasContent({String? alias, @Default([]) altAliases}) =
_CanonicalAliasContent;
factory CanonicalAliasContent({
String? alias,
@Default(ISet.empty()) ISet<String> altAliases,
}) = _CanonicalAliasContent;
factory CanonicalAliasContent.fromJson(Map<String, Object?> json) =>
_$CanonicalAliasContentFromJson(json);

View file

@ -12,6 +12,7 @@ import "package:nexus/helpers/extensions/get_headers.dart";
import "package:nexus/helpers/extensions/mxc_to_https.dart";
import "package:nexus/helpers/extensions/show_context_menu.dart";
import "package:nexus/models/content/avatar.dart";
import "package:nexus/models/content/canonical_alias.dart";
import "package:nexus/models/content/content.dart";
import "package:nexus/models/content/encrypted.dart";
import "package:nexus/models/content/membership.dart";
@ -404,14 +405,38 @@ class EventRenderer extends ConsumerWidget {
content.status
? null
: MembershipRenderer(event),
AvatarContent() => GenericEventRenderer(Icons.numbers, [
Padding(
padding: EdgeInsets.symmetric(horizontal: 4),
child: Icon(Icons.numbers),
),
Flexible(child: MessageDisplayname(event)),
Expanded(child: Text("changed the room avatar")),
AvatarContent() => GenericEventRenderer(Icons.interests, [
MessageDisplayname(event),
Text("changed the room avatar"),
]),
CanonicalAliasContent(:final alias, :final altAliases) =>
GenericEventRenderer(Icons.numbers, [
MessageDisplayname(event),
Text(switch ([
if (event.previousContent case CanonicalAliasContent(
alias: final prevAlias,
altAliases: final prevAltAliases,
)) ...[
if (prevAlias != alias)
if (alias == null)
"removed the room's canonical alias"
else
"changed the room's canonical alias to $alias",
if (prevAltAliases
.remove(alias ?? "")
.remove(prevAlias ?? "") !=
altAliases.remove(alias ?? "").remove(prevAlias ?? ""))
"changed the room's aliases",
] else ...[
if (alias != null) "set the room's canonical alias",
if (altAliases.isNotEmpty) "set the room's aliases",
],
]) {
[] => "did something related to room aliases",
List prev => prev.join(" and "),
}),
]),
_ => null,
};