fix boosting and voting in boosted statuses (this time for real)

This commit is contained in:
Konrad Pozniak 2021-07-01 20:54:02 +02:00
parent 15c43f9971
commit 4ff0989835
1 changed files with 6 additions and 15 deletions

View File

@ -369,7 +369,7 @@ class TimelineViewModel @Inject constructor(
fun voteInPoll(position: Int, choices: List<Int>): Job = viewModelScope.launch { fun voteInPoll(position: Int, choices: List<Int>): Job = viewModelScope.launch {
val status = statuses[position].asStatusOrNull() ?: return@launch val status = statuses[position].asStatusOrNull() ?: return@launch
val poll = status.status.poll ?: run { val poll = status.actionable.poll ?: run {
Log.w(TAG, "No poll on status ${status.id}") Log.w(TAG, "No poll on status ${status.id}")
return@launch return@launch
} }
@ -390,8 +390,8 @@ class TimelineViewModel @Inject constructor(
status: StatusViewData.Concrete, status: StatusViewData.Concrete,
newPoll: Poll newPoll: Poll
) { ) {
updateStatusById(status.id) { updateActionableStatusById(status.id) {
it.copy(status = it.status.copy(poll = newPoll)) it.copy(poll = newPoll)
} }
} }
@ -712,8 +712,8 @@ class TimelineViewModel @Inject constructor(
} }
private fun handleReblogEvent(reblogEvent: ReblogEvent) { private fun handleReblogEvent(reblogEvent: ReblogEvent) {
updateStatusById(reblogEvent.statusId) { updateActionableStatusById(reblogEvent.statusId) {
it.copy(status = it.status.copy(reblogged = reblogEvent.reblog)) it.copy(reblogged = reblogEvent.reblog)
} }
} }
@ -862,7 +862,7 @@ class TimelineViewModel @Inject constructor(
id: String, id: String,
updater: (Status) -> Status updater: (Status) -> Status
) { ) {
val pos = statuses.indexOfFirst { it.asStatusOrNull()?.id == id } val pos = statuses.indexOfFirst { it.asStatusOrNull()?.actionableId == id }
if (pos == -1) return if (pos == -1) return
updateStatusAt(pos) { updateStatusAt(pos) {
if (it.status.reblog != null) { if (it.status.reblog != null) {
@ -873,15 +873,6 @@ class TimelineViewModel @Inject constructor(
} }
} }
private inline fun updateStatusById(
id: String,
updater: (StatusViewData.Concrete) -> StatusViewData.Concrete
) {
val pos = statuses.indexOfFirst { it.asStatusOrNull()?.id == id }
if (pos == -1) return
updateStatusAt(pos, updater)
}
private inline fun updateStatusAt( private inline fun updateStatusAt(
position: Int, position: Int,
updater: (StatusViewData.Concrete) -> StatusViewData.Concrete updater: (StatusViewData.Concrete) -> StatusViewData.Concrete