diff --git a/lib/src/room.dart b/lib/src/room.dart index 870fac3d..939aadd2 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -251,6 +251,18 @@ class Room { ? getState(EventTypes.RoomCanonicalAlias).content['alias'] : ''; + /// Sets the canonical alias. If the [canonicalAlias] is not yet an alias of + /// this room, it will create one. + Future setCanonicalAlias(String canonicalAlias) async { + final aliases = await client.requestRoomAliases(id); + if (!aliases.contains(canonicalAlias)) { + await client.createRoomAlias(canonicalAlias, id); + } + await client.sendState(id, EventTypes.RoomCanonicalAlias, { + 'alias': canonicalAlias, + }); + } + /// If this room is a direct chat, this is the matrix ID of the user. /// Returns null otherwise. String get directChatMatrixID { @@ -1643,17 +1655,6 @@ class Room { ); } - /// Returns all aliases for this room. - List get aliases { - final aliases = []; - for (final aliasEvent in states[EventTypes.RoomAliases].values) { - if (aliasEvent.content['aliases'] is List) { - aliases.addAll(aliasEvent.content['aliases']); - } - } - return aliases; - } - /// A room may be public meaning anyone can join the room without any prior action. Alternatively, /// it can be invite meaning that a user who wishes to join the room must first receive an invite /// to the room from someone already inside of the room. Currently, knock and private are reserved diff --git a/pubspec.yaml b/pubspec.yaml index 4544c10a..5481a3a5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: olm: ^2.0.0 isolate: ^2.0.3 logger: ^1.0.0 - matrix_api_lite: ^0.2.4 + matrix_api_lite: ^0.2.6 dev_dependencies: test: ^1.15.7