Cleanup: remove unused summaryLine field.
This commit is contained in:
parent
8e0e8c3f14
commit
71fef289d1
4 changed files with 1 additions and 58 deletions
|
|
@ -9,17 +9,12 @@
|
||||||
package io.element.android.libraries.push.impl.notifications
|
package io.element.android.libraries.push.impl.notifications
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.graphics.Typeface
|
|
||||||
import android.text.style.StyleSpan
|
|
||||||
import androidx.core.text.buildSpannedString
|
|
||||||
import androidx.core.text.inSpans
|
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import dev.zacsweers.metro.AppScope
|
import dev.zacsweers.metro.AppScope
|
||||||
import dev.zacsweers.metro.ContributesBinding
|
import dev.zacsweers.metro.ContributesBinding
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.SessionId
|
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.ThreadId
|
||||||
import io.element.android.libraries.push.impl.R
|
|
||||||
import io.element.android.libraries.push.impl.notifications.factories.NotificationAccountParams
|
import io.element.android.libraries.push.impl.notifications.factories.NotificationAccountParams
|
||||||
import io.element.android.libraries.push.impl.notifications.factories.NotificationCreator
|
import io.element.android.libraries.push.impl.notifications.factories.NotificationCreator
|
||||||
import io.element.android.libraries.push.impl.notifications.model.FallbackNotifiableEvent
|
import io.element.android.libraries.push.impl.notifications.model.FallbackNotifiableEvent
|
||||||
|
|
@ -98,7 +93,6 @@ class DefaultNotificationDataFactory(
|
||||||
notification = notification,
|
notification = notification,
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
threadId = threadId,
|
threadId = threadId,
|
||||||
summaryLine = createRoomMessagesGroupSummaryLine(events, roomName, isDm),
|
|
||||||
messageCount = events.size,
|
messageCount = events.size,
|
||||||
latestTimestamp = events.maxOf { it.timestamp },
|
latestTimestamp = events.maxOf { it.timestamp },
|
||||||
shouldBing = events.any { it.noisy }
|
shouldBing = events.any { it.noisy }
|
||||||
|
|
@ -123,7 +117,6 @@ class DefaultNotificationDataFactory(
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.roomId.value,
|
tag = event.roomId.value,
|
||||||
notification = notificationCreator.createRoomInvitationNotification(notificationAccountParams, event),
|
notification = notificationCreator.createRoomInvitationNotification(notificationAccountParams, event),
|
||||||
summaryLine = event.description,
|
|
||||||
isNoisy = event.noisy,
|
isNoisy = event.noisy,
|
||||||
timestamp = event.timestamp
|
timestamp = event.timestamp
|
||||||
)
|
)
|
||||||
|
|
@ -140,7 +133,6 @@ class DefaultNotificationDataFactory(
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.eventId.value,
|
tag = event.eventId.value,
|
||||||
notification = notificationCreator.createSimpleEventNotification(notificationAccountParams, event),
|
notification = notificationCreator.createSimpleEventNotification(notificationAccountParams, event),
|
||||||
summaryLine = event.description,
|
|
||||||
isNoisy = event.noisy,
|
isNoisy = event.noisy,
|
||||||
timestamp = event.timestamp
|
timestamp = event.timestamp
|
||||||
)
|
)
|
||||||
|
|
@ -157,7 +149,6 @@ class DefaultNotificationDataFactory(
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
tag = event.eventId.value,
|
tag = event.eventId.value,
|
||||||
notification = notificationCreator.createFallbackNotification(notificationAccountParams, event),
|
notification = notificationCreator.createFallbackNotification(notificationAccountParams, event),
|
||||||
summaryLine = event.description.orEmpty(),
|
|
||||||
isNoisy = false,
|
isNoisy = false,
|
||||||
timestamp = event.timestamp
|
timestamp = event.timestamp
|
||||||
)
|
)
|
||||||
|
|
@ -184,53 +175,12 @@ class DefaultNotificationDataFactory(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createRoomMessagesGroupSummaryLine(events: List<NotifiableMessageEvent>, roomName: String, roomIsDm: Boolean): CharSequence {
|
|
||||||
return when (events.size) {
|
|
||||||
1 -> createFirstMessageSummaryLine(events.first(), roomName, roomIsDm)
|
|
||||||
else -> {
|
|
||||||
stringProvider.getQuantityString(
|
|
||||||
R.plurals.notification_compat_summary_line_for_room,
|
|
||||||
events.size,
|
|
||||||
roomName,
|
|
||||||
events.size
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createFirstMessageSummaryLine(event: NotifiableMessageEvent, roomName: String, roomIsDm: Boolean): CharSequence {
|
|
||||||
return if (roomIsDm) {
|
|
||||||
buildSpannedString {
|
|
||||||
event.senderDisambiguatedDisplayName?.let {
|
|
||||||
inSpans(StyleSpan(Typeface.BOLD)) {
|
|
||||||
append(it)
|
|
||||||
append(": ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
append(event.description)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buildSpannedString {
|
|
||||||
inSpans(StyleSpan(Typeface.BOLD)) {
|
|
||||||
append(roomName)
|
|
||||||
append(": ")
|
|
||||||
event.senderDisambiguatedDisplayName?.let {
|
|
||||||
append(it)
|
|
||||||
append(" ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
append(event.description)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class RoomNotification(
|
data class RoomNotification(
|
||||||
val notification: Notification,
|
val notification: Notification,
|
||||||
val roomId: RoomId,
|
val roomId: RoomId,
|
||||||
val threadId: ThreadId?,
|
val threadId: ThreadId?,
|
||||||
val summaryLine: CharSequence,
|
|
||||||
val messageCount: Int,
|
val messageCount: Int,
|
||||||
val latestTimestamp: Long,
|
val latestTimestamp: Long,
|
||||||
val shouldBing: Boolean,
|
val shouldBing: Boolean,
|
||||||
|
|
@ -239,7 +189,6 @@ data class RoomNotification(
|
||||||
return notification == other.notification &&
|
return notification == other.notification &&
|
||||||
roomId == other.roomId &&
|
roomId == other.roomId &&
|
||||||
threadId == other.threadId &&
|
threadId == other.threadId &&
|
||||||
summaryLine.toString() == other.summaryLine.toString() &&
|
|
||||||
messageCount == other.messageCount &&
|
messageCount == other.messageCount &&
|
||||||
latestTimestamp == other.latestTimestamp &&
|
latestTimestamp == other.latestTimestamp &&
|
||||||
shouldBing == other.shouldBing
|
shouldBing == other.shouldBing
|
||||||
|
|
@ -249,7 +198,6 @@ data class RoomNotification(
|
||||||
data class OneShotNotification(
|
data class OneShotNotification(
|
||||||
val notification: Notification,
|
val notification: Notification,
|
||||||
val tag: String,
|
val tag: String,
|
||||||
val summaryLine: CharSequence,
|
|
||||||
val isNoisy: Boolean,
|
val isNoisy: Boolean,
|
||||||
val timestamp: Long,
|
val timestamp: Long,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ class DefaultSummaryGroupMessageCreatorTest {
|
||||||
RoomNotification(
|
RoomNotification(
|
||||||
notification = Notification(),
|
notification = Notification(),
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
summaryLine = "",
|
|
||||||
messageCount = 1,
|
messageCount = 1,
|
||||||
latestTimestamp = A_FAKE_TIMESTAMP + 10,
|
latestTimestamp = A_FAKE_TIMESTAMP + 10,
|
||||||
shouldBing = true,
|
shouldBing = true,
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ class NotificationDataFactoryTest {
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
notification = expectedNotification,
|
notification = expectedNotification,
|
||||||
tag = A_ROOM_ID.value,
|
tag = A_ROOM_ID.value,
|
||||||
summaryLine = AN_INVITATION_EVENT.description,
|
|
||||||
isNoisy = AN_INVITATION_EVENT.noisy,
|
isNoisy = AN_INVITATION_EVENT.noisy,
|
||||||
timestamp = AN_INVITATION_EVENT.timestamp
|
timestamp = AN_INVITATION_EVENT.timestamp
|
||||||
)
|
)
|
||||||
|
|
@ -83,7 +82,6 @@ class NotificationDataFactoryTest {
|
||||||
OneShotNotification(
|
OneShotNotification(
|
||||||
notification = expectedNotification,
|
notification = expectedNotification,
|
||||||
tag = AN_EVENT_ID.value,
|
tag = AN_EVENT_ID.value,
|
||||||
summaryLine = A_SIMPLE_EVENT.description,
|
|
||||||
isNoisy = A_SIMPLE_EVENT.noisy,
|
isNoisy = A_SIMPLE_EVENT.noisy,
|
||||||
timestamp = AN_INVITATION_EVENT.timestamp
|
timestamp = AN_INVITATION_EVENT.timestamp
|
||||||
)
|
)
|
||||||
|
|
@ -105,7 +103,6 @@ class NotificationDataFactoryTest {
|
||||||
existingNotification = null,
|
existingNotification = null,
|
||||||
),
|
),
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
summaryLine = "A room name: Bob Hello world!",
|
|
||||||
messageCount = events.size,
|
messageCount = events.size,
|
||||||
latestTimestamp = events.maxOf { it.timestamp },
|
latestTimestamp = events.maxOf { it.timestamp },
|
||||||
shouldBing = events.any { it.noisy },
|
shouldBing = events.any { it.noisy },
|
||||||
|
|
@ -161,7 +158,6 @@ class NotificationDataFactoryTest {
|
||||||
existingNotification = null,
|
existingNotification = null,
|
||||||
),
|
),
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
summaryLine = "A room name: Bob Hello world!",
|
|
||||||
messageCount = withRedactedRemoved.size,
|
messageCount = withRedactedRemoved.size,
|
||||||
latestTimestamp = withRedactedRemoved.maxOf { it.timestamp },
|
latestTimestamp = withRedactedRemoved.maxOf { it.timestamp },
|
||||||
shouldBing = withRedactedRemoved.any { it.noisy },
|
shouldBing = withRedactedRemoved.any { it.noisy },
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ private const val USE_COMPLETE_NOTIFICATION_FORMAT = true
|
||||||
|
|
||||||
private val A_SUMMARY_NOTIFICATION = SummaryNotification.Update(A_NOTIFICATION)
|
private val A_SUMMARY_NOTIFICATION = SummaryNotification.Update(A_NOTIFICATION)
|
||||||
private val ONE_SHOT_NOTIFICATION =
|
private val ONE_SHOT_NOTIFICATION =
|
||||||
OneShotNotification(notification = A_NOTIFICATION, tag = "ignored", summaryLine = "ignored", isNoisy = false, timestamp = -1)
|
OneShotNotification(notification = A_NOTIFICATION, tag = "ignored", isNoisy = false, timestamp = -1)
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
class NotificationRendererTest {
|
class NotificationRendererTest {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue