Rust sdk : refactor LocalSendState to use the new failure states as iOS does
This commit is contained in:
@@ -84,7 +84,7 @@ internal fun aTimelineItemList(content: TimelineItemEventContent): ImmutableList
|
||||
isMine = false,
|
||||
content = content,
|
||||
groupPosition = TimelineItemGroupPosition.Middle,
|
||||
sendState = LocalEventSendState.SendingFailed.Unrecoverable("Message failed to send"),
|
||||
sendState = LocalEventSendState.Failed.Unknown("Message failed to send"),
|
||||
),
|
||||
aTimelineItemEvent(
|
||||
isMine = false,
|
||||
@@ -107,7 +107,7 @@ internal fun aTimelineItemList(content: TimelineItemEventContent): ImmutableList
|
||||
isMine = true,
|
||||
content = content,
|
||||
groupPosition = TimelineItemGroupPosition.Middle,
|
||||
sendState = LocalEventSendState.SendingFailed.Unrecoverable("Message failed to send"),
|
||||
sendState = LocalEventSendState.Failed.Unknown("Message failed to send"),
|
||||
),
|
||||
aTimelineItemEvent(
|
||||
isMine = true,
|
||||
|
||||
@@ -51,10 +51,10 @@ fun TimelineEventTimestampView(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val formattedTime = event.sentTime
|
||||
val hasUnrecoverableError = event.localSendState is LocalEventSendState.SendingFailed.Unrecoverable
|
||||
val hasError = event.localSendState is LocalEventSendState.Failed
|
||||
val hasEncryptionCritical = event.messageShield?.isCritical.orFalse()
|
||||
val isMessageEdited = event.content.isEdited()
|
||||
val tint = if (hasUnrecoverableError || hasEncryptionCritical) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.secondary
|
||||
val tint = if (hasError || hasEncryptionCritical) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.secondary
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(start = TimelineEventTimestampViewDefaults.spacing))
|
||||
@@ -74,7 +74,7 @@ fun TimelineEventTimestampView(
|
||||
style = ElementTheme.typography.fontBodyXsRegular,
|
||||
color = tint,
|
||||
)
|
||||
if (hasUnrecoverableError) {
|
||||
if (hasError) {
|
||||
Spacer(modifier = Modifier.width(2.dp))
|
||||
Icon(
|
||||
imageVector = CompoundIcons.Error(),
|
||||
|
||||
@@ -27,15 +27,13 @@ class TimelineItemEventForTimestampViewProvider : PreviewParameterProvider<Timel
|
||||
override val values: Sequence<TimelineItem.Event>
|
||||
get() = sequenceOf(
|
||||
aTimelineItemEvent(),
|
||||
// Sending failed recoverable
|
||||
aTimelineItemEvent().copy(localSendState = LocalEventSendState.SendingFailed.Recoverable("AN_ERROR")),
|
||||
// Sending failed unrecoverable
|
||||
aTimelineItemEvent().copy(localSendState = LocalEventSendState.SendingFailed.Unrecoverable("AN_ERROR")),
|
||||
aTimelineItemEvent().copy(localSendState = LocalEventSendState.Sending),
|
||||
aTimelineItemEvent().copy(localSendState = LocalEventSendState.Failed.Unknown("AN_ERROR")),
|
||||
// Edited
|
||||
aTimelineItemEvent().copy(content = aTimelineItemTextContent().copy(isEdited = true)),
|
||||
// Sending failed + Edited (not sure this is possible IRL, but should be covered by test)
|
||||
aTimelineItemEvent().copy(
|
||||
localSendState = LocalEventSendState.SendingFailed.Unrecoverable("AN_ERROR"),
|
||||
localSendState = LocalEventSendState.Failed.Unknown("AN_ERROR"),
|
||||
content = aTimelineItemTextContent().copy(isEdited = true),
|
||||
),
|
||||
aTimelineItemEvent().copy(
|
||||
|
||||
@@ -26,7 +26,7 @@ class ReadReceiptViewStateForTimelineItemEventRowProvider :
|
||||
override val values: Sequence<ReadReceiptViewState>
|
||||
get() = sequenceOf(
|
||||
aReadReceiptViewState(
|
||||
sendState = LocalEventSendState.NotSentYet
|
||||
sendState = LocalEventSendState.Sending,
|
||||
),
|
||||
aReadReceiptViewState(
|
||||
sendState = LocalEventSendState.Sent(EventId("\$eventId")),
|
||||
|
||||
@@ -29,7 +29,7 @@ class ReadReceiptViewStateProvider : PreviewParameterProvider<ReadReceiptViewSta
|
||||
override val values: Sequence<ReadReceiptViewState>
|
||||
get() = sequenceOf(
|
||||
aReadReceiptViewState(),
|
||||
aReadReceiptViewState(sendState = LocalEventSendState.NotSentYet),
|
||||
aReadReceiptViewState(sendState = LocalEventSendState.Sending),
|
||||
aReadReceiptViewState(sendState = LocalEventSendState.Sent(EventId("\$eventId"))),
|
||||
aReadReceiptViewState(
|
||||
sendState = LocalEventSendState.Sent(EventId("\$eventId")),
|
||||
|
||||
@@ -70,19 +70,18 @@ fun TimelineItemReadReceiptView(
|
||||
ReadReceiptsAvatars(
|
||||
receipts = state.receipts,
|
||||
modifier = Modifier
|
||||
.testTag(TestTags.messageReadReceipts)
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.clickable {
|
||||
onReadReceiptsClick()
|
||||
}
|
||||
.padding(2.dp)
|
||||
.testTag(TestTags.messageReadReceipts)
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.clickable {
|
||||
onReadReceiptsClick()
|
||||
}
|
||||
.padding(2.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
when (state.sendState) {
|
||||
LocalEventSendState.NotSentYet,
|
||||
is LocalEventSendState.SendingFailed.Recoverable -> {
|
||||
LocalEventSendState.Sending -> {
|
||||
ReadReceiptsRow(modifier) {
|
||||
Icon(
|
||||
modifier = Modifier.padding(2.dp),
|
||||
@@ -92,7 +91,7 @@ fun TimelineItemReadReceiptView(
|
||||
)
|
||||
}
|
||||
}
|
||||
is LocalEventSendState.SendingFailed.Unrecoverable -> {
|
||||
is LocalEventSendState.Failed -> {
|
||||
// Error? The timestamp is already displayed in red
|
||||
}
|
||||
null,
|
||||
@@ -119,9 +118,9 @@ private fun ReadReceiptsRow(
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(AvatarSize.TimelineReadReceipt.dp + 8.dp)
|
||||
.padding(horizontal = 18.dp),
|
||||
.fillMaxWidth()
|
||||
.height(AvatarSize.TimelineReadReceipt.dp + 8.dp)
|
||||
.padding(horizontal = 18.dp),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
@@ -160,11 +159,11 @@ private fun ReadReceiptsAvatars(
|
||||
.forEachIndexed { index, readReceiptData ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(end = (12.dp + avatarStrokeSize * 2) * index)
|
||||
.size(size = avatarSize + avatarStrokeSize * 2)
|
||||
.clip(CircleShape)
|
||||
.background(avatarStrokeColor)
|
||||
.zIndex(index.toFloat()),
|
||||
.padding(end = (12.dp + avatarStrokeSize * 2) * index)
|
||||
.size(size = avatarSize + avatarStrokeSize * 2)
|
||||
.clip(CircleShape)
|
||||
.background(avatarStrokeColor)
|
||||
.zIndex(index.toFloat()),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Avatar(
|
||||
|
||||
@@ -90,7 +90,7 @@ sealed interface TimelineItem {
|
||||
|
||||
val safeSenderName: String = senderProfile.getDisambiguatedDisplayName(senderId)
|
||||
|
||||
val failedToSend: Boolean = localSendState is LocalEventSendState.SendingFailed
|
||||
val failedToSend: Boolean = localSendState is LocalEventSendState.Failed
|
||||
|
||||
val isTextMessage: Boolean = content is TimelineItemTextBasedContent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user