From 392299d5cebbc910d67cfd792704832fc1ec0133 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 22 Jan 2025 17:07:11 +0100 Subject: [PATCH] feat(security&privacy) : update the save address algorithm --- .../editroomaddress/EditRoomAddressPresenter.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/securityandprivacy/editroomaddress/EditRoomAddressPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/securityandprivacy/editroomaddress/EditRoomAddressPresenter.kt index caaf4c373d..3402e2f174 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/securityandprivacy/editroomaddress/EditRoomAddressPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/securityandprivacy/editroomaddress/EditRoomAddressPresenter.kt @@ -107,15 +107,24 @@ class EditRoomAddressPresenter @AssistedInject constructor( if (savedAliasFromHomeserver != null) { room.removeRoomAliasFromRoomDirectory(savedAliasFromHomeserver).getOrThrow() } - // Finally update the canonical alias state.. + + // Finally update the canonical alias state when { // Allow to update the canonical alias only if the saved canonical alias matches the homeserver or if there is no canonical alias savedCanonicalAlias == null || savedCanonicalAlias.matchesServer(serverName) -> { - room.updateCanonicalAlias(newRoomAlias, room.alternativeAliases).getOrThrow() + val newAlternativeAliases = room.alternativeAliases.filter { it != savedAliasFromHomeserver } + room.updateCanonicalAlias(newRoomAlias, newAlternativeAliases).getOrThrow() } - // Otherwise, update the alternative aliases and keep the current canonical alias + // Otherwise, only update the alternative aliases and keep the current canonical alias else -> { - val newAlternativeAliases = listOf(newRoomAlias) + room.alternativeAliases + val newAlternativeAliases = buildList { + add(newRoomAlias) + for (alias in room.alternativeAliases) { + if (alias != savedAliasFromHomeserver) { + add(alias) + } + } + } room.updateCanonicalAlias(savedCanonicalAlias, newAlternativeAliases).getOrThrow() } }