Skip to content

Commit

Permalink
Implemented toDos (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo authored Nov 11, 2024
1 parent e72bda0 commit 65f4c4e
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pubnub-chat-api/pubnub_chat_api.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'pubnub_chat_api'
spec.version = '0.8.1-DEV'
spec.version = '0.9.0'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ interface Channel {
*
* @return [PNFuture] containing [GetFilesResult]
*/
fun getFiles(limit: Int = 100, next: String? = null): PNFuture<GetFilesResult> // todo add tests for this
fun getFiles(limit: Int = 100, next: String? = null): PNFuture<GetFilesResult>

/**
* Delete sent files or files from published messages.
Expand All @@ -477,7 +477,7 @@ interface Channel {
*
* @return [PNFuture] containing [PNDeleteFileResult]
*/
fun deleteFile(id: String, name: String): PNFuture<PNDeleteFileResult> // todo add tests for this
fun deleteFile(id: String, name: String): PNFuture<PNDeleteFileResult>

/**
* Enables real-time tracking of users connecting to or disconnecting from a [Channel].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface Message {
* @param reaction Specific emoji added to the message.
* @return Specifies if the current user added a given emoji to the message or not.
*/
fun hasUserReaction(reaction: String): Boolean // todo add test
fun hasUserReaction(reaction: String): Boolean

/**
* Changes the content of the existing message to a new one.
Expand Down Expand Up @@ -171,14 +171,12 @@ interface Message {
*/
fun createThread(): PNFuture<ThreadChannel>

// todo do we have test for this?

/**
* Removes a thread (channel) for a selected message.
*
* @return A pair of values containing an object with details about the result of the remove message action (indicating whether the message was successfully removed and potentially including additional metadata or information about the removal) and the updated channel object after the removal of the thread.
*/
fun removeThread(): PNFuture<Pair<PNRemoveMessageActionResult, Channel?>> // todo add test
fun removeThread(): PNFuture<Pair<PNRemoveMessageActionResult, Channel?>>

/**
* Add or remove a reaction to a message.
Expand All @@ -198,7 +196,7 @@ interface Message {
* @param callback Function that takes a single Message object. It defines the custom behavior to be executed when detecting message or message reaction changes.
* @return Interface that lets you stop receiving message-related updates by invoking the close() method
*/
fun <T : Message> streamUpdates(callback: (message: T) -> Unit): AutoCloseable // todo add test
fun <T : Message> streamUpdates(callback: (message: T) -> Unit): AutoCloseable

/**
* If you delete a message, you can restore its content together with the attached files using the restore() method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ class CustomPayloads(
*
*/
val deleteMessageActionName: String? = null,
/**
* A type of action you want to be added to your Message object whenever a reaction is added to a published message, like "reacted".
*
* The default message action used by Chat SDK is "reactions".
*/
val reactionsActionName: String? = null
)
2 changes: 1 addition & 1 deletion pubnub-chat-impl/pubnub_chat_impl.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'pubnub_chat_impl'
spec.version = '0.8.1-DEV'
spec.version = '0.9.0'
spec.homepage = 'Link to a Kotlin/Native module homepage'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,18 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() {
val completableStatus = CompletableDeferred<String?>()

pubnub.test(backgroundScope, checkAllEvents = false) {
var dispose: AutoCloseable? = null
pubnub.awaitSubscribe(listOf(channel01.id)) {
channel01.streamUpdates { channel: Channel? ->
dispose = channel01.streamUpdates { channel: Channel? ->
completableDescription.complete(channel?.description)
completableStatus.complete(channel?.status)
}
}
channel01.update(description = expectedDescription, status = expectedStatus).await()
assertEquals(expectedDescription, completableDescription.await())
assertEquals(expectedStatus, completableStatus.await())

dispose?.close()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class MessageIntegrationTest : BaseChatIntegrationTest() {
Expand Down Expand Up @@ -68,6 +69,31 @@ class MessageIntegrationTest : BaseChatIntegrationTest() {
assertEquals(2, restoredMessage.actions!!.size)
}

@Test
fun createMessageWithThreadThenDeleteThread() = runTest {
// create message with thread
val messageText = "messageText_${randomString()}"
val pnPublishResult = channel01.sendText(text = messageText).await()
val publishTimetoken = pnPublishResult.timetoken
val message: Message = channel01.getMessage(publishTimetoken).await()!!
val threadChannel: ThreadChannel = message.createThread().await()
// we need to call sendText because addMessageAction is called in sendText that stores details about thread
threadChannel.sendText("message in thread_${randomString()}").await()

delayInMillis(1500)
// we need to call getMessage to get message with indication that it hasThread
val messageWithThread: Message = channel01.getMessage(publishTimetoken).await()!!

assertTrue(messageWithThread.hasThread)

messageWithThread.removeThread().await()

// we need to call getMessage to get message with indication that it has no Thread
val messageWithNoThread: Message = channel01.getMessage(publishTimetoken).await()!!

assertFalse(messageWithNoThread.hasThread)
}

@Test
fun streamUpdatesOn() = runTest {
chat.createChannel(
Expand Down Expand Up @@ -142,6 +168,24 @@ class MessageIntegrationTest : BaseChatIntegrationTest() {
)
}

@Test
fun addReactionToMessageThenCheckIfPresent() = runTest {
val reactionValue = "wow"
val messageText = "messageText_${randomString()}"
val pnPublishResult = channel01.sendText(text = messageText).await()
val publishTimetoken = pnPublishResult.timetoken
val message: Message = channel01.getMessage(publishTimetoken).await()!!

val messageWithReaction = message.toggleReaction(reactionValue).await()

assertTrue(messageWithReaction.hasUserReaction(reactionValue))

delayInMillis(1000)
val messageWithReactionFromHistory: Message = channel01.getHistory(publishTimetoken + 1, publishTimetoken).await().messages.first()

assertTrue(messageWithReactionFromHistory.hasUserReaction(reactionValue))
}

@Test
fun adminCanSubscribeToInternalChannelRelatedToReportsForSpecificChannelAndCanGetReportedMessageEvent() = runTest {
val pnPublishResult = channel01.sendText("message1").await()
Expand All @@ -155,7 +199,6 @@ class MessageIntegrationTest : BaseChatIntegrationTest() {
removeListenerAndUnsubscribe = chat.listenForEvents<EventContent.Report>(
channelId = channelId,
callback = { event: Event<EventContent.Report> ->
println("-= in listenForEvents")
try {
// we need to have try/catch here because assertion error will not cause test to fail
assertEquals(reason, event.payload.reason)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.pubnub.integration

import com.pubnub.chat.types.GetFilesResult
import com.pubnub.chat.types.InputFile
import com.pubnub.test.await
import kotlinx.coroutines.test.runTest
import org.junit.Test
import java.io.ByteArrayInputStream
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class ChannelJvmIntegrationTest : BaseChatIntegrationTest() {
@Test
fun sendFileGetFileDeleteFile() = runTest {
val fileName = "test.txt"
val type = "text/plain"
val data = "dfa"
val source = ByteArrayInputStream(data.toByteArray())
val file = InputFile(name = fileName, type = type, source = source)

// send file
channel01.sendText(text = "messageWithFile", files = listOf(file)).await()

// get file
val filesResult: GetFilesResult = channel01.getFiles().await()

assertEquals(1, filesResult.files.size)
val actualFile = filesResult.files.first()
assertEquals(fileName, actualFile.name)
assertNotNull(actualFile.id)
assertNotNull(actualFile.url)

// delete file
val deleteFileResult = channel01.deleteFile(actualFile.id, actualFile.name).await()
assertEquals(200, deleteFileResult.status)
}
}
2 changes: 1 addition & 1 deletion pubnub_chat.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'pubnub_chat'
spec.version = '0.8.1-DEV'
spec.version = '0.9.0'
spec.homepage = 'Link to a Kotlin/Native module homepage'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 65f4c4e

Please sign in to comment.