Skip to content

Commit

Permalink
Fix toggleReaction
Browse files Browse the repository at this point in the history
There was a bug where removing a reaction would not remove it from the returned value.

Additionally we were missing a configurable `reactionsActionName` from TS Chat.
  • Loading branch information
wkal-pubnub committed Oct 25, 2024
1 parent 44b6a03 commit 4e73878
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pubnub-chat-api/api/pubnub-chat-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,13 @@ public final class com/pubnub/chat/config/ChatConfigurationKt {

public final class com/pubnub/chat/config/CustomPayloads {
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getDeleteMessageActionName ()Ljava/lang/String;
public final fun getEditMessageActionName ()Ljava/lang/String;
public final fun getGetMessagePublishBody ()Lkotlin/jvm/functions/Function3;
public final fun getGetMessageResponseBody ()Lkotlin/jvm/functions/Function3;
public final fun getReactionsActionName ()Ljava/lang/String;
}

public final class com/pubnub/chat/config/LogLevel : java/lang/Enum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ class CustomPayloads(
*
*/
val deleteMessageActionName: String? = null,
val reactionsActionName: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class ChatImpl(
?: MessageActionType.EDITED.toString(),
override val deleteMessageActionName: String = config.customPayloads?.deleteMessageActionName
?: MessageActionType.DELETED.toString(),
override val reactionsActionName: String = config.customPayloads?.reactionsActionName
?: MessageActionType.REACTIONS.toString(),
override val timerManager: TimerManager = createTimerManager()
) : ChatInternal {
override var currentUser: User =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.pubnub.kmp.PNFuture
interface ChatInternal : Chat {
val editMessageActionName: String
val deleteMessageActionName: String
val reactionsActionName: String
val timerManager: TimerManager

fun createUser(user: User): PNFuture<User>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.pubnub.chat.internal.util.logWarnAndReturnException
import com.pubnub.chat.internal.util.pnError
import com.pubnub.chat.types.EventContent
import com.pubnub.chat.types.File
import com.pubnub.chat.types.MessageActionType
import com.pubnub.chat.types.MessageMentionedUser
import com.pubnub.chat.types.MessageMentionedUsers
import com.pubnub.chat.types.MessageReferencedChannel
Expand Down Expand Up @@ -93,7 +92,7 @@ abstract class BaseMessage<T : Message>(
get() = content.files ?: emptyList()

override val reactions: Map<String, List<PNFetchMessageItem.Action>>
get() = actions?.get(MessageActionType.REACTIONS.toString()) ?: emptyMap()
get() = actions?.get(chat.reactionsActionName) ?: emptyMap()

override val textLinks: List<TextLink>? get() = (
meta?.get(
Expand Down Expand Up @@ -209,7 +208,10 @@ abstract class BaseMessage<T : Message>(
it.uuid == chat.currentUser.id
}
val messageAction =
PNMessageAction(MessageActionType.REACTIONS.toString(), reaction, timetoken)
PNMessageAction(chat.reactionsActionName, reaction, timetoken).apply {
actionTimetoken = existingReaction?.actionTimetoken
uuid = chat.currentUser.id
}
val newActions = if (existingReaction != null) {
chat.pubNub.removeMessageAction(channelId, timetoken, existingReaction.actionTimetoken.toLong())
.then { filterAction(actions, messageAction) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ abstract class FakeChat(override val config: ChatConfiguration, override val pub
TODO("Not yet implemented")
}

override val reactionsActionName: String
get() = TODO("Not yet implemented")

override val currentUser: User
get() = TODO("Not yet implemented")

Expand Down

0 comments on commit 4e73878

Please sign in to comment.