Skip to content

Commit

Permalink
Masquer les identifiants matrix (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Sep 4, 2024
1 parent 130e72b commit 3207726
Show file tree
Hide file tree
Showing 262 changed files with 1,056 additions and 398 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.element.android.libraries.usersearch.api.UserSearchResult

@Composable
fun SearchMultipleUsersResultItem(
isDebugBuild: Boolean,
searchResult: UserSearchResult,
isUserSelected: Boolean,
onCheckedChange: (Boolean) -> Unit,
Expand All @@ -50,6 +51,7 @@ fun SearchMultipleUsersResultItem(
)
}
CheckableUserRow(
isDebugBuild = isDebugBuild,
checked = isUserSelected,
modifier = modifier,
data = data,
Expand All @@ -62,6 +64,7 @@ fun SearchMultipleUsersResultItem(
internal fun SearchMultipleUsersResultItemPreview() = ElementThemedPreview {
Column {
SearchMultipleUsersResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(
aMatrixUser(),
isUnresolved = false
Expand All @@ -71,6 +74,7 @@ internal fun SearchMultipleUsersResultItemPreview() = ElementThemedPreview {
)
HorizontalDivider()
SearchMultipleUsersResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(
aMatrixUser(),
isUnresolved = false
Expand All @@ -80,6 +84,7 @@ internal fun SearchMultipleUsersResultItemPreview() = ElementThemedPreview {
)
HorizontalDivider()
SearchMultipleUsersResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(
aMatrixUser(),
isUnresolved = true
Expand All @@ -89,6 +94,7 @@ internal fun SearchMultipleUsersResultItemPreview() = ElementThemedPreview {
)
HorizontalDivider()
SearchMultipleUsersResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(
aMatrixUser(),
isUnresolved = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.element.android.libraries.usersearch.api.UserSearchResult

@Composable
fun SearchSingleUserResultItem(
isDebugBuild: Boolean,
searchResult: UserSearchResult,
onClick: () -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -44,6 +45,7 @@ fun SearchSingleUserResultItem(
)
} else {
MatrixUserRow(
isDebugBuild = isDebugBuild,
modifier = modifier.clickable(onClick = onClick),
matrixUser = searchResult.matrixUser,
avatarSize = AvatarSize.UserListItem,
Expand All @@ -56,11 +58,13 @@ fun SearchSingleUserResultItem(
internal fun SearchSingleUserResultItemPreview() = ElementThemedPreview {
Column {
SearchSingleUserResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(aMatrixUser(), isUnresolved = false),
onClick = {},
)
HorizontalDivider()
SearchSingleUserResultItem(
isDebugBuild = false,
searchResult = UserSearchResult(aMatrixUser(), isUnresolved = true),
onClick = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import kotlinx.collections.immutable.ImmutableList
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchUserBar(
isDebugBuild: Boolean,
query: String,
state: SearchBarResultState<ImmutableList<UserSearchResult>>,
showLoader: Boolean,
Expand Down Expand Up @@ -112,6 +113,7 @@ fun SearchUserBar(
if (isMultiSelectionEnable) {
itemsIndexed(users) { index, searchResult ->
SearchMultipleUsersResultItem(
isDebugBuild = isDebugBuild,
modifier = Modifier.fillMaxWidth(),
searchResult = searchResult,
isUserSelected = selectedUsers.contains(searchResult.matrixUser),
Expand All @@ -130,6 +132,7 @@ fun SearchUserBar(
} else {
itemsIndexed(users) { index, searchResult ->
SearchSingleUserResultItem(
isDebugBuild = isDebugBuild,
modifier = Modifier.fillMaxWidth(),
searchResult = searchResult,
onClick = { onUserSelect(searchResult.matrixUser) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fun UserListView(
modifier = modifier,
) {
SearchUserBar(
isDebugBuild = state.isDebugBuild,
modifier = Modifier.fillMaxWidth(),
query = state.searchQuery,
state = state.searchResults,
Expand Down Expand Up @@ -98,6 +99,7 @@ fun UserListView(
recentDirectRoom.matrixUser.userId == it.userId
}
CheckableUserRow(
isDebugBuild = state.isDebugBuild,
checked = isSelected,
onCheckedChange = {
if (isSelected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CreateRoomRootPresenter @Inject constructor(
}

return CreateRoomRootState(
isDebugBuild = buildMeta.isDebuggable,
applicationName = buildMeta.applicationName,
userListState = userListState,
startDmAction = startDmActionState.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.matrix.api.core.RoomId

data class CreateRoomRootState(
val isDebugBuild: Boolean,
val applicationName: String,
val userListState: UserListState,
val startDmAction: AsyncAction<RoomId>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fun aCreateRoomRootState(
startDmAction: AsyncAction<RoomId> = AsyncAction.Uninitialized,
eventSink: (CreateRoomRootEvents) -> Unit = {},
) = CreateRoomRootState(
isDebugBuild = false,
applicationName = applicationName,
userListState = userListState,
startDmAction = startDmAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private fun CreateRoomActionButtonsList(
state.userListState.recentDirectRooms.forEach { recentDirectRoom ->
item {
MatrixUserRow(
isDebugBuild = state.isDebugBuild,
modifier = Modifier.clickable(
onClick = {
onDmClick(recentDirectRoom.roomId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.squareup.anvil.annotations.ContributesBinding
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.designsystem.theme.components.SearchBarResultState
import io.element.android.libraries.di.SessionScope
import io.element.android.libraries.matrix.api.MatrixClient
Expand All @@ -44,6 +45,7 @@ class DefaultUserListPresenter @AssistedInject constructor(
@Assisted val args: UserListPresenterArgs,
@Assisted val userRepository: UserRepository,
@Assisted val userListDataStore: UserListDataStore,
private val buildMeta: BuildMeta,
private val matrixClient: MatrixClient,
) : UserListPresenter {
@AssistedFactory
Expand Down Expand Up @@ -84,6 +86,7 @@ class DefaultUserListPresenter @AssistedInject constructor(
}

return UserListState(
isDebugBuild = buildMeta.isDebuggable,
searchQuery = searchQuery,
searchResults = searchResults,
selectedUsers = selectedUsers.toImmutableList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.element.android.libraries.usersearch.api.UserSearchResult
import kotlinx.collections.immutable.ImmutableList

data class UserListState(
val isDebugBuild: Boolean,
val searchQuery: String,
val searchResults: SearchBarResultState<ImmutableList<UserSearchResult>>,
val showSearchLoader: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fun aUserListState(
recentDirectRooms: List<RecentDirectRoom> = emptyList(),
eventSink: (UserListEvents) -> Unit = {},
) = UserListState(
isDebugBuild = false,
searchQuery = searchQuery,
isSearchActive = isSearchActive,
searchResults = searchResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.designsystem.theme.components.SearchBarResultState
import io.element.android.libraries.matrix.test.FakeMatrixClient
import io.element.android.libraries.matrix.test.core.aBuildMeta
import io.element.android.libraries.matrix.ui.components.aMatrixUser
import io.element.android.libraries.matrix.ui.components.aMatrixUserList
import io.element.android.libraries.usersearch.api.UserSearchResult
Expand All @@ -38,6 +39,7 @@ class DefaultUserListPresenterTest {
val warmUpRule = WarmUpRule()

private val userRepository = FakeUserRepository()
private val buildMeta = aBuildMeta()

@Test
fun `present - initial state for single selection`() = runTest {
Expand All @@ -46,6 +48,7 @@ class DefaultUserListPresenterTest {
UserListPresenterArgs(selectionMode = SelectionMode.Single),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand All @@ -68,6 +71,7 @@ class DefaultUserListPresenterTest {
UserListPresenterArgs(selectionMode = SelectionMode.Multiple),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand All @@ -90,6 +94,7 @@ class DefaultUserListPresenterTest {
UserListPresenterArgs(selectionMode = SelectionMode.Single),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand Down Expand Up @@ -127,6 +132,7 @@ class DefaultUserListPresenterTest {
),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand Down Expand Up @@ -180,6 +186,7 @@ class DefaultUserListPresenterTest {
),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand All @@ -206,6 +213,7 @@ class DefaultUserListPresenterTest {
UserListPresenterArgs(selectionMode = SelectionMode.Single),
userRepository,
UserListDataStore(),
buildMeta,
FakeMatrixClient(),
)
moleculeFlow(RecompositionMode.Immediate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class MessagesPresenter @AssistedInject constructor(
}

return MessagesState(
isDebugBuild = buildMeta.isDebuggable,
roomId = room.roomId,
roomName = roomName,
roomAvatar = roomAvatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.collections.immutable.ImmutableList

@Immutable
data class MessagesState(
val isDebugBuild: Boolean,
val roomId: RoomId,
val roomName: AsyncData<String>,
val roomAvatar: AsyncData<AvatarData>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ fun aMessagesState(
pinnedMessagesBannerState: PinnedMessagesBannerState = aLoadedPinnedMessagesBannerState(),
eventSink: (MessagesEvents) -> Unit = {},
) = MessagesState(
isDebugBuild = false,
roomId = RoomId("!id:domain"),
roomName = roomName,
roomAvatar = roomAvatar,
Expand Down Expand Up @@ -184,6 +185,7 @@ fun aReadReceiptBottomSheetState(
selectedEvent: TimelineItem.Event? = null,
eventSink: (ReadReceiptBottomSheetEvents) -> Unit = {},
) = ReadReceiptBottomSheetState(
isDebugBuild = false,
selectedEvent = selectedEvent,
eventSink = eventSink,
)
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ private fun MessagesViewComposerBottomSheetContents(
return available
}
}),
isDebugBuild = state.isDebugBuild,
roomId = state.roomId,
roomName = state.roomName.dataOrNull(),
roomAvatarData = state.roomAvatar.dataOrNull(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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.matrix.ui.components.aRoomSummaryDetails
import io.element.android.libraries.matrix.ui.model.getAvatarData
import io.element.android.libraries.textcomposer.mentions.ResolvedSuggestion
Expand All @@ -53,6 +54,7 @@ import kotlinx.collections.immutable.persistentListOf

@Composable
fun SuggestionsPickerView(
isDebugBuild: Boolean,
roomId: RoomId,
roomName: String?,
roomAvatarData: AvatarData?,
Expand All @@ -75,6 +77,7 @@ fun SuggestionsPickerView(
) {
Column(modifier = Modifier.fillParentMaxWidth()) {
SuggestionItemView(
isDebugBuild = isDebugBuild,
suggestion = it,
roomId = roomId.value,
roomName = roomName,
Expand All @@ -90,6 +93,7 @@ fun SuggestionsPickerView(

@Composable
private fun SuggestionItemView(
isDebugBuild: Boolean,
suggestion: ResolvedSuggestion,
roomId: String,
roomName: String?,
Expand All @@ -109,12 +113,12 @@ private fun SuggestionItemView(
}
val title = when (suggestion) {
is ResolvedSuggestion.AtRoom -> stringResource(R.string.screen_room_mentions_at_room_title)
is ResolvedSuggestion.Member -> suggestion.roomMember.displayName
is ResolvedSuggestion.Member -> suggestion.roomMember.getBestName() // TCHAP TODO should be applied in Element X
is ResolvedSuggestion.Alias -> suggestion.roomSummary.name
}
val subtitle = when (suggestion) {
is ResolvedSuggestion.AtRoom -> "@room"
is ResolvedSuggestion.Member -> suggestion.roomMember.userId.value
is ResolvedSuggestion.Member -> suggestion.roomMember.userId.value.takeIf { isDebugBuild } // TCHAP hide the Matrix Id in release mode
is ResolvedSuggestion.Alias -> suggestion.roomAlias.value
}

Expand All @@ -134,13 +138,15 @@ private fun SuggestionItemView(
overflow = TextOverflow.Ellipsis,
)
}
Text(
text = subtitle,
style = ElementTheme.typography.fontBodySmRegular,
color = ElementTheme.colors.textSecondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
subtitle?.let {
Text(
text = subtitle,
style = ElementTheme.typography.fontBodySmRegular,
color = ElementTheme.colors.textSecondary,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
Expand All @@ -167,6 +173,7 @@ internal fun SuggestionsPickerViewPreview() {
)
}
SuggestionsPickerView(
isDebugBuild = false,
roomId = RoomId("!room:matrix.org"),
roomName = "Room",
roomAvatarData = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import io.element.android.libraries.architecture.Presenter
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.matrix.api.room.MatrixRoom
import io.element.android.libraries.matrix.api.room.RoomMember
import io.element.android.libraries.matrix.api.room.roomMembers
Expand All @@ -33,6 +34,7 @@ import kotlinx.collections.immutable.toImmutableList
import javax.inject.Inject

class ReactionSummaryPresenter @Inject constructor(
private val buildMeta: BuildMeta,
private val room: MatrixRoom,
) : Presenter<ReactionSummaryState> {
@Composable
Expand All @@ -47,6 +49,7 @@ class ReactionSummaryPresenter @Inject constructor(
fun handleEvents(event: ReactionSummaryEvents) {
when (event) {
is ReactionSummaryEvents.ShowReactionSummary -> target.value = ReactionSummaryState.Summary(
isDebugBuild = buildMeta.isDebuggable,
reactions = event.reactions.toImmutableList(),
selectedKey = event.selectedKey,
selectedEventId = event.eventId
Expand Down
Loading

0 comments on commit 3207726

Please sign in to comment.