|
|
|
@ -76,9 +76,6 @@ class TimelinePresenter @AssistedInject constructor(
@@ -76,9 +76,6 @@ class TimelinePresenter @AssistedInject constructor(
|
|
|
|
|
@Composable |
|
|
|
|
override fun present(): TimelineState { |
|
|
|
|
val localScope = rememberCoroutineScope() |
|
|
|
|
val focusedEventId: MutableState<EventId?> = rememberSaveable { |
|
|
|
|
mutableStateOf(null) |
|
|
|
|
} |
|
|
|
|
val focusRequestState: MutableState<FocusRequestState> = remember { |
|
|
|
|
mutableStateOf(FocusRequestState.None) |
|
|
|
|
} |
|
|
|
@ -139,23 +136,16 @@ class TimelinePresenter @AssistedInject constructor(
@@ -139,23 +136,16 @@ class TimelinePresenter @AssistedInject constructor(
|
|
|
|
|
navigator.onEditPollClick(event.pollStartId) |
|
|
|
|
} |
|
|
|
|
is TimelineEvents.FocusOnEvent -> localScope.launch { |
|
|
|
|
focusedEventId.value = event.eventId |
|
|
|
|
if (timelineItemIndexer.isKnown(event.eventId)) { |
|
|
|
|
val index = timelineItemIndexer.indexOf(event.eventId) |
|
|
|
|
focusRequestState.value = FocusRequestState.Cached(index) |
|
|
|
|
focusRequestState.value = FocusRequestState.Success(eventId = event.eventId, index = index) |
|
|
|
|
} else { |
|
|
|
|
focusRequestState.value = FocusRequestState.Fetching |
|
|
|
|
timelineController.focusOnEvent(event.eventId) |
|
|
|
|
.fold( |
|
|
|
|
onSuccess = { |
|
|
|
|
focusRequestState.value = FocusRequestState.Fetched |
|
|
|
|
}, |
|
|
|
|
onFailure = { |
|
|
|
|
focusRequestState.value = FocusRequestState.Failure(it) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
focusRequestState.value = FocusRequestState.Loading(eventId = event.eventId) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
is TimelineEvents.OnFocusEventRender -> { |
|
|
|
|
focusRequestState.value = focusRequestState.value.onFocusEventRender() |
|
|
|
|
} |
|
|
|
|
is TimelineEvents.ClearFocusRequestState -> { |
|
|
|
|
focusRequestState.value = FocusRequestState.None |
|
|
|
|
} |
|
|
|
@ -165,16 +155,33 @@ class TimelinePresenter @AssistedInject constructor(
@@ -165,16 +155,33 @@ class TimelinePresenter @AssistedInject constructor(
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LaunchedEffect(focusRequestState.value) { |
|
|
|
|
val currentFocusRequestState = focusRequestState.value |
|
|
|
|
if (currentFocusRequestState is FocusRequestState.Loading) { |
|
|
|
|
val eventId = currentFocusRequestState.eventId |
|
|
|
|
timelineController.focusOnEvent(eventId) |
|
|
|
|
.fold( |
|
|
|
|
onSuccess = { |
|
|
|
|
focusRequestState.value = FocusRequestState.Success(eventId = eventId) |
|
|
|
|
}, |
|
|
|
|
onFailure = { |
|
|
|
|
focusRequestState.value = FocusRequestState.Failure(throwable = it) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LaunchedEffect(timelineItems.size) { |
|
|
|
|
computeNewItemState(timelineItems, prevMostRecentItemId, newEventState) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LaunchedEffect(timelineItems.size, focusRequestState.value, focusedEventId.value) { |
|
|
|
|
val currentFocusedEventId = focusedEventId.value |
|
|
|
|
if (focusRequestState.value is FocusRequestState.Fetched && currentFocusedEventId != null) { |
|
|
|
|
if (timelineItemIndexer.isKnown(currentFocusedEventId)) { |
|
|
|
|
val index = timelineItemIndexer.indexOf(currentFocusedEventId) |
|
|
|
|
focusRequestState.value = FocusRequestState.Cached(index) |
|
|
|
|
LaunchedEffect(timelineItems.size, focusRequestState.value) { |
|
|
|
|
val currentFocusRequestState = focusRequestState.value |
|
|
|
|
if (currentFocusRequestState is FocusRequestState.Success && !currentFocusRequestState.isIndexed) { |
|
|
|
|
val eventId = currentFocusRequestState.eventId |
|
|
|
|
if (timelineItemIndexer.isKnown(eventId)) { |
|
|
|
|
val index = timelineItemIndexer.indexOf(eventId) |
|
|
|
|
focusRequestState.value = FocusRequestState.Success(eventId = eventId, index = index) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -208,7 +215,6 @@ class TimelinePresenter @AssistedInject constructor(
@@ -208,7 +215,6 @@ class TimelinePresenter @AssistedInject constructor(
|
|
|
|
|
renderReadReceipts = renderReadReceipts, |
|
|
|
|
newEventState = newEventState.value, |
|
|
|
|
isLive = isLive, |
|
|
|
|
focusedEventId = focusedEventId.value, |
|
|
|
|
focusRequestState = focusRequestState.value, |
|
|
|
|
eventSink = { handleEvents(it) } |
|
|
|
|
) |
|
|
|
@ -278,3 +284,10 @@ class TimelinePresenter @AssistedInject constructor(
@@ -278,3 +284,10 @@ class TimelinePresenter @AssistedInject constructor(
|
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun FocusRequestState.onFocusEventRender(): FocusRequestState { |
|
|
|
|
return when (this) { |
|
|
|
|
is FocusRequestState.Success -> copy(rendered = true) |
|
|
|
|
else -> this |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|