Remove stale pre-edit statuses from the thread view. (#3377)

Fixes #3366
This commit is contained in:
Levi Bard 2023-03-10 20:24:41 +01:00 committed by GitHub
parent 4d401c7878
commit f71aa55bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -15,6 +15,7 @@ data class MuteEvent(val accountId: String) : Dispatchable
data class StatusDeletedEvent(val statusId: String) : Dispatchable data class StatusDeletedEvent(val statusId: String) : Dispatchable
data class StatusComposedEvent(val status: Status) : Dispatchable data class StatusComposedEvent(val status: Status) : Dispatchable
data class StatusScheduledEvent(val status: Status) : Dispatchable data class StatusScheduledEvent(val status: Status) : Dispatchable
data class StatusEditedEvent(val originalId: String, val status: Status) : Dispatchable
data class ProfileEditedEvent(val newProfileData: Account) : Dispatchable data class ProfileEditedEvent(val newProfileData: Account) : Dispatchable
data class PreferenceChangedEvent(val preferenceKey: String) : Dispatchable data class PreferenceChangedEvent(val preferenceKey: String) : Dispatchable
data class MainTabsChangedEvent(val newTabs: List<TabData>) : Dispatchable data class MainTabsChangedEvent(val newTabs: List<TabData>) : Dispatchable

View File

@ -45,6 +45,7 @@ import com.keylesspalace.tusky.adapter.StatusBaseViewHolder
import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
import com.keylesspalace.tusky.appstore.StatusComposedEvent import com.keylesspalace.tusky.appstore.StatusComposedEvent
import com.keylesspalace.tusky.appstore.StatusEditedEvent
import com.keylesspalace.tusky.components.accountlist.AccountListActivity import com.keylesspalace.tusky.components.accountlist.AccountListActivity
import com.keylesspalace.tusky.components.accountlist.AccountListActivity.Companion.newIntent import com.keylesspalace.tusky.components.accountlist.AccountListActivity.Companion.newIntent
import com.keylesspalace.tusky.components.preference.PreferencesFragment.ReadingOrder import com.keylesspalace.tusky.components.preference.PreferencesFragment.ReadingOrder
@ -303,6 +304,9 @@ class TimelineFragment :
val status = event.status val status = event.status
handleStatusComposeEvent(status) handleStatusComposeEvent(status)
} }
is StatusEditedEvent -> {
handleStatusComposeEvent(event.status)
}
} }
} }
} }

View File

@ -29,6 +29,7 @@ import com.keylesspalace.tusky.appstore.PinEvent
import com.keylesspalace.tusky.appstore.ReblogEvent import com.keylesspalace.tusky.appstore.ReblogEvent
import com.keylesspalace.tusky.appstore.StatusComposedEvent import com.keylesspalace.tusky.appstore.StatusComposedEvent
import com.keylesspalace.tusky.appstore.StatusDeletedEvent import com.keylesspalace.tusky.appstore.StatusDeletedEvent
import com.keylesspalace.tusky.appstore.StatusEditedEvent
import com.keylesspalace.tusky.components.timeline.toViewData import com.keylesspalace.tusky.components.timeline.toViewData
import com.keylesspalace.tusky.components.timeline.util.ifExpected import com.keylesspalace.tusky.components.timeline.util.ifExpected
import com.keylesspalace.tusky.db.AccountManager import com.keylesspalace.tusky.db.AccountManager
@ -92,6 +93,7 @@ class ViewThreadViewModel @Inject constructor(
is BlockEvent -> removeAllByAccountId(event.accountId) is BlockEvent -> removeAllByAccountId(event.accountId)
is StatusComposedEvent -> handleStatusComposedEvent(event) is StatusComposedEvent -> handleStatusComposedEvent(event)
is StatusDeletedEvent -> handleStatusDeletedEvent(event) is StatusDeletedEvent -> handleStatusDeletedEvent(event)
is StatusEditedEvent -> handleStatusEditedEvent(event)
} }
} }
} }
@ -327,6 +329,20 @@ class ViewThreadViewModel @Inject constructor(
} }
} }
private fun handleStatusEditedEvent(event: StatusEditedEvent) {
updateSuccess { uiState ->
uiState.copy(
statusViewData = uiState.statusViewData.map { status ->
if (status.actionableId == event.originalId) {
event.status.toViewData()
} else {
status
}
}
)
}
}
private fun handleStatusDeletedEvent(event: StatusDeletedEvent) { private fun handleStatusDeletedEvent(event: StatusDeletedEvent) {
updateSuccess { uiState -> updateSuccess { uiState ->
uiState.copy( uiState.copy(

View File

@ -21,6 +21,7 @@ import com.keylesspalace.tusky.MainActivity
import com.keylesspalace.tusky.R import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.StatusComposedEvent import com.keylesspalace.tusky.appstore.StatusComposedEvent
import com.keylesspalace.tusky.appstore.StatusEditedEvent
import com.keylesspalace.tusky.appstore.StatusScheduledEvent import com.keylesspalace.tusky.appstore.StatusScheduledEvent
import com.keylesspalace.tusky.components.compose.MediaUploader import com.keylesspalace.tusky.components.compose.MediaUploader
import com.keylesspalace.tusky.components.compose.UploadEvent import com.keylesspalace.tusky.components.compose.UploadEvent
@ -202,16 +203,17 @@ class SendStatusService : Service(), Injectable {
}, },
) )
val sendResult = if (statusToSend.statusId == null) { val editing = (statusToSend.statusId != null)
mastodonApi.createStatus( val sendResult = if (editing) {
mastodonApi.editStatus(
statusToSend.statusId!!,
"Bearer " + account.accessToken, "Bearer " + account.accessToken,
account.domain, account.domain,
statusToSend.idempotencyKey, statusToSend.idempotencyKey,
newStatus newStatus
) )
} else { } else {
mastodonApi.editStatus( mastodonApi.createStatus(
statusToSend.statusId,
"Bearer " + account.accessToken, "Bearer " + account.accessToken,
account.domain, account.domain,
statusToSend.idempotencyKey, statusToSend.idempotencyKey,
@ -232,6 +234,8 @@ class SendStatusService : Service(), Injectable {
if (scheduled) { if (scheduled) {
eventHub.dispatch(StatusScheduledEvent(sentStatus)) eventHub.dispatch(StatusScheduledEvent(sentStatus))
} else if (editing) {
eventHub.dispatch(StatusEditedEvent(statusToSend.statusId!!, sentStatus))
} else { } else {
eventHub.dispatch(StatusComposedEvent(sentStatus)) eventHub.dispatch(StatusComposedEvent(sentStatus))
} }