diff --git a/gradle.properties b/gradle.properties index 411e2e09..ef19d491 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ SONATYPE_HOST=DEFAULT SONATYPE_AUTOMATIC_RELEASE=false GROUP=com.pubnub POM_PACKAGING=jar -VERSION_NAME=0.11.4 +VERSION_NAME=0.11.5 POM_NAME=PubNub Chat SDK POM_DESCRIPTION=This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application. diff --git a/js-chat/.pubnub.yml b/js-chat/.pubnub.yml index 78f208a8..6f9d4738 100644 --- a/js-chat/.pubnub.yml +++ b/js-chat/.pubnub.yml @@ -1,10 +1,15 @@ name: pubnub-js-chat -version: 0.11.4 +version: 0.11.5 scm: github.com/pubnub/js-chat schema: 1 files: - lib/dist/index.js changelog: + - date: 2025-02-06 + version: 0.11.5 + changes: + - type: bug + text: "Fixed method sendEvent for event types different from custom ." - date: 2025-02-04 version: 0.11.4 changes: diff --git a/js-chat/package.json b/js-chat/package.json index bfab2117..74642ab2 100644 --- a/js-chat/package.json +++ b/js-chat/package.json @@ -40,7 +40,7 @@ "module": "dist/index.es.js", "types": "dist/index.d.ts", "react-native": "dist/index.es.js", - "version": "0.11.4", + "version": "0.11.5", "name": "@pubnub/chat", "dependencies": { "pubnub": "8.6.0", diff --git a/js-chat/tests/channel.test.ts b/js-chat/tests/channel.test.ts index 1e5393ae..10fcf5fd 100644 --- a/js-chat/tests/channel.test.ts +++ b/js-chat/tests/channel.test.ts @@ -1276,36 +1276,96 @@ describe("Channel test", () => { expect(result.channels.length).toBe(2) }) + test("send report event", async () => { + let receivedEvent + const reason = "rude" + const text = "reporting" + const unsubscribe = chat.listenForEvents({ + channel: channel.id, + type: "report", + callback: (event) => { + receivedEvent = event + }, + }) + + await sleep(1000) + await chat.emitEvent({ + channel: channel.id, + type: 'report', + payload: { + text: text, + reason: reason + } + }) + await sleep(500) + expect(receivedEvent.payload.text).toEqual(text) + expect(receivedEvent.payload.reason).toEqual(reason) + + unsubscribe(); // Cleanup + }) + + test("send receipt event", async () => { + let receivedEvent + const messageTimetokenValue = "123" + const eventTypeReceipt = "receipt" + + const unsubscribe = chat.listenForEvents({ + type: eventTypeReceipt, + channel: channel.id, + callback: event => { + receivedEvent = event + } + }) + + await sleep(1000) + await chat.emitEvent({ + type: eventTypeReceipt, + channel: channel.id, + payload: { + messageTimetoken: messageTimetokenValue + } + + }) + + await sleep(500) + expect(receivedEvent.payload.messageTimetoken).toEqual(messageTimetokenValue) + expect(receivedEvent.type).toEqual(eventTypeReceipt) + + unsubscribe() // cleanup + }) + test("send custom event", async () => { - const inviteCallback = jest.fn() - const unsubscribe = chat.listenForEvents({ - channel: channel.id, - type: "custom", - method: "publish", - callback: inviteCallback, - }) - - await sleep(1000) - await chat.emitEvent({ - channel: channel.id, - type: 'custom', - method: 'publish', - payload: { - action: "action", - body: "payload" - } - }) - await sleep(2000) - expect(inviteCallback).toHaveBeenCalledTimes(1) - expect(inviteCallback).toHaveBeenCalledWith( + const inviteCallback = jest.fn() + const unsubscribe = chat.listenForEvents({ + channel: channel.id, + type: "custom", + method: "publish", + callback: inviteCallback, + }) + + await sleep(1000) + await chat.emitEvent({ + channel: channel.id, + type: 'custom', + method: 'publish', + payload: { + action: "action", + body: "payload" + } + }) + await sleep(2000) + expect(inviteCallback).toHaveBeenCalledTimes(1) + expect(inviteCallback).toHaveBeenCalledWith( expect.objectContaining({ payload: expect.objectContaining({ action: "action", body: "payload" }), }) - ) - }) + ) + + unsubscribe(); // Cleanup + }) test("use PubNub SDK types from Chat SDK", async () => { let channelMetadata = await chat.sdk.objects.getChannelMetadata({ diff --git a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChatIntegrationTest.kt b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChatIntegrationTest.kt index 5f5d8a91..7b53f3c5 100644 --- a/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChatIntegrationTest.kt +++ b/pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/integration/ChatIntegrationTest.kt @@ -620,6 +620,7 @@ class ChatIntegrationTest : BaseChatIntegrationTest() { } } + delayForHistory() delayForHistory() val eventFromHistory = chat.getEventsHistory(channelId, tt + 1, tt).await().events.first() val payload: EventContent.Custom = eventFromHistory.payload as EventContent.Custom diff --git a/pubnub-chat-impl/src/jsMain/kotlin/ChatJs.kt b/pubnub-chat-impl/src/jsMain/kotlin/ChatJs.kt index 9a5b70d6..74787b19 100644 --- a/pubnub-chat-impl/src/jsMain/kotlin/ChatJs.kt +++ b/pubnub-chat-impl/src/jsMain/kotlin/ChatJs.kt @@ -47,7 +47,7 @@ class ChatJs internal constructor(val chat: ChatInternal, val config: ChatConfig EventContent.Custom((payload as JsMap).toMap(), method) } else { payload.type = type - PNDataEncoder.decode(createJsonElement(payload)) + PNDataEncoder.decode(createJsonElement(payload)) } return chat.emitEvent( channel,