fix updating boosts in network timeline (#4549)
re: https://infosec.exchange/@webhat/112745609655586468 Boost were not correctly handled here, probably because they are only on profile timelines which I rarely check. This makes sure likes and boosts get correctly set to posts even when they are boosts.
This commit is contained in:
parent
000af7fb94
commit
fcd6e9c67b
|
@ -295,13 +295,7 @@ class NetworkTimelineViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleStatusChangedEvent(status: Status) {
|
||||
updateStatusById(status.id) { oldViewData ->
|
||||
status.toViewData(
|
||||
isShowingContent = oldViewData.isShowingContent,
|
||||
isExpanded = oldViewData.isExpanded,
|
||||
isCollapsed = oldViewData.isCollapsed
|
||||
)
|
||||
}
|
||||
updateStatusByActionableId(status.id) { status }
|
||||
}
|
||||
|
||||
override fun fullReload() {
|
||||
|
@ -311,7 +305,7 @@ class NetworkTimelineViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun clearWarning(status: StatusViewData.Concrete) {
|
||||
updateActionableStatusById(status.id) {
|
||||
updateStatusByActionableId(status.id) {
|
||||
it.copy(filtered = emptyList())
|
||||
}
|
||||
}
|
||||
|
@ -399,19 +393,11 @@ class NetworkTimelineViewModel @Inject constructor(
|
|||
currentSource?.invalidate()
|
||||
}
|
||||
|
||||
private inline fun updateStatusById(
|
||||
id: String,
|
||||
updater: (StatusViewData.Concrete) -> StatusViewData.Concrete
|
||||
) {
|
||||
val pos = statusData.indexOfFirst { it.asStatusOrNull()?.id == id }
|
||||
if (pos == -1) return
|
||||
updateViewDataAt(pos, updater)
|
||||
}
|
||||
|
||||
private inline fun updateActionableStatusById(id: String, updater: (Status) -> Status) {
|
||||
val pos = statusData.indexOfFirst { it.asStatusOrNull()?.id == id }
|
||||
if (pos == -1) return
|
||||
updateViewDataAt(pos) { vd ->
|
||||
private inline fun updateStatusByActionableId(id: String, updater: (Status) -> Status) {
|
||||
// posts can be multiple times in the timeline, e.g. once the original and once as boost
|
||||
statusData.forEachIndexed { index, status ->
|
||||
if (status.asStatusOrNull()?.actionableId == id) {
|
||||
updateViewDataAt(index) { vd ->
|
||||
if (vd.status.reblog != null) {
|
||||
vd.copy(status = vd.status.copy(reblog = updater(vd.status.reblog)))
|
||||
} else {
|
||||
|
@ -419,6 +405,8 @@ class NetworkTimelineViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun updateViewDataAt(
|
||||
position: Int,
|
||||
|
|
Loading…
Reference in New Issue