Room: remove bestName and use displayName instead of name where it makes sense

This commit is contained in:
ganfra
2023-07-05 12:01:51 +02:00
parent 79eef06995
commit 03b2cbb06f
9 changed files with 26 additions and 36 deletions

View File

@@ -105,7 +105,7 @@ private suspend fun MatrixClient.leaveRoom(
room.leave().onSuccess {
roomMembershipObserver.notifyUserLeftRoom(room.roomId)
}.onFailure {
Timber.e(it, "Error while leaving room ${room.name} - ${room.roomId}")
Timber.e(it, "Error while leaving room ${room.displayName} - ${room.roomId}")
error.value = LeaveRoomState.Error.Shown
}
}

View File

@@ -24,6 +24,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
@@ -107,13 +108,12 @@ class MessagesPresenter @AssistedInject constructor(
val syncUpdateFlow = room.syncUpdateFlow.collectAsState()
val userHasPermissionToSendMessage by room.canSendEventAsState(type = MessageEventType.ROOM_MESSAGE, updateKey = syncUpdateFlow.value)
val roomName: MutableState<String?> = rememberSaveable {
mutableStateOf(null)
val roomName by produceState(initialValue = room.displayName, key1 = syncUpdateFlow.value){
value = room.displayName
}
val roomAvatar: MutableState<AvatarData?> = remember {
mutableStateOf(null)
val roomAvatar by produceState(initialValue = room.avatarData(), key1 = syncUpdateFlow.value){
value = room.avatarData()
}
var hasDismissedInviteDialog by rememberSaveable {
mutableStateOf(false)
}
@@ -134,16 +134,6 @@ class MessagesPresenter @AssistedInject constructor(
val snackbarMessage by snackbarDispatcher.collectSnackbarMessageAsState()
LaunchedEffect(syncUpdateFlow.value) {
roomAvatar.value =
AvatarData(
id = room.roomId.value,
name = room.name,
url = room.avatarUrl,
size = AvatarSize.TimelineRoom
)
roomName.value = room.name
}
LaunchedEffect(composerState.mode.relatedEventId) {
timelineState.eventSink(TimelineEvents.SetHighlightedEvent(composerState.mode.relatedEventId))
}
@@ -169,8 +159,8 @@ class MessagesPresenter @AssistedInject constructor(
return MessagesState(
roomId = room.roomId,
roomName = roomName.value,
roomAvatar = roomAvatar.value,
roomName = roomName,
roomAvatar = roomAvatar,
userHasPermissionToSendMessage = userHasPermissionToSendMessage,
composerState = composerState,
timelineState = timelineState,
@@ -185,6 +175,15 @@ class MessagesPresenter @AssistedInject constructor(
)
}
private fun MatrixRoom.avatarData(): AvatarData {
return AvatarData(
id = room.roomId.value,
name = room.displayName,
url = room.avatarUrl,
size = AvatarSize.TimelineRoom
)
}
private fun CoroutineScope.handleTimelineAction(
action: TimelineItemAction,
targetEvent: TimelineItem.Event,

View File

@@ -30,8 +30,8 @@ import io.element.android.libraries.matrix.api.core.RoomId
@Immutable
data class MessagesState(
val roomId: RoomId,
val roomName: String?,
val roomAvatar: AvatarData?,
val roomName: String,
val roomAvatar: AvatarData,
val userHasPermissionToSendMessage: Boolean,
val composerState: MessageComposerState,
val timelineState: TimelineState,

View File

@@ -277,8 +277,8 @@ fun MessagesViewContent(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MessagesViewTopBar(
roomTitle: String?,
roomAvatar: AvatarData?,
roomTitle: String,
roomAvatar: AvatarData,
modifier: Modifier = Modifier,
onRoomDetailsClicked: () -> Unit = {},
onBackPressed: () -> Unit = {},
@@ -293,14 +293,12 @@ fun MessagesViewTopBar(
modifier = Modifier.clickable { onRoomDetailsClicked() },
verticalAlignment = Alignment.CenterVertically
) {
if (roomAvatar != null) {
Avatar(roomAvatar)
Spacer(modifier = Modifier.width(8.dp))
}
Avatar(roomAvatar)
Spacer(modifier = Modifier.width(8.dp))
Text(
fontSize = 16.sp,
fontWeight = FontWeight.SemiBold,
text = roomTitle ?: "Unknown room",
text = roomTitle,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)

View File

@@ -78,7 +78,7 @@ class RoomDetailsPresenter @Inject constructor(
return RoomDetailsState(
roomId = room.roomId.value,
roomName = room.name ?: room.displayName,
roomName = room.displayName,
roomAlias = room.alias,
roomAvatarUrl = room.avatarUrl,
roomTopic = topicState,

View File

@@ -62,7 +62,7 @@ class RoomDetailsPresenterTests {
}.test {
val initialState = awaitItem()
assertThat(initialState.roomId).isEqualTo(room.roomId.value)
assertThat(initialState.roomName).isEqualTo(room.name)
assertThat(initialState.roomName).isEqualTo(room.displayName)
assertThat(initialState.roomAvatarUrl).isEqualTo(room.avatarUrl)
assertThat(initialState.roomTopic).isEqualTo(RoomTopicState.ExistingTopic(room.topic!!))
assertThat(initialState.memberCount).isEqualTo(room.joinedMemberCount)

View File

@@ -35,7 +35,6 @@ interface MatrixRoom : Closeable {
val sessionId: SessionId
val roomId: RoomId
val name: String?
val bestName: String
val displayName: String
val alias: String?
val alternativeAliases: List<String>

View File

@@ -130,11 +130,6 @@ class RustMatrixRoom(
return roomListItem.name()
}
override val bestName: String
get() {
return name?.takeIf { it.isNotEmpty() } ?: innerRoom.id()
}
override val displayName: String
get() {
return innerRoom.displayName()

View File

@@ -43,7 +43,6 @@ class FakeMatrixRoom(
override val sessionId: SessionId = A_SESSION_ID,
override val roomId: RoomId = A_ROOM_ID,
override val name: String? = null,
override val bestName: String = "",
override val displayName: String = "",
override val topic: String? = null,
override val avatarUrl: String? = null,