Skip to content

Commit faeffc3

Browse files
perf(conversation list): drop a deleted conversation from the list at once
Deleting left the row in place until the worker had finished and the list had been fetched again. It now disappears on confirmation, reusing the guard that hides a conversation being left, and comes back if the delete fails. Assisted-by: Claude Code:claude-opus-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 581c4cf commit faeffc3

2 files changed

Lines changed: 44 additions & 35 deletions

File tree

‎app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt‎

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,15 +1288,15 @@ class ConversationsListActivity : BaseActivity() {
12881288
@SuppressLint("StringFormatInvalid")
12891289
private fun showLeaveConversationSnackbar(conversation: ConversationModel) {
12901290
val token = conversation.token ?: return
1291-
conversationsListViewModel.markConversationPendingLeave(token)
1291+
conversationsListViewModel.markConversationPendingRemoval(token)
12921292
lifecycleScope.launch {
12931293
val result = snackbarHostState.showSnackbar(
12941294
message = String.format(resources.getString(R.string.left_conversation), conversation.displayName),
12951295
actionLabel = getString(R.string.nc_undo),
12961296
duration = SnackbarDuration.Long
12971297
)
12981298
when (result) {
1299-
SnackbarResult.ActionPerformed -> conversationsListViewModel.clearConversationPendingLeave(token)
1299+
SnackbarResult.ActionPerformed -> conversationsListViewModel.clearConversationPendingRemoval(token)
13001300
SnackbarResult.Dismissed -> leaveConversation(conversation)
13011301
}
13021302
}
@@ -1324,12 +1324,12 @@ class ConversationsListActivity : BaseActivity() {
13241324
resources.getString(R.string.nc_shortcut_conversation_deleted)
13251325
)
13261326
}
1327-
conversationsListViewModel.clearConversationPendingLeave(token)
1327+
conversationsListViewModel.clearConversationPendingRemoval(token)
13281328
fetchRooms()
13291329
}
13301330
WorkInfo.State.FAILED -> {
13311331
logger.e(TAG, "LeaveConversationWorker failed for token $token")
1332-
conversationsListViewModel.clearConversationPendingLeave(token)
1332+
conversationsListViewModel.clearConversationPendingRemoval(token)
13331333
showSnackbar(resources.getString(R.string.nc_common_error_sorry))
13341334
}
13351335
else -> {}
@@ -1346,6 +1346,7 @@ class ConversationsListActivity : BaseActivity() {
13461346
.setTitle(R.string.nc_delete_call)
13471347
.setMessage(R.string.nc_delete_conversation_more)
13481348
.setPositiveButton(R.string.nc_delete) { _, _ ->
1349+
conversation.token?.let { conversationsListViewModel.markConversationPendingRemoval(it) }
13491350
deleteConversation(conversation)
13501351
}
13511352
.setNegativeButton(R.string.nc_cancel) { _, _ ->
@@ -1567,32 +1568,40 @@ class ConversationsListActivity : BaseActivity() {
15671568

15681569
WorkManager.getInstance(context).getWorkInfoByIdLiveData(deleteConversationWorker.id)
15691570
.observeForever { workInfo: WorkInfo? ->
1570-
if (workInfo != null) {
1571-
when (workInfo.state) {
1572-
WorkInfo.State.SUCCEEDED -> {
1573-
currentUser.id?.let { userId ->
1574-
ShortcutManagerHelper.disableConversationShortcut(
1575-
context,
1576-
conversation.token,
1577-
userId,
1578-
context.resources.getString(R.string.nc_shortcut_conversation_deleted)
1579-
)
1580-
}
1581-
showSnackbar(
1582-
String.format(
1583-
context.resources.getString(R.string.deleted_conversation),
1584-
conversation.displayName
1585-
)
1571+
when (workInfo?.state) {
1572+
WorkInfo.State.SUCCEEDED -> {
1573+
currentUser.id?.let { userId ->
1574+
ShortcutManagerHelper.disableConversationShortcut(
1575+
context,
1576+
conversation.token,
1577+
userId,
1578+
context.resources.getString(R.string.nc_shortcut_conversation_deleted)
15861579
)
15871580
}
1581+
conversation.token?.let { conversationsListViewModel.clearConversationPendingRemoval(it) }
1582+
// the worker only deletes the room on the server, so without this the entry
1583+
// comes back as soon as it stops being hidden
1584+
fetchRooms()
1585+
showSnackbar(
1586+
String.format(
1587+
context.resources.getString(R.string.deleted_conversation),
1588+
conversation.displayName
1589+
)
1590+
)
1591+
}
15881592

1589-
WorkInfo.State.FAILED -> {
1590-
logger.e(TAG, "DeleteConversationWorker failed for token ${conversation.token}")
1591-
showSnackbar(context.resources.getString(R.string.nc_common_error_sorry))
1592-
}
1593+
WorkInfo.State.FAILED -> {
1594+
logger.e(TAG, "DeleteConversationWorker failed for token ${conversation.token}")
1595+
conversation.token?.let { conversationsListViewModel.clearConversationPendingRemoval(it) }
1596+
showSnackbar(context.resources.getString(R.string.nc_common_error_sorry))
1597+
}
15931598

1594-
else -> {
1595-
}
1599+
WorkInfo.State.CANCELLED -> {
1600+
// nothing was deleted, so the entry must not stay hidden
1601+
conversation.token?.let { conversationsListViewModel.clearConversationPendingRemoval(it) }
1602+
}
1603+
1604+
else -> {
15961605
}
15971606
}
15981607
}

‎app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ class ConversationsListViewModel @AssistedInject constructor(
242242

243243
private val hideRoomToken = MutableStateFlow<String?>(null)
244244

245-
/** Tokens of rooms being left; hidden optimistically while the leave-undo snackbar is showing. */
246-
private val pendingLeaveTokens = MutableStateFlow<Set<String>>(emptySet())
245+
/** Tokens of rooms being left or deleted; hidden optimistically until the request finished. */
246+
private val pendingRemovalTokens = MutableStateFlow<Set<String>>(emptySet())
247247

248-
private val excludedRoomTokens = combine(hideRoomToken, pendingLeaveTokens) { hideToken, pendingTokens ->
248+
private val excludedRoomTokens = combine(hideRoomToken, pendingRemovalTokens) { hideToken, pendingTokens ->
249249
if (hideToken != null) pendingTokens + hideToken else pendingTokens
250250
}
251251

@@ -387,14 +387,14 @@ class ConversationsListViewModel @AssistedInject constructor(
387387
hideRoomToken.value = token
388388
}
389389

390-
/** Optimistically hide a room while its leave-undo snackbar is showing. */
391-
fun markConversationPendingLeave(token: String) {
392-
pendingLeaveTokens.value = pendingLeaveTokens.value + token
390+
/** Optimistically hide a room that is being left or deleted. */
391+
fun markConversationPendingRemoval(token: String) {
392+
pendingRemovalTokens.value = pendingRemovalTokens.value + token
393393
}
394394

395-
/** Un-hide a room, either because the leave was undone or because it finished/failed. */
396-
fun clearConversationPendingLeave(token: String) {
397-
pendingLeaveTokens.value = pendingLeaveTokens.value - token
395+
/** Un-hide a room, either because the removal was undone or because it finished or failed. */
396+
fun clearConversationPendingRemoval(token: String) {
397+
pendingRemovalTokens.value = pendingRemovalTokens.value - token
398398
}
399399

400400
fun getFederationInvitations() {

0 commit comments

Comments
 (0)