Skip to content

Commit

Permalink
Delete message returns message with valid actions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Aug 16, 2024
1 parent f39c315 commit e774b7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,27 @@ abstract class BaseMessage<T : Message>(
override fun delete(soft: Boolean, preserveFiles: Boolean): PNFuture<Message?> {
val type = chat.deleteMessageActionName
if (soft) {
var updatedActions: Map<String, Map<String, List<PNFetchMessageItem.Action>>> = mapOf()
return chat.pubNub.addMessageAction(
channelId,
PNMessageAction(
type,
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<PNMessageAction> =
pnGetMessageActionsResult.actions.filter { it.messageTimetoken == timetoken }
// update actions map
messageActionsForMessage.forEach { pnMessageAction ->
updatedActions = assignAction(updatedActions, pnMessageAction)
}
}.then {
copyWithActions(updatedActions)
}
} else {
val previousTimetoken = timetoken - 1
Expand Down Expand Up @@ -267,7 +276,6 @@ abstract class BaseMessage<T : Message>(
}

private fun deleteThread(soft: Boolean): PNFuture<Unit> {
// todo check on server, discuss with Team
if (hasThread) {
return getThread().thenAsync {
it.delete(soft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e774b7b

Please sign in to comment.