Skip to content

Show a room list decoration for notification setting applied #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ed1949a
Show a room list decoration for notification setting applied
langleyd Sep 14, 2023
dec32ac
Only show green indicator for "All Messages"
langleyd Sep 14, 2023
7a7cc26
Fix test compilation
langleyd Sep 14, 2023
9a234a8
Merge branch 'develop' of https://github.com/vector-im/element-x-andr…
langleyd Sep 14, 2023
57aeac9
Update RoomListDataSource.kt
langleyd Sep 14, 2023
0cdc5f5
Cancel scope in tests.
langleyd Sep 15, 2023
90fc536
Merge branch 'develop' of https://github.com/vector-im/element-x-andr…
langleyd Sep 15, 2023
4a3ffd3
Use userDefinedNotificationMode.
langleyd Sep 15, 2023
db02b0c
Update screenshots
Sep 15, 2023
f287a65
Reverting the change to only show the green dot for all messages.
langleyd Sep 15, 2023
e25280b
Merge branch 'develop' of https://github.com/vector-im/element-x-andr…
langleyd Sep 15, 2023
21ca59e
Merge branch 'dla/feature/room_list_decoration' of https://github.com…
langleyd Sep 15, 2023
6d7e51c
Update screenshots
Sep 15, 2023
bc29a31
Merge branch 'develop' into dla/feature/room_list_decoration
langleyd Sep 18, 2023
e48a9ee
Fix typo, remove unnecessary filter of all rooms in the datasource.
langleyd Sep 18, 2023
c160a37
Merge branch 'dla/feature/room_list_decoration' of https://github.com…
langleyd Sep 18, 2023
6497d21
Add test.
langleyd Sep 18, 2023
8098193
Merge branch 'develop' into dla/feature/room_list_decoration
langleyd Sep 18, 2023
67b9e94
Fix unused import.
langleyd Sep 18, 2023
70d9fee
Merge branch 'dla/feature/room_list_decoration' of https://github.com…
langleyd Sep 18, 2023
f465231
Merge branch 'develop' into dla/feature/room_list_decoration
langleyd Sep 18, 2023
bd97cca
Merge branch 'develop' of https://github.com/vector-im/element-x-andr…
langleyd Sep 18, 2023
0d172df
Merge branch 'develop' into dla/feature/room_list_decoration
langleyd Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.element.android.features.roomlist.impl.components
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
Expand All @@ -33,6 +34,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -41,16 +45,20 @@ import androidx.compose.ui.unit.dp
import io.element.android.features.roomlist.impl.model.RoomListRoomSummary
import io.element.android.features.roomlist.impl.model.RoomListRoomSummaryProvider
import io.element.android.libraries.core.extensions.orEmpty
import io.element.android.libraries.designsystem.VectorIcons
import io.element.android.libraries.designsystem.atomic.atoms.UnreadIndicatorAtom
import io.element.android.libraries.designsystem.components.avatar.Avatar
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.roomListRoomMessage
import io.element.android.libraries.designsystem.theme.roomListRoomMessageDate
import io.element.android.libraries.designsystem.theme.roomListRoomName
import io.element.android.libraries.designsystem.theme.unreadIndicator
import io.element.android.libraries.matrix.api.room.RoomNotificationMode
import io.element.android.libraries.theme.ElementTheme
import io.element.android.libraries.ui.strings.CommonStrings

internal val minHeight = 84.dp

Expand Down Expand Up @@ -161,11 +169,39 @@ private fun RowScope.LastMessageAndIndicatorRow(room: RoomListRoomSummary) {
maxLines = 2,
overflow = TextOverflow.Ellipsis
)

// Unread
UnreadIndicatorAtom(
modifier = Modifier.padding(top = 3.dp),
isVisible = room.hasUnread,
)
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
NotificationIcon(room)
if (room.hasUnread) {
UnreadIndicatorAtom(
modifier = Modifier.padding(top = 3.dp),
)
}
}

}

@Composable
private fun NotificationIcon(room: RoomListRoomSummary) {
val tint = if(room.hasUnread) ElementTheme.colors.unreadIndicator else ElementTheme.colors.iconQuaternary
when(room.notificationMode) {
null, RoomNotificationMode.ALL_MESSAGES -> return
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY ->
Icon(
contentDescription = stringResource(CommonStrings.screen_notification_settings_mode_mentions),
imageVector = ImageVector.vectorResource(VectorIcons.Mention),
tint = tint,
)
RoomNotificationMode.MUTE ->
Icon(
contentDescription = stringResource(CommonStrings.common_mute),
imageVector = ImageVector.vectorResource(VectorIcons.Mute),
tint = tint,
)
}
}

@Preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,37 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.eventformatter.api.RoomLastMessageFormatter
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService
import io.element.android.libraries.matrix.api.roomlist.RoomListService
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds

class RoomListDataSource @Inject constructor(
private val roomListService: RoomListService,
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
private val roomLastMessageFormatter: RoomLastMessageFormatter,
private val coroutineDispatchers: CoroutineDispatchers,
private val notificationSettingsService: NotificationSettingsService,
private val appScope: CoroutineScope,
) {
init {
observeNotificationSettings()
}

private val _filter = MutableStateFlow("")
private val _allRooms = MutableStateFlow<ImmutableList<RoomListRoomSummary>>(persistentListOf())
Expand Down Expand Up @@ -92,6 +101,16 @@ class RoomListDataSource @Inject constructor(
val allRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _allRooms
val filteredRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _filteredRooms

@OptIn(FlowPreview::class)
private fun observeNotificationSettings() {
notificationSettingsService.notificationSettingsChangeFlow
.debounce(0.5.seconds)
.onEach {
roomListService.rebuildRoomSummaries()
}
.launchIn(appScope)
}

private suspend fun replaceWith(roomSummaries: List<RoomSummary>) = withContext(coroutineDispatchers.computation) {
lock.withLock {
diffCacheUpdater.updateWith(roomSummaries)
Expand Down Expand Up @@ -120,10 +139,7 @@ class RoomListDataSource @Inject constructor(
}
}

private fun buildAndCacheItem(
roomSummaries: List<RoomSummary>,
index: Int
): RoomListRoomSummary? {
private fun buildAndCacheItem(roomSummaries: List<RoomSummary>, index: Int): RoomListRoomSummary? {
val roomListRoomSummary = when (val roomSummary = roomSummaries.getOrNull(index)) {
is RoomSummary.Empty -> RoomListRoomSummaryPlaceholders.create(roomSummary.identifier)
is RoomSummary.Filled -> {
Expand All @@ -144,10 +160,12 @@ class RoomListDataSource @Inject constructor(
roomLastMessageFormatter.format(message.event, roomSummary.details.isDirect)
}.orEmpty(),
avatarData = avatarData,
notificationMode = roomSummary.details.notificationMode,
)
}
null -> null
}

diffCache[index] = roomListRoomSummary
return roomListRoomSummary
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.Immutable
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.RoomNotificationMode

@Immutable
data class RoomListRoomSummary constructor(
Expand All @@ -31,4 +32,5 @@ data class RoomListRoomSummary constructor(
val lastMessage: CharSequence? = null,
val avatarData: AvatarData = AvatarData(id, name, size = AvatarSize.RoomListItem),
val isPlaceholder: Boolean = false,
val notificationMode: RoomNotificationMode? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.matrix.api.room.RoomNotificationMode

open class RoomListRoomSummaryProvider : PreviewParameterProvider<RoomListRoomSummary> {
override val values: Sequence<RoomListRoomSummary>
get() = sequenceOf(
aRoomListRoomSummary(),
aRoomListRoomSummary().copy(lastMessage = null),
aRoomListRoomSummary().copy(hasUnread = true),
aRoomListRoomSummary().copy(timestamp = "88:88"),
aRoomListRoomSummary().copy(hasUnread = true, notificationMode = RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY),
aRoomListRoomSummary().copy(timestamp = "88:88", notificationMode = RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY),
aRoomListRoomSummary().copy(timestamp = "88:88", notificationMode = RoomNotificationMode.MUTE),
aRoomListRoomSummary().copy(timestamp = "88:88", hasUnread = true),
aRoomListRoomSummary().copy(isPlaceholder = true, timestamp = "88:88"),
aRoomListRoomSummary().copy(
Expand Down
Loading