Skip to content

Commit 982316b

Browse files
VelikovPetarclaude
andauthored
Fix delete message not working when offline (SYNC_NEEDED) (#6184)
* Fix delete message not working when offline (SYNC_NEEDED) Co-Authored-By: Claude <noreply@anthropic.com> * Update DeleteMessageListener tests for SYNC_NEEDED remote delete Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ab79e25 commit 982316b

4 files changed

Lines changed: 14 additions & 20 deletions

File tree

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/message/MessageUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ public fun Message.shouldDeleteRemote(currentUserId: String?): Result<Unit> {
230230
return Result.Failure(error)
231231
}
232232
// 2. type = 'error'/'ephemeral' - not persisted on server, delete only locally
233-
// 3. syncStatus = 'IN_PROGRESS'/`SYNC_NEEDED`/`FAILED_PERMANENTLY` - not persisted on server, delete only locally
233+
// 3. syncStatus = 'IN_PROGRESS'/`FAILED_PERMANENTLY` - not persisted on server, delete only locally
234234
if (isError() || isEphemeral() ||
235235
syncStatus == SyncStatus.IN_PROGRESS ||
236-
syncStatus == SyncStatus.SYNC_NEEDED ||
237236
syncStatus == SyncStatus.FAILED_PERMANENTLY
238237
) {
239238
val error = Error.GenericError("Message is local-only, don't call DeleteMessage API")

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/utils/message/MessageUtilsTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,40 +629,40 @@ internal class MessageUtilsTest {
629629
}
630630

631631
@Test
632-
fun `shouldDeleteRemote should return Failure for SYNC_NEEDED sync status`() {
632+
fun `shouldDeleteRemote should return Failure for FAILED_PERMANENTLY sync status`() {
633633
val message = randomMessage(
634634
type = MessageType.REGULAR,
635-
syncStatus = SyncStatus.SYNC_NEEDED,
635+
syncStatus = SyncStatus.FAILED_PERMANENTLY,
636636
)
637637
val result = message.shouldDeleteRemote(randomString())
638638
assertTrue(result is Result.Failure)
639639
}
640640

641641
@Test
642-
fun `shouldDeleteRemote should return Failure for FAILED_PERMANENTLY sync status`() {
642+
fun `shouldDeleteRemote should return Success for COMPLETED regular message`() {
643643
val message = randomMessage(
644644
type = MessageType.REGULAR,
645-
syncStatus = SyncStatus.FAILED_PERMANENTLY,
645+
syncStatus = SyncStatus.COMPLETED,
646646
)
647647
val result = message.shouldDeleteRemote(randomString())
648-
assertTrue(result is Result.Failure)
648+
assertTrue(result is Result.Success)
649649
}
650650

651651
@Test
652-
fun `shouldDeleteRemote should return Success for COMPLETED regular message`() {
652+
fun `shouldDeleteRemote should return Success for AWAITING_ATTACHMENTS regular message`() {
653653
val message = randomMessage(
654654
type = MessageType.REGULAR,
655-
syncStatus = SyncStatus.COMPLETED,
655+
syncStatus = SyncStatus.AWAITING_ATTACHMENTS,
656656
)
657657
val result = message.shouldDeleteRemote(randomString())
658658
assertTrue(result is Result.Success)
659659
}
660660

661661
@Test
662-
fun `shouldDeleteRemote should return Success for AWAITING_ATTACHMENTS regular message`() {
662+
fun `shouldDeleteRemote should return Success for SYNC_NEEDED sync status`() {
663663
val message = randomMessage(
664664
type = MessageType.REGULAR,
665-
syncStatus = SyncStatus.AWAITING_ATTACHMENTS,
665+
syncStatus = SyncStatus.SYNC_NEEDED,
666666
)
667667
val result = message.shouldDeleteRemote(randomString())
668668
assertTrue(result is Result.Success)

stream-chat-android-offline/src/test/java/io/getstream/chat/android/offline/plugin/listener/internal/DeleteMessageListenerDatabaseTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ internal class DeleteMessageListenerDatabaseTest {
209209
}
210210

211211
@Test
212-
fun `onMessageDeletePrecondition when message has SYNC_NEEDED should return Failure and delete from repo`() =
212+
fun `onMessageDeletePrecondition when message has SYNC_NEEDED should return Success`() =
213213
runTest {
214214
val currentUser = randomUser()
215215
val testMessage = randomMessage(
@@ -224,8 +224,7 @@ internal class DeleteMessageListenerDatabaseTest {
224224

225225
val result = deleteMessageListenerState.onMessageDeletePrecondition(testMessage.id)
226226

227-
assertTrue(result is Result.Failure)
228-
verify(messageRepository).deleteChannelMessage(argThat { id == testMessage.id })
227+
assertTrue(result is Result.Success)
229228
}
230229

231230
@Test

stream-chat-android-state/src/test/java/io/getstream/chat/android/state/plugin/listener/internal/DeleteMessageListenerStateTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ internal class DeleteMessageListenerStateTest {
252252
}
253253

254254
@Test
255-
fun `onMessageDeletePrecondition when message has SYNC_NEEDED should return Failure and delete locally`() =
255+
fun `onMessageDeletePrecondition when message has SYNC_NEEDED should return Success`() =
256256
runTest {
257257
val testMessage = randomMessage(
258258
id = "msg-1",
@@ -262,15 +262,11 @@ internal class DeleteMessageListenerStateTest {
262262
)
263263

264264
whenever(logicRegistry.channelFromMessageId(any())) doReturn channelLogic
265-
whenever(logicRegistry.channelFromMessage(any())) doReturn channelLogic
266-
whenever(logicRegistry.getActiveQueryThreadsLogic()) doReturn activeThreadsLogic
267-
whenever(logicRegistry.threadFromMessage(any())) doReturn null
268265
whenever(channelLogic.getMessage(any())) doReturn testMessage
269266

270267
val result = deleteMessageListenerState.onMessageDeletePrecondition(testMessage.id)
271268

272-
assertTrue(result is Result.Failure)
273-
verify(channelLogic).deleteMessage(argThat { id == testMessage.id })
269+
assertTrue(result is Result.Success)
274270
}
275271

276272
@Test

0 commit comments

Comments
 (0)