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) {
|
private fun handleStatusChangedEvent(status: Status) {
|
||||||
updateStatusById(status.id) { oldViewData ->
|
updateStatusByActionableId(status.id) { status }
|
||||||
status.toViewData(
|
|
||||||
isShowingContent = oldViewData.isShowingContent,
|
|
||||||
isExpanded = oldViewData.isExpanded,
|
|
||||||
isCollapsed = oldViewData.isCollapsed
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fullReload() {
|
override fun fullReload() {
|
||||||
|
@ -311,7 +305,7 @@ class NetworkTimelineViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearWarning(status: StatusViewData.Concrete) {
|
override fun clearWarning(status: StatusViewData.Concrete) {
|
||||||
updateActionableStatusById(status.id) {
|
updateStatusByActionableId(status.id) {
|
||||||
it.copy(filtered = emptyList())
|
it.copy(filtered = emptyList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,19 +393,11 @@ class NetworkTimelineViewModel @Inject constructor(
|
||||||
currentSource?.invalidate()
|
currentSource?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun updateStatusById(
|
private inline fun updateStatusByActionableId(id: String, updater: (Status) -> Status) {
|
||||||
id: String,
|
// posts can be multiple times in the timeline, e.g. once the original and once as boost
|
||||||
updater: (StatusViewData.Concrete) -> StatusViewData.Concrete
|
statusData.forEachIndexed { index, status ->
|
||||||
) {
|
if (status.asStatusOrNull()?.actionableId == id) {
|
||||||
val pos = statusData.indexOfFirst { it.asStatusOrNull()?.id == id }
|
updateViewDataAt(index) { vd ->
|
||||||
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 ->
|
|
||||||
if (vd.status.reblog != null) {
|
if (vd.status.reblog != null) {
|
||||||
vd.copy(status = vd.status.copy(reblog = updater(vd.status.reblog)))
|
vd.copy(status = vd.status.copy(reblog = updater(vd.status.reblog)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -419,6 +405,8 @@ class NetworkTimelineViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun updateViewDataAt(
|
private inline fun updateViewDataAt(
|
||||||
position: Int,
|
position: Int,
|
||||||
|
|
Loading…
Reference in New Issue