Unify the way we decide whether a room is a DM or a group room (#3100)
* Add centralised 'room is DM' check Also add extension functions for `MatrixRoom` and `MatrixRoomInfo`. * Use the centralised method and extension functions through the app, including: - Room list. - Room details screen. - Invites. - Notifications. Replace most `isDirect` usages with `isDm`. * Update screenshots --------- Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
parent
1a03edbe63
commit
0be7058416
47 changed files with 195 additions and 73 deletions
|
|
@ -79,7 +79,7 @@ class DefaultCallNotificationEventResolver @Inject constructor(
|
|||
senderDisambiguatedDisplayName = getDisambiguatedDisplayName(content.senderId),
|
||||
body = "☎️ ${stringProvider.getString(R.string.notification_incoming_call)}",
|
||||
roomName = roomDisplayName,
|
||||
roomIsDirect = isDirect,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
senderAvatarPath = senderAvatarUrl,
|
||||
type = EventType.CALL_NOTIFY,
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
body = notificationBody,
|
||||
imageUriString = fetchImageIfPresent(client)?.toString(),
|
||||
roomName = roomDisplayName,
|
||||
roomIsDirect = isDirect,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
senderAvatarPath = senderAvatarUrl,
|
||||
)
|
||||
|
|
@ -168,7 +168,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
body = stringProvider.getString(CommonStrings.common_call_invite),
|
||||
imageUriString = fetchImageIfPresent(client)?.toString(),
|
||||
roomName = roomDisplayName,
|
||||
roomIsDirect = isDirect,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
senderAvatarPath = senderAvatarUrl,
|
||||
)
|
||||
|
|
@ -197,7 +197,7 @@ class DefaultNotifiableEventResolver @Inject constructor(
|
|||
body = stringProvider.getString(CommonStrings.common_poll_summary, content.question),
|
||||
imageUriString = null,
|
||||
roomName = roomDisplayName,
|
||||
roomIsDirect = isDirect,
|
||||
roomIsDm = isDm,
|
||||
roomAvatarPath = roomAvatarUrl,
|
||||
senderAvatarPath = senderAvatarUrl,
|
||||
)
|
||||
|
|
@ -330,7 +330,7 @@ internal fun buildNotifiableMessageEvent(
|
|||
imageUriString: String? = null,
|
||||
threadId: ThreadId? = null,
|
||||
roomName: String? = null,
|
||||
roomIsDirect: Boolean = false,
|
||||
roomIsDm: Boolean = false,
|
||||
roomAvatarPath: String? = null,
|
||||
senderAvatarPath: String? = null,
|
||||
soundName: String? = null,
|
||||
|
|
@ -354,7 +354,7 @@ internal fun buildNotifiableMessageEvent(
|
|||
imageUriString = imageUriString,
|
||||
threadId = threadId,
|
||||
roomName = roomName,
|
||||
roomIsDirect = roomIsDirect,
|
||||
roomIsDm = roomIsDm,
|
||||
roomAvatarPath = roomAvatarPath,
|
||||
senderAvatarPath = senderAvatarPath,
|
||||
soundName = soundName,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import io.element.android.libraries.matrix.api.core.SessionId
|
|||
import io.element.android.libraries.matrix.api.core.ThreadId
|
||||
import io.element.android.libraries.matrix.api.core.asEventId
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||
import io.element.android.libraries.matrix.api.room.isDm
|
||||
import io.element.android.libraries.matrix.api.timeline.ReceiptType
|
||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStoreFactory
|
||||
import io.element.android.libraries.push.api.notifications.NotificationDrawerManager
|
||||
|
|
@ -160,7 +161,7 @@ class NotificationBroadcastReceiverHandler @Inject constructor(
|
|||
imageUriString = null,
|
||||
threadId = threadId,
|
||||
roomName = room.displayName,
|
||||
roomIsDirect = room.isDirect,
|
||||
roomIsDm = room.isDm,
|
||||
outGoingMessage = true,
|
||||
)
|
||||
onNotifiableEventReceived.onNotifiableEventReceived(notifiableMessageEvent)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class DefaultNotificationDataFactory @Inject constructor(
|
|||
.groupBy { it.roomId }
|
||||
return messagesToDisplay.map { (roomId, events) ->
|
||||
val roomName = events.lastOrNull()?.roomName ?: roomId.value
|
||||
val isDirect = events.lastOrNull()?.roomIsDirect ?: false
|
||||
val isDm = events.lastOrNull()?.roomIsDm ?: false
|
||||
val notification = roomGroupMessageCreator.createRoomMessage(
|
||||
currentUser = currentUser,
|
||||
events = events,
|
||||
|
|
@ -90,7 +90,7 @@ class DefaultNotificationDataFactory @Inject constructor(
|
|||
RoomNotification(
|
||||
notification = notification,
|
||||
roomId = roomId,
|
||||
summaryLine = createRoomMessagesGroupSummaryLine(events, roomName, isDirect),
|
||||
summaryLine = createRoomMessagesGroupSummaryLine(events, roomName, isDm),
|
||||
messageCount = events.size,
|
||||
latestTimestamp = events.maxOf { it.timestamp },
|
||||
shouldBing = events.any { it.noisy }
|
||||
|
|
@ -167,9 +167,9 @@ class DefaultNotificationDataFactory @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createRoomMessagesGroupSummaryLine(events: List<NotifiableMessageEvent>, roomName: String, roomIsDirect: Boolean): CharSequence {
|
||||
private fun createRoomMessagesGroupSummaryLine(events: List<NotifiableMessageEvent>, roomName: String, roomIsDm: Boolean): CharSequence {
|
||||
return when (events.size) {
|
||||
1 -> createFirstMessageSummaryLine(events.first(), roomName, roomIsDirect)
|
||||
1 -> createFirstMessageSummaryLine(events.first(), roomName, roomIsDm)
|
||||
else -> {
|
||||
stringProvider.getQuantityString(
|
||||
R.plurals.notification_compat_summary_line_for_room,
|
||||
|
|
@ -181,8 +181,8 @@ class DefaultNotificationDataFactory @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createFirstMessageSummaryLine(event: NotifiableMessageEvent, roomName: String, roomIsDirect: Boolean): CharSequence {
|
||||
return if (roomIsDirect) {
|
||||
private fun createFirstMessageSummaryLine(event: NotifiableMessageEvent, roomName: String, roomIsDm: Boolean): CharSequence {
|
||||
return if (roomIsDm) {
|
||||
buildSpannedString {
|
||||
event.senderDisambiguatedDisplayName?.let {
|
||||
inSpans(StyleSpan(Typeface.BOLD)) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ data class RoomEventGroupInfo(
|
|||
val sessionId: SessionId,
|
||||
val roomId: RoomId,
|
||||
val roomDisplayName: String,
|
||||
val isDirect: Boolean = false,
|
||||
val isDm: Boolean = false,
|
||||
// An event in the list has not yet been display
|
||||
val hasNewEvent: Boolean = false,
|
||||
// true if at least one on the not yet displayed event is noisy
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class DefaultRoomGroupMessageCreator @Inject constructor(
|
|||
): Notification {
|
||||
val lastKnownRoomEvent = events.last()
|
||||
val roomName = lastKnownRoomEvent.roomName ?: lastKnownRoomEvent.senderDisambiguatedDisplayName ?: "Room name (${roomId.value.take(8)}…)"
|
||||
val roomIsGroup = !lastKnownRoomEvent.roomIsDirect
|
||||
val roomIsGroup = !lastKnownRoomEvent.roomIsDm
|
||||
|
||||
val tickerText = if (roomIsGroup) {
|
||||
stringProvider.getString(R.string.notification_ticker_text_group, roomName, events.last().senderDisambiguatedDisplayName, events.last().description)
|
||||
|
|
@ -68,12 +68,13 @@ class DefaultRoomGroupMessageCreator @Inject constructor(
|
|||
|
||||
val lastMessageTimestamp = events.last().timestamp
|
||||
val smartReplyErrors = events.filter { it.isSmartReplyError() }
|
||||
val roomIsDm = !roomIsGroup
|
||||
return notificationCreator.createMessagesListNotification(
|
||||
RoomEventGroupInfo(
|
||||
sessionId = currentUser.userId,
|
||||
roomId = roomId,
|
||||
roomDisplayName = roomName,
|
||||
isDirect = !roomIsGroup,
|
||||
isDm = roomIsDm,
|
||||
hasSmartReplyError = smartReplyErrors.isNotEmpty(),
|
||||
shouldBing = events.any { it.noisy },
|
||||
customSound = events.last().soundName,
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class DefaultNotificationCreator @Inject constructor(
|
|||
|
||||
val messagingStyle = existingNotification?.let {
|
||||
MessagingStyle.extractMessagingStyleFromNotification(it)
|
||||
} ?: messagingStyleFromCurrentUser(roomInfo.sessionId, currentUser, imageLoader, roomInfo.roomDisplayName, !roomInfo.isDirect)
|
||||
} ?: messagingStyleFromCurrentUser(roomInfo.sessionId, currentUser, imageLoader, roomInfo.roomDisplayName, !roomInfo.isDm)
|
||||
|
||||
messagingStyle.addMessagesFromEvents(events, imageLoader)
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ data class NotifiableMessageEvent(
|
|||
val imageUriString: String?,
|
||||
val threadId: ThreadId?,
|
||||
val roomName: String?,
|
||||
val roomIsDirect: Boolean = false,
|
||||
val roomIsDm: Boolean = false,
|
||||
val roomAvatarPath: String? = null,
|
||||
val senderAvatarPath: String? = null,
|
||||
val soundName: String? = null,
|
||||
|
|
|
|||
|
|
@ -473,7 +473,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
imageUriString = null,
|
||||
threadId = null,
|
||||
roomName = null,
|
||||
roomIsDirect = false,
|
||||
roomAvatarPath = null,
|
||||
senderAvatarPath = null,
|
||||
soundName = null,
|
||||
|
|
@ -544,7 +543,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
roomId = A_ROOM_ID,
|
||||
threadId = null,
|
||||
roomName = null,
|
||||
roomIsDirect = false,
|
||||
canBeReplaced = false,
|
||||
isRedacted = false,
|
||||
imageUriString = null,
|
||||
|
|
@ -578,7 +576,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
roomId = A_ROOM_ID,
|
||||
threadId = null,
|
||||
roomName = null,
|
||||
roomIsDirect = false,
|
||||
canBeReplaced = false,
|
||||
isRedacted = false,
|
||||
imageUriString = null,
|
||||
|
|
@ -686,6 +683,7 @@ class DefaultNotifiableEventResolverTest {
|
|||
timestamp = timestamp,
|
||||
content = content,
|
||||
hasMention = hasMention,
|
||||
isDm = false,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -704,7 +702,6 @@ class DefaultNotifiableEventResolverTest {
|
|||
imageUriString = null,
|
||||
threadId = null,
|
||||
roomName = null,
|
||||
roomIsDirect = false,
|
||||
roomAvatarPath = null,
|
||||
senderAvatarPath = null,
|
||||
soundName = null,
|
||||
|
|
|
|||
|
|
@ -188,14 +188,14 @@ class DefaultRoomGroupMessageCreatorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `test createRoomMessage for direct room`() = runTest {
|
||||
fun `test createRoomMessage for DM`() = runTest {
|
||||
val sut = createRoomGroupMessageCreator()
|
||||
val fakeImageLoader = FakeImageLoader()
|
||||
val result = sut.createRoomMessage(
|
||||
currentUser = aMatrixUser(),
|
||||
events = listOf(
|
||||
aNotifiableMessageEvent(timestamp = A_TIMESTAMP).copy(
|
||||
roomIsDirect = true,
|
||||
roomIsDm = true,
|
||||
),
|
||||
),
|
||||
roomId = A_ROOM_ID,
|
||||
|
|
|
|||
|
|
@ -227,7 +227,6 @@ class DefaultNotificationCreatorTest {
|
|||
sessionId = A_SESSION_ID,
|
||||
roomId = A_ROOM_ID,
|
||||
roomDisplayName = "roomDisplayName",
|
||||
isDirect = false,
|
||||
hasSmartReplyError = false,
|
||||
shouldBing = false,
|
||||
customSound = null,
|
||||
|
|
@ -254,7 +253,6 @@ class DefaultNotificationCreatorTest {
|
|||
sessionId = A_SESSION_ID,
|
||||
roomId = A_ROOM_ID,
|
||||
roomDisplayName = "roomDisplayName",
|
||||
isDirect = false,
|
||||
hasSmartReplyError = false,
|
||||
shouldBing = true,
|
||||
customSound = null,
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ fun aNotifiableMessageEvent(
|
|||
roomId = roomId,
|
||||
threadId = threadId,
|
||||
roomName = "room-name",
|
||||
roomIsDirect = false,
|
||||
canBeReplaced = false,
|
||||
isRedacted = isRedacted,
|
||||
imageUriString = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue