Browse Source

Don't blindly retry fetching pending or failed event details

pull/913/head
Jorge Martín 1 year ago
parent
commit
243a39d6de
  1. 14
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/item/event/EventContent.kt
  2. 2
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/item/event/EventTimelineItem.kt
  3. 3
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/item/event/EventMessageMapper.kt

14
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/item/event/EventContent.kt

@ -35,7 +35,13 @@ data class MessageContent( @@ -35,7 +35,13 @@ data class MessageContent(
sealed interface InReplyTo {
/** The event details are not loaded yet. We can fetch them. */
data class NotLoaded(val eventId: EventId) : InReplyTo
/** The event details are pending to be fetched. We should **not** fetch them again. */
object Pending : InReplyTo
/** The event details are available. */
data class Ready(
val eventId: EventId,
val content: MessageContent,
@ -44,6 +50,14 @@ sealed interface InReplyTo { @@ -44,6 +50,14 @@ sealed interface InReplyTo {
val senderAvatarUrl: String?,
) : InReplyTo
/**
* Fetching the event details failed.
*
* We can try to fetch them again **with a proper retry strategy**, but not blindly:
*
* If the reason for the failure is consistent on the server, we'd enter a loop
* where we keep trying to fetch the same event.
* */
object Error : InReplyTo
}

2
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/item/event/EventTimelineItem.kt

@ -42,6 +42,6 @@ data class EventTimelineItem( @@ -42,6 +42,6 @@ data class EventTimelineItem(
}
fun hasNotLoadedInReplyTo(): Boolean {
val details = inReplyTo()
return details is InReplyTo.NotLoaded || details is InReplyTo.Error
return details is InReplyTo.NotLoaded
}
}

3
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/item/event/EventMessageMapper.kt

@ -58,7 +58,8 @@ class EventMessageMapper { @@ -58,7 +58,8 @@ class EventMessageMapper {
)
}
is RepliedToEventDetails.Error -> InReplyTo.Error
is RepliedToEventDetails.Pending, is RepliedToEventDetails.Unavailable -> InReplyTo.NotLoaded(inReplyToId!!)
is RepliedToEventDetails.Pending -> InReplyTo.Pending
is RepliedToEventDetails.Unavailable -> InReplyTo.NotLoaded(inReplyToId!!)
}
}
MessageContent(

Loading…
Cancel
Save