diff --git a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/message/BaseMessage.kt b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/message/BaseMessage.kt index 91465137..8f687788 100644 --- a/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/message/BaseMessage.kt +++ b/pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/message/BaseMessage.kt @@ -129,6 +129,7 @@ abstract class BaseMessage( override fun delete(soft: Boolean, preserveFiles: Boolean): PNFuture { val type = chat.deleteMessageActionName if (soft) { + var updatedActions: Map>> = mapOf() return chat.pubNub.addMessageAction( channelId, PNMessageAction( @@ -136,11 +137,19 @@ abstract class BaseMessage( type, timetoken ) - ).then { it: PNAddMessageActionResult -> - val actions = assignAction(actions, it) - copyWithActions(actions) - }.alsoAsync { + ).thenAsync { deleteThread(soft) + }.thenAsync { + chat.pubNub.getMessageActions(channel = channelId, page = PNBoundedPage(end = timetoken)) + }.then { pnGetMessageActionsResult: PNGetMessageActionsResult -> + val messageActionsForMessage: List = + pnGetMessageActionsResult.actions.filter { it.messageTimetoken == timetoken } + // update actions map + messageActionsForMessage.forEach { pnMessageAction -> + updatedActions = assignAction(updatedActions, pnMessageAction) + } + }.then { + copyWithActions(updatedActions) } } else { val previousTimetoken = timetoken - 1 @@ -267,7 +276,6 @@ abstract class BaseMessage( } private fun deleteThread(soft: Boolean): PNFuture { - // todo check on server, discuss with Team if (hasThread) { return getThread().thenAsync { it.delete(soft) diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MessageIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MessageIntegrationTest.kt index 5ff0dfec..862e4f8e 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MessageIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/MessageIntegrationTest.kt @@ -35,12 +35,9 @@ class MessageIntegrationTest : BaseChatIntegrationTest() { val messageWithThread = channel01.getMessage(publishTimetoken).await() val messageWithReaction = messageWithThread!!.toggleReaction(reactionValue).await() val deletedMessage: Message = messageWithReaction.delete(soft = true).await()!! - // todo returned message provide invalid state because in actions map there is THREAD_ROOT_ID. - // To workaround this we need to call channel01.getMessage(publishTimetoken) to get message in proper state. - val messageAfterDeletedMessage: Message = channel01.getMessage(publishTimetoken).await()!! - val restoredMessage: Message = messageAfterDeletedMessage.restore().await() -// val messageAfterRestore: Message = channel01.getMessage(publishTimetoken).await()!! + delayInMillis(500) + val restoredMessage: Message = deletedMessage.restore().await() assertEquals(messageText, restoredMessage.text) assertEquals(reactionValue, restoredMessage.actions!!["reactions"]?.keys?.first())