Merge pull request #2293 from element-hq/feature/bma/notificationCount

Iterate on notification badges
This commit is contained in:
Benoit Marty 2024-01-30 10:33:17 +01:00 committed by GitHub
commit a7541be6bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 138 additions and 150 deletions

1
changelog.d/2282.bugfix Normal file
View file

@ -0,0 +1 @@
Room list Ensure the indicators stay grey if the global setting is set to mention only and a regular message is received.

View file

@ -35,6 +35,7 @@ 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.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
@ -141,7 +142,7 @@ private fun RowScope.NameAndTimestampRow(room: RoomListRoomSummary) {
Text(
text = room.timestamp ?: "",
style = ElementTheme.typography.fontBodySmMedium,
color = if (room.isTimestampHighlighted) {
color = if (room.isHighlighted) {
ElementTheme.colors.unreadIndicator
} else {
MaterialTheme.roomListRoomMessageDate()
@ -165,86 +166,61 @@ private fun RowScope.LastMessageAndIndicatorRow(room: RoomListRoomSummary) {
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
// Unread
// Call and unread
Row(
modifier = Modifier.height(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
// Video call
OnGoingCallIcon(
room.hasRoomCall,
)
// Other indicators
NotificationIcons(
room.userDefinedNotificationMode,
room.numberOfUnreadMessages,
room.numberOfUnreadMentions,
)
val tint = if (room.isHighlighted) ElementTheme.colors.unreadIndicator else ElementTheme.colors.iconQuaternary
if (room.hasRoomCall) {
OnGoingCallIcon(
color = tint,
)
}
if (room.userDefinedNotificationMode == RoomNotificationMode.MUTE) {
NotificationOffIndicatorAtom()
} else if (room.numberOfUnreadMentions > 0) {
MentionIndicatorAtom()
}
if (room.hasNewContent) {
UnreadIndicatorAtom(
color = tint
)
}
}
}
@Composable
private fun OnGoingCallIcon(
hasRoomCall: Boolean,
color: Color,
) {
if (hasRoomCall) {
Icon(
modifier = Modifier.size(16.dp),
imageVector = CompoundIcons.VideoCallSolid,
contentDescription = null,
tint = ElementTheme.colors.unreadIndicator,
)
}
Icon(
modifier = Modifier.size(16.dp),
imageVector = CompoundIcons.VideoCallSolid,
contentDescription = null,
tint = color,
)
}
@Composable
private fun RowScope.NotificationIcons(
userDefinedNotificationMode: RoomNotificationMode?,
numberOfUnreadMessages: Int,
numberOfUnreadMentions: Int,
) {
when (userDefinedNotificationMode) {
null,
RoomNotificationMode.ALL_MESSAGES -> {
if (numberOfUnreadMentions > 0) {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
UnreadIndicatorAtom()
} else if (numberOfUnreadMessages > 0) {
UnreadIndicatorAtom()
}
}
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> {
if (numberOfUnreadMentions > 0) {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
UnreadIndicatorAtom()
} else if (numberOfUnreadMessages > 0) {
UnreadIndicatorAtom(color = ElementTheme.colors.iconQuaternary)
}
}
RoomNotificationMode.MUTE -> {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.NotificationsSolidOff,
tint = ElementTheme.colors.iconQuaternary,
)
if (numberOfUnreadMessages > 0 || numberOfUnreadMentions > 0) {
UnreadIndicatorAtom(color = ElementTheme.colors.iconQuaternary)
}
}
}
private fun NotificationOffIndicatorAtom() {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.NotificationsSolidOff,
tint = ElementTheme.colors.iconQuaternary,
)
}
@Composable
private fun MentionIndicatorAtom() {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
}
@PreviewsDayNight

View file

@ -43,6 +43,7 @@ class RoomListRoomSummaryFactory @Inject constructor(
avatarData = AvatarData(id, "S", size = AvatarSize.RoomListItem),
numberOfUnreadMessages = 0,
numberOfUnreadMentions = 0,
numberOfUnreadNotifications = 0,
userDefinedNotificationMode = null,
hasRoomCall = false,
isDm = false,
@ -69,6 +70,7 @@ class RoomListRoomSummaryFactory @Inject constructor(
name = roomSummary.details.name,
numberOfUnreadMessages = roomSummary.details.numUnreadMessages,
numberOfUnreadMentions = roomSummary.details.numUnreadMentions,
numberOfUnreadNotifications = roomSummary.details.numUnreadNotifications,
timestamp = lastMessageTimestampFormatter.format(roomSummary.details.lastMessageTimestamp),
lastMessage = roomSummary.details.lastMessage?.let { message ->
roomLastMessageFormatter.format(message.event, roomSummary.details.isDirect)

View file

@ -28,6 +28,7 @@ data class RoomListRoomSummary(
val name: String,
val numberOfUnreadMessages: Int,
val numberOfUnreadMentions: Int,
val numberOfUnreadNotifications: Int,
val timestamp: String?,
val lastMessage: CharSequence?,
val avatarData: AvatarData,
@ -36,11 +37,10 @@ data class RoomListRoomSummary(
val hasRoomCall: Boolean,
val isDm: Boolean,
) {
val isTimestampHighlighted = hasRoomCall ||
when (userDefinedNotificationMode) {
null,
RoomNotificationMode.ALL_MESSAGES -> numberOfUnreadMessages > 0 || numberOfUnreadMentions > 0
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> numberOfUnreadMentions > 0
RoomNotificationMode.MUTE -> false
}
val isHighlighted = userDefinedNotificationMode != RoomNotificationMode.MUTE &&
(numberOfUnreadNotifications > 0 || numberOfUnreadMentions > 0)
val hasNewContent = numberOfUnreadMessages > 0 ||
numberOfUnreadMentions > 0 ||
numberOfUnreadNotifications > 0
}

View file

@ -88,6 +88,7 @@ internal fun aRoomListRoomSummary(
name: String = "Room name",
numberOfUnreadMessages: Int = 0,
numberOfUnreadMentions: Int = 0,
numberOfUnreadNotifications: Int = 0,
lastMessage: String? = "Last message",
timestamp: String? = lastMessage?.let { "88:88" },
isPlaceholder: Boolean = false,
@ -101,6 +102,7 @@ internal fun aRoomListRoomSummary(
name = name,
numberOfUnreadMessages = numberOfUnreadMessages,
numberOfUnreadMentions = numberOfUnreadMentions,
numberOfUnreadNotifications = numberOfUnreadNotifications,
timestamp = timestamp,
lastMessage = lastMessage,
avatarData = avatarData,

View file

@ -442,6 +442,7 @@ private val aRoomListRoomSummary = RoomListRoomSummary(
name = A_ROOM_NAME,
numberOfUnreadMentions = 1,
numberOfUnreadMessages = 2,
numberOfUnreadNotifications = 0,
timestamp = A_FORMATTED_DATE,
lastMessage = "",
avatarData = AvatarData(id = A_ROOM_ID.value, name = A_ROOM_NAME, size = AvatarSize.RoomListItem),

View file

@ -42,6 +42,7 @@ data class RoomSummaryDetails(
val lastMessage: RoomMessage?,
val numUnreadMessages: Int,
val numUnreadMentions: Int,
val numUnreadNotifications: Int,
val inviter: RoomMember?,
val userDefinedNotificationMode: RoomNotificationMode?,
val hasRoomCall: Boolean,

View file

@ -37,6 +37,7 @@ class RoomSummaryDetailsFactory(private val roomMessageFactory: RoomMessageFacto
avatarUrl = roomInfo.avatarUrl,
numUnreadMentions = roomInfo.numUnreadMentions.toInt(),
numUnreadMessages = roomInfo.numUnreadMessages.toInt(),
numUnreadNotifications = roomInfo.numUnreadNotifications.toInt(),
lastMessage = latestRoomMessage,
inviter = roomInfo.inviter?.let(RoomMemberMapper::map),
userDefinedNotificationMode = roomInfo.userDefinedNotificationMode?.let(RoomNotificationSettingsMapper::mapMode),

View file

@ -61,6 +61,7 @@ fun aRoomSummaryDetails(
lastMessage: RoomMessage? = aRoomMessage(),
numUnreadMentions: Int = 0,
numUnreadMessages: Int = 0,
numUnreadNotifications: Int = 0,
notificationMode: RoomNotificationMode? = null,
inviter: RoomMember? = null,
canonicalAlias: String? = null,
@ -74,6 +75,7 @@ fun aRoomSummaryDetails(
lastMessage = lastMessage,
numUnreadMentions = numUnreadMentions,
numUnreadMessages = numUnreadMessages,
numUnreadNotifications = numUnreadNotifications,
userDefinedNotificationMode = notificationMode,
inviter = inviter,
canonicalAlias = canonicalAlias,

View file

@ -115,6 +115,7 @@ fun aRoomSummaryDetails(
isDm: Boolean = false,
numUnreadMentions: Int = 0,
numUnreadMessages: Int = 0,
numUnreadNotifications: Int = 0,
) = RoomSummaryDetails(
roomId = roomId,
name = name,
@ -128,4 +129,5 @@ fun aRoomSummaryDetails(
isDm = isDm,
numUnreadMentions = numUnreadMentions,
numUnreadMessages = numUnreadMessages,
numUnreadNotifications = numUnreadNotifications,
)

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:aed38a22a1d3a481d07c6955cc14f2a81ed27d754fb0701113d5ec5b6bb85015
size 14461
oid sha256:a02ead0e9c689ac14337dbfb1d238a4082321aa5e9ce5447135df71358dd36b4
size 14338

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b8194ccafe6f78cb90bbe1d1291a8b04463e57e9fe0a891adb3d1a95cb7b91a9
size 15652
oid sha256:a4b88a625372bd794e8f18fb572cfc642d5738e36916e5639a8aac3fdddf70f8
size 15474

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f9b6e33a825b4fb6379827a9ec28f586e64d05aaf013d8120eccdafa178f6816
size 16714
oid sha256:215750e3ed728fe17ac8b2a12e3867ef3dbaa1b486276fc73b7a1fd334ee831c
size 16573

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:229fbadc49f0ef62434e9f26e7f31f1f94037a358dfc218b552046978ca3a182
size 17874
oid sha256:b8140db57575dc4f447b12bb1369ad0f1cff549679b707dd3e82e1224470a1d4
size 17707

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3951f02f9f2cc0ba1907363ba7fdf1150260b5add22be95d7bea94ec0c52f31e
size 12841
oid sha256:44087f904de812d58363dd64ed95d3007c13d8c97c93b05afd53da7fb4a6b3a7
size 12703

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:324024fbe1bf52291a0352859742d630f688becaed00c3c1eeab4ef96f436d63
size 13943
oid sha256:f2f6c42ffcef69b58758a29b037b06a4844e047e06c2bdd7187fa64c6208ad41
size 13781

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1b6cc4f49d6440ea9ae146ff816ea7ac649a6880924a7be82b2823b1064ce285
size 15454
oid sha256:e3d3386f399049e3903413d93b711f430285f19f1a845a5791b4c1fdfd8566ff
size 15296

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2b3e39f3c7e6606d340bf4462d18f9b4e5329b1e845beb6a4a3d0c1a1dabe5b2
size 13521
oid sha256:8b911a96afcfef14ccfcee87bae860105e4d34c6b06bb5db74334a1494ba0f05
size 13367

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1dfe518ad4ee77539f017a39c684e0ce7bfb733a33161639fdf606a188b13d0
size 22406
oid sha256:eeddf38808c98548f550956dd9338a897f51913944bd1e9adac06117bbd002d9
size 22262

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:176f15fb96c05d5932708c9eb26a98261540f07fa4204a416b67baa2388993e5
size 14775
oid sha256:f6bbad58b0e446703ab76117af2916fbee40196faf8424e36eceac10f625d50c
size 14642

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0f59a1489dc39a6b9fdb3c90a17eb2d604d3f9a422827fe30b6e3251a6a5e54f
size 14131
oid sha256:a47196a390720a7321121c934e44fb524f37e4e5f45feaec6a334d0d8faf893a
size 14151

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f5d8aa34aaebac1defbc0a78aef1f45635e68b58390639d9e8ddaff1e8c95647
size 15261
oid sha256:619163e820ad38561e31c2c231e8df63ef43b6bb39f324eab9cda1d5d7d0212c
size 15242

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4aae70caf5fda4fce4f014d1526456e33da65b8221fa81998d69ba675f1a478d
size 16163
oid sha256:f53362e755ef01ec7eb6d5b5b70d0c55e661d3d0f425f58e396fee9c8df10023
size 16152

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:17419657995b619a72322d54fb148f9ddf689016f2fb0fc385aeaa9d6114d81c
size 17233
oid sha256:bc020ed69f860405af38a99d9710495fe84bad6e11f89ca174ee352b62615deb
size 17225

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:288c85268c3383d5daaa6d45ee8060ca74330e284b5ef807a1cca7706284daf9
size 12686
oid sha256:f5c7efc5dda976509dea1e8259dbe417f655a036cfdbffeaaba5405bc94d52e1
size 12702

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:63d8fe9ff875a9e7223af0c0acfbdc025600580c5a43144bcc650bfc6bc0b696
size 13797
oid sha256:54536f0eaa19b20629a0ebebeeed9ff892a54a8009ac6d06d63a742f4e2791e0
size 13772

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5dda78f4088b9201f0600a06a35d44ca6d407551aeea538392c8a38e9e6fb16e
size 15234
oid sha256:91437deeb71a9a1e7b8d4f0e343275712d320d3c2f44a3f5cda6efa28a49bdff
size 15197

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b6414b6557672508d6bdabe2b40d547b25ef9a73566241e98bc12500b4cf7234
size 13370
oid sha256:dbc09a6ae1619e8a870371bf110654ebd288b686001d892116f6c27cdb3c1919
size 13339

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b5f274b1ad4ca31aaf585d34ce48c2898fbb9ada8294b211fe1440a097da21f6
size 21626
oid sha256:4d40489903e1fa61d91ae44bda36fa2f59f81357edb441a198b27f6f928f6c70
size 21654

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9e13796d33e2ae08bdf7e1b9cc3ae4216e4a4d86054b8172d7054f8758232f03
size 14406
oid sha256:75db8e2faba1070c628a79e193679b67438a8ae0d484f72e52e32d8411605baa
size 14412

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:95659c6503ff1def5f3ec59bf96e9b47ea8f539ba90016c06aee3c1ead4d4387
size 30047
oid sha256:ac45ae9f8aefc681d6f73d46ecd7683ea9f84c646e4b92f9282924aec0d73bcb
size 29980

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:56c5abd33920c390237f2889fceb20f18283c10fd075612ff7abc85bf6e5da52
size 29887
oid sha256:3010426862d9e56245b96d9a0ad9d4468996bfd1a7436254e984b6cad46ccac4
size 29874

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f6415c4b16fca9f9c33fa26c320eba7db63414f9e7f80e4be8c06aadf0d761ef
size 64895
oid sha256:21835cc7375230c585465e400338a92230ac164ba5fbb3c08a81935295798739
size 64818

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eb5cd4ad10a617fdc031c417402c20b8c83c9224ee4e4c40a0803d7399d1d338
size 86439
oid sha256:a477aef8b2a641362996cf27c5630ebb0da670c0fc180e2b2b45eb9b0afab3d4
size 86360

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f6415c4b16fca9f9c33fa26c320eba7db63414f9e7f80e4be8c06aadf0d761ef
size 64895
oid sha256:21835cc7375230c585465e400338a92230ac164ba5fbb3c08a81935295798739
size 64818

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9482d5bdce23a63c4b682fc7ef6c48d3b29c42ae88eb22c0c79876591816ca1c
size 64880
oid sha256:880db00d69af2c419ea11ec199196b2bd4811c7829ced249a899948e6825b2a2
size 64785

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7164dd963d88f12cd5b784d2184e9832b21f4465e42b1b8e687cdfde87e0c853
size 65990
oid sha256:b49b631bb839eb12df9beca2dd48554f128da5decbb1381c9da384020b243f94
size 65875

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:01a3240614334fcacc98cdfe4fcba8d91629f000f6224cda2d2218c8d9fdb7aa
size 66366
oid sha256:33b483b3ef695f55c8a153d8e50b81e244f5125235cc3db559efa861756e6b68
size 66253

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:95659c6503ff1def5f3ec59bf96e9b47ea8f539ba90016c06aee3c1ead4d4387
size 30047
oid sha256:ac45ae9f8aefc681d6f73d46ecd7683ea9f84c646e4b92f9282924aec0d73bcb
size 29980

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ff9327bbe5d92c91bfbe23811fa4776b4fc3c73ab26563a303e27cba4056e5e1
size 89621
oid sha256:cc15def26261d505147ee309d90666a7f9325128332fe6b3d246978044a99f78
size 89554

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:47fce43a17dc5db55f901d43fe2ce6436ad18373129f0ca82ea3aecc07707442
size 67127
oid sha256:71b8af217423a992e17414a084d4b336cfa6d0701a0029ed93bb227596024e85
size 67112

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2d3228cbd10bee0e42b4d6ac09261b6b3d9eb6822f4d6fb8097fbe7ba06b2d8a
size 88321
oid sha256:d9293afdc38af47fe988d78df044178f845e1e9b5dbf78bfd840711d73bb48b0
size 88305

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:47fce43a17dc5db55f901d43fe2ce6436ad18373129f0ca82ea3aecc07707442
size 67127
oid sha256:71b8af217423a992e17414a084d4b336cfa6d0701a0029ed93bb227596024e85
size 67112

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5871901c9988ce8954758e4b6487f8448b11e9f24984bae8bc4a05336fce99e6
size 66896
oid sha256:829115185aa5d0c3c2b91107dfad58dff09357223e5f1df82223fb044a19ec5c
size 66864

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1bea5791ddb9180750462f17e65733a91bb246c6095f3b87477d3f0406d5a800
size 68716
oid sha256:bc15f30e62f68dd8ea3d1a17073328eba61e97e24cd63e5ae9a997287b24145c
size 68682

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:45fdc87068b3eec07720f4d81ed31c7914e3b6ba781dd5bf699a889a859218b1
size 69069
oid sha256:b58177f669fb5aeb03c7b72697feda03492a3df5ec37ebb3a7588fef7e8130f2
size 69041

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:56c5abd33920c390237f2889fceb20f18283c10fd075612ff7abc85bf6e5da52
size 29887
oid sha256:3010426862d9e56245b96d9a0ad9d4468996bfd1a7436254e984b6cad46ccac4
size 29874

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c59880d152c30171ef28b06035067bb8209028eaf66ff77dc0492112a00979e0
size 91200
oid sha256:4908718c873903f2566fd953bd947ad012c822ba3289a8dec96793d3ef879e2b
size 91185