Skip to content

Commit

Permalink
Hide user ids
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Aug 21, 2024
1 parent 1b1062b commit 2241c94
Show file tree
Hide file tree
Showing 24 changed files with 499 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.RoomMembershipState
import io.element.android.libraries.matrix.api.room.getBestName
import io.element.android.libraries.textcomposer.mentions.ResolvedMentionSuggestion
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
Expand Down Expand Up @@ -105,12 +106,12 @@ private fun RoomMemberSuggestionItemView(
}
val title = when (memberSuggestion) {
is ResolvedMentionSuggestion.AtRoom -> stringResource(R.string.screen_room_mentions_at_room_title)
is ResolvedMentionSuggestion.Member -> memberSuggestion.roomMember.displayName
is ResolvedMentionSuggestion.Member -> memberSuggestion.roomMember.getBestName() // TCHAP should be applied in Element X
}

val subtitle = when (memberSuggestion) {
is ResolvedMentionSuggestion.AtRoom -> "@room"
is ResolvedMentionSuggestion.Member -> memberSuggestion.roomMember.userId.value
is ResolvedMentionSuggestion.Member -> null // TCHAP hide the Matrix Id
}

Avatar(avatarData = avatarData, modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp))
Expand All @@ -129,13 +130,16 @@ private fun RoomMemberSuggestionItemView(
overflow = TextOverflow.Ellipsis,
)
}
Text(
text = subtitle,
style = ElementTheme.typography.fontBodySmRegular,
color = ElementTheme.colors.textSecondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
// TCHAP hide the Matrix Id
if (subtitle != null) {
Text(
text = subtitle,
style = ElementTheme.typography.fontBodySmRegular,
color = ElementTheme.colors.textSecondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import io.element.android.libraries.matrix.api.media.MediaSource
import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.matrix.ui.media.MediaRequestData
import io.element.android.libraries.matrix.ui.model.getAvatarData
import io.element.android.libraries.matrix.ui.model.getBestName
import kotlinx.coroutines.launch

internal val REACTION_SUMMARY_LINE_HEIGHT = 25.sp
Expand Down Expand Up @@ -156,7 +157,7 @@ private fun SheetContent(

SenderRow(
avatarData = user.getAvatarData(AvatarSize.UserListItem),
name = user.displayName ?: user.userId.value,
name = user.getBestName(), // TCHAP should be applied in Element X
userId = user.userId.value,
sentTime = sender.sentTime
)
Expand Down Expand Up @@ -270,13 +271,14 @@ private fun SenderRow(
style = ElementTheme.typography.fontBodySmRegular,
)
}
Text(
text = userId,
color = MaterialTheme.colorScheme.secondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = ElementTheme.typography.fontBodySmRegular,
)
// TCHAP hide the Matrix Id
// Text(
// text = userId,
// color = MaterialTheme.colorScheme.secondary,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// style = ElementTheme.typography.fontBodySmRegular,
// )
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ fun EditUserProfileView(
onAvatarClick = { onAvatarClick() },
modifier = Modifier.align(Alignment.CenterHorizontally),
)
Spacer(modifier = Modifier.height(16.dp))
Text(
modifier = Modifier.fillMaxWidth(),
text = state.userId.value,
style = ElementTheme.typography.fontBodyLgRegular,
textAlign = TextAlign.Center,
)
// TCHAP hide the Matrix Id
// Spacer(modifier = Modifier.height(16.dp))
// Text(
// modifier = Modifier.fillMaxWidth(),
// text = state.userId.value,
// style = ElementTheme.typography.fontBodyLgRegular,
// textAlign = TextAlign.Center,
// )
Spacer(modifier = Modifier.height(40.dp))
LabelledOutlinedTextField(
label = stringResource(R.string.screen_edit_profile_display_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private fun DmHeaderSection(
)
TitleAndSubtitle(
title = roomName,
subtitle = otherMember.userId.value,
subtitle = null, // TCHAP hide the Matrix Id
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,28 @@ private fun RoomMemberActionsBottomSheet(
.padding(bottom = 28.dp)
.align(Alignment.CenterHorizontally)
)
roomMember.displayName?.let {
Text(
text = it,
style = ElementTheme.typography.fontHeadingLgBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
.fillMaxWidth()
)
}
// TCHAP hide the Matrix Id
Text(
text = roomMember.userId.toString(),
style = ElementTheme.typography.fontBodyLgRegular,
color = ElementTheme.colors.textSecondary,
text = roomMember.getBestName(),
style = ElementTheme.typography.fontHeadingLgBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(horizontal = 16.dp)
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
.fillMaxWidth()
)
// Text(
// text = roomMember.userId.toString(),
// style = ElementTheme.typography.fontBodyLgRegular,
// color = ElementTheme.colors.textSecondary,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// textAlign = TextAlign.Center,
// modifier = Modifier
// .padding(horizontal = 16.dp)
// .fillMaxWidth()
// )
Spacer(modifier = Modifier.height(32.dp))

for (action in actions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,17 @@ private fun MemberRow(
)
}
}
// Id
userId?.let {
Text(
text = userId,
color = MaterialTheme.colorScheme.secondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = ElementTheme.typography.fontBodySmRegular,
)
}
// TCHAP hide the Matrix Id
// // Id
// userId?.let {
// Text(
// text = userId,
// color = MaterialTheme.colorScheme.secondary,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// style = ElementTheme.typography.fontBodySmRegular,
// )
// }
}
trailingContent?.invoke()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private fun InviteSubtitle(
modifier: Modifier = Modifier
) {
val subtitle = if (isDm) {
inviteSender?.userId?.value
null // TCHAP hide the Matrix Id
} else {
canonicalAlias?.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ fun UserProfileHeaderSection(
)
Spacer(modifier = Modifier.height(6.dp))
}
Text(
text = userId.value,
style = ElementTheme.typography.fontBodyLgRegular,
color = MaterialTheme.colorScheme.secondary,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
textAlign = TextAlign.Center,
)
// TCHAP hide the Matrix Id
// Text(
// text = userId.value,
// style = ElementTheme.typography.fontBodyLgRegular,
// color = MaterialTheme.colorScheme.secondary,
// modifier = Modifier
// .fillMaxWidth()
// .padding(horizontal = 16.dp),
// textAlign = TextAlign.Center,
// )
Spacer(Modifier.height(40.dp))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import fr.gouv.tchap.android.libraries.matrix.api.core.toDisplayName
import io.element.android.features.userprofile.shared.blockuser.BlockUserDialogs
import io.element.android.features.userprofile.shared.blockuser.BlockUserSection
import io.element.android.libraries.designsystem.components.async.AsyncActionView
Expand Down Expand Up @@ -69,7 +70,7 @@ fun UserProfileView(
UserProfileHeaderSection(
avatarUrl = state.avatarUrl,
userId = state.userId,
userName = state.userName,
userName = state.userName ?: state.userId.toDisplayName(), // TCHAP hide the Matrix Id
openAvatarPreview = { avatarUrl ->
openAvatarPreview(state.userName ?: state.userId.value, avatarUrl)
},
Expand Down
1 change: 1 addition & 0 deletions libraries/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ android {
implementation(libs.vanniktech.blurhash)
implementation(projects.libraries.architecture)
implementation(projects.libraries.preferences.api)
implementation(projects.libraries.tchaputils)
implementation(projects.libraries.testtags)
implementation(projects.libraries.uiStrings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.element.android.libraries.designsystem.components.avatar

import androidx.compose.runtime.Immutable
import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.toDisplayName

@Immutable
data class AvatarData(
Expand Down Expand Up @@ -60,5 +61,5 @@ data class AvatarData(
}

fun AvatarData.getBestName(): String {
return name?.takeIf { it.isNotEmpty() } ?: id
return name?.takeIf { it.isNotEmpty() } ?: id.toDisplayName()
}
1 change: 1 addition & 0 deletions libraries/matrix/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ anvil {

dependencies {
implementation(projects.libraries.di)
implementation(projects.libraries.tchaputils)
implementation(libs.dagger)
implementation(projects.libraries.androidutils)
implementation(projects.libraries.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2024. DINUM
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fr.gouv.tchap.android.libraries.matrix.api.core

import fr.gouv.tchap.libraries.tchaputils.TchapPatterns.toDisplayName
import io.element.android.libraries.matrix.api.core.UserId

fun UserId.toDisplayName() = this.value.toDisplayName()
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.element.android.libraries.matrix.api.room

import fr.gouv.tchap.android.libraries.matrix.api.core.toDisplayName
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.user.MatrixUser

Expand Down Expand Up @@ -56,7 +57,7 @@ data class RoomMember(
* Otherwise, the display name is returned.
*/
val disambiguatedDisplayName: String = when {
displayName == null -> userId.value
displayName == null -> userId.toDisplayName() // TCHAP hide the Matrix Id
isNameAmbiguous -> "$displayName ($userId)"
else -> displayName
}
Expand All @@ -77,7 +78,7 @@ enum class RoomMembershipState {
* If the [RoomMember.displayName] is present and not empty it'll be used, otherwise the [RoomMember.userId] will be used.
*/
fun RoomMember.getBestName(): String {
return displayName?.takeIf { it.isNotEmpty() } ?: userId.value
return displayName?.takeIf { it.isNotEmpty() } ?: userId.toDisplayName() // TCHAP hide the Matrix Id
}

fun RoomMember.toMatrixUser() = MatrixUser(
Expand Down
1 change: 1 addition & 0 deletions libraries/matrixui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation(projects.libraries.designsystem)
implementation(projects.libraries.core)
implementation(projects.libraries.uiStrings)
implementation(projects.libraries.tchaputils)
implementation(projects.libraries.testtags)
implementation(libs.coil.compose)
implementation(libs.coil.gif)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ private fun MatrixUserHeaderContent(
overflow = TextOverflow.Ellipsis,
color = ElementTheme.materialColors.primary,
)
// Id
if (matrixUser.displayName.isNullOrEmpty().not()) {
Text(
text = matrixUser.userId.value,
style = ElementTheme.typography.fontBodyMdRegular,
color = ElementTheme.materialColors.secondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
// TCHAP hide the Matrix Id
// // Id
// if (matrixUser.displayName.isNullOrEmpty().not()) {
// Text(
// text = matrixUser.userId.value,
// style = ElementTheme.typography.fontBodyMdRegular,
// color = ElementTheme.materialColors.secondary,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis
// )
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ internal fun UserRow(
color = MaterialTheme.colorScheme.primary,
style = ElementTheme.typography.fontBodyLgRegular,
)
// Id
subtext?.let {
Text(
text = subtext,
color = MaterialTheme.colorScheme.secondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = ElementTheme.typography.fontBodySmRegular,
)
}
// TCHAP hide the Matrix Id
// // Id
// subtext?.let {
// Text(
// text = subtext,
// color = MaterialTheme.colorScheme.secondary,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// style = ElementTheme.typography.fontBodySmRegular,
// )
// }
}
trailingContent?.invoke()
}
Expand Down
Loading

0 comments on commit 2241c94

Please sign in to comment.