From 1324ce517dd56eb4a561498d20ba818a7a175a0e Mon Sep 17 00:00:00 2001 From: Krille Date: Sun, 25 Feb 2024 09:34:00 +0100 Subject: [PATCH] refactor: Remove old aliases workaround --- lib/pages/chat_details/chat_details.dart | 36 +++++++----------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/pages/chat_details/chat_details.dart b/lib/pages/chat_details/chat_details.dart index d15eb9d73..0d7721f26 100644 --- a/lib/pages/chat_details/chat_details.dart +++ b/lib/pages/chat_details/chat_details.dart @@ -72,34 +72,19 @@ class ChatDetailsController extends State { void editAliases() async { final room = Matrix.of(context).client.getRoomById(roomId!); - // The current endpoint doesnt seem to be implemented in Synapse. This may - // change in the future and then we just need to switch to this api call: - // - // final aliases = await showFutureLoadingDialog( - // context: context, - // future: () => room.client.requestRoomAliases(room.id), - // ); - // - // While this is not working we use the unstable api: - final aliases = await showFutureLoadingDialog( + final aliasesResult = await showFutureLoadingDialog( context: context, - future: () => room!.client - .request( - RequestType.GET, - '/client/unstable/org.matrix.msc2432/rooms/${Uri.encodeComponent(room.id)}/aliases', - ) - .then( - (response) => List.from(response['aliases'] as Iterable), - ), + future: () => room!.client.getLocalAliases(room.id), ); - // Switch to the stable api once it is implemented. - if (aliases.error != null) return; - final adminMode = room!.canSendEvent('m.room.canonical_alias'); - if (aliases.result!.isEmpty && (room.canonicalAlias.isNotEmpty)) { - aliases.result!.add(room.canonicalAlias); + final aliases = aliasesResult.result; + + if (aliases == null) return; + final adminMode = room!.canSendEvent(EventTypes.RoomCanonicalAlias); + if (aliases.isEmpty && (room.canonicalAlias.isNotEmpty)) { + aliases.add(room.canonicalAlias); } - if (aliases.result!.isEmpty && adminMode) { + if (aliases.isEmpty && adminMode) { return setAliasAction(); } final select = await showConfirmationDialog( @@ -108,8 +93,7 @@ class ChatDetailsController extends State { actions: [ if (adminMode) AlertDialogAction(label: L10n.of(context)!.create, key: 'new'), - ...aliases.result! - .map((alias) => AlertDialogAction(key: alias, label: alias)), + ...aliases.map((alias) => AlertDialogAction(key: alias, label: alias)), ], ); if (select == null) return;