Skip to content

Commit

Permalink
Mc/refactor1 (#99)
Browse files Browse the repository at this point in the history
* Added integration tests.
* Small fixes.
* Handles a few ToDo-s
  • Loading branch information
marcin-cebo authored Oct 1, 2024
1 parent 3faca8b commit 96a7682
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ interface Channel {
/**
* Returns historical messages for the [Channel]
*
* @param startTimetoken
* @param endTimetoken
* @param startTimetoken Timetoken delimiting the start of a time slice (exclusive) to pull messages from.
* @param endTimetoken Timetoken delimiting the end of a time slice (inclusive) to pull messages from
* @param count The maximum number of messages to retrieve. Default and maximum values is 25.
*
* @return [PNFuture] containing a list of messages with pagination information (isMore: Boolean). The result of
Expand Down Expand Up @@ -443,7 +443,7 @@ interface Channel {
*
* @param callback Function that takes a single Channel object. It defines the custom behavior to be executed when detecting channel changes.
*
* @return AutoCloseable interface that lets you stop receiving channel-related updates (objects events)
* @return [AutoCloseable] interface that lets you stop receiving channel-related updates (objects events)
* and clean up resources by invoking the close() method.
*/
fun streamUpdates(callback: (channel: Channel?) -> Unit): AutoCloseable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ interface Chat {
* Lets you watch a selected channel for any new custom events emitted by your chat app.
*
* @param channelId Channel to listen for new events.
* @param customMethod An optional custom method for emitting events. If not provided, defaults to null.
* @param customMethod An optional custom method for emitting events. If not provided, defaults to EmitEventMethod.PUBLISH.
* @param callback A function that is called with an Event<T> as its parameter.
* It defines the custom behavior to be executed whenever an event is detected on the specified channel.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface Membership {
* Updates the channel membership information for a given user.
*
* @param custom Any custom properties or metadata associated with the channel-user membership in a `Map`. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
* @return A [PNFuture] that returns an updated [Membership] object.
*/
fun update(custom: CustomObject): PNFuture<Membership>

Expand All @@ -74,8 +75,6 @@ interface Membership {
*/
fun getUnreadMessagesCount(): PNFuture<Long?>

// todo do we have test for this?

/**
* You can receive updates when specific user-channel Membership object(s) are added, edited, or removed.
*
Expand Down
16 changes: 8 additions & 8 deletions pubnub-chat-api/src/commonMain/kotlin/com/pubnub/chat/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import com.pubnub.chat.types.QuotedMessage
import com.pubnub.chat.types.TextLink
import com.pubnub.kmp.PNFuture

// todo do we have tests for methods in this class?
/**
* Represents an object that refers to a single message in a chat.
*/
interface Message {
/**
* Reference to the main Chat object.
Expand Down Expand Up @@ -108,7 +110,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
fun hasUserReaction(reaction: String): Boolean // todo add test

/**
* Changes the content of the existing message to a new one.
Expand Down Expand Up @@ -142,14 +144,14 @@ interface Message {
* @param channelId Unique identifier of the channel to which you want to forward the message. You can forward a message to the same channel on which it was published or to any other.
* @return [PNFuture] containing [PNPublishResult] that holds the timetoken of the forwarded message.
*/
fun forward(channelId: String): PNFuture<PNPublishResult>
fun forward(channelId: String): PNFuture<PNPublishResult> // todo add test

/**
* Attach this message to its channel.
*
* @return `PNFuture` containing the updated channel metadata
*/
fun pin(): PNFuture<Channel>
fun pin(): PNFuture<Channel> // todo add test

// todo do we have test for this?

Expand All @@ -175,7 +177,7 @@ interface 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>>
fun removeThread(): PNFuture<Pair<PNRemoveMessageActionResult, Channel>> // todo add test

/**
* Add or remove a reaction to a message.
Expand All @@ -189,15 +191,13 @@ interface Message {
*/
fun toggleReaction(reaction: String): PNFuture<Message>

// todo do we want to have test for this?

/**
* You can receive updates when this message and related message reactions are added, edited, or removed.
*
* @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
fun <T : Message> streamUpdates(callback: (message: T) -> Unit): AutoCloseable // todo add test

/**
* 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 @@ -3,8 +3,6 @@ package com.pubnub.chat
import com.pubnub.chat.types.HistoryResponse
import com.pubnub.kmp.PNFuture

// todo add unit and integTests

/**
* Represents an object that refers to a single thread (channel) in a chat.
*/
Expand Down Expand Up @@ -34,7 +32,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing [ThreadChannel]
*/
override fun unpinMessage(): PNFuture<ThreadChannel>
override fun unpinMessage(): PNFuture<ThreadChannel> // todo add test

/**
* Returns historical messages for the [ThreadChannel]
Expand All @@ -58,7 +56,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing the updated [Channel] with the pinned message metadata.
*/
fun pinMessageToParentChannel(message: ThreadMessage): PNFuture<Channel>
fun pinMessageToParentChannel(message: ThreadMessage): PNFuture<Channel> // todo add test

/**
* Unpins the currently pinned message from the parent channel. This updates the parent channel's metadata by removing
Expand All @@ -68,7 +66,7 @@ interface ThreadChannel : Channel {
*
* @return [PNFuture] containing the updated [Channel] after the message is unpinned.
*/
fun unpinMessageFromParentChannel(): PNFuture<Channel>
fun unpinMessageFromParentChannel(): PNFuture<Channel> // todo add test

companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class ChatImpl(
init {
KmLogging.setLogLevel(mapLogLevelFromConfigToKmLogging())

// todo move this to config initialization or setters?
if (config.storeUserActivityInterval < 60.seconds) {
log.pnError(STORE_USER_ACTIVITY_INTERVAL_SHOULD_BE_AT_LEAST_1_MIN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ abstract class BaseChannel<C : Channel, M : Message>(
).then { setMembershipsResult ->
MembershipImpl.fromMembershipDTO(chat, setMembershipsResult.data.first(), user)
}.thenAsync { membership ->
chat.pubNub.time().thenAsync { time -> // todo time API maybe removed from SDK soon
chat.pubNub.time().thenAsync { time ->
membership.setLastReadMessageTimetoken(time.timetoken)
}
}.alsoAsync {
Expand Down Expand Up @@ -459,7 +459,7 @@ abstract class BaseChannel<C : Channel, M : Message>(
this.id,
custom
)
), // todo should null overwrite? wait for optionals?
), // todo should null overwrite? Waiting for optionals?
includeChannelDetails = PNChannelDetailsLevel.CHANNEL_WITH_CUSTOM,
includeCustom = true,
includeCount = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,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
20 changes: 20 additions & 0 deletions src/commonMain/kotlin/com/pubnub/chat/mediators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,31 @@ fun ThreadMessage.Companion.streamUpdatesOn(
callback: (messages: Collection<ThreadMessage>) -> Unit,
): AutoCloseable = BaseMessage.streamUpdatesOn(messages, callback)

/**
* Receives updates on list of [Channel] object.
*
* @param channels Collection of channels to get updates.
* @param callback Function that takes a single Channel object. It defines the custom behavior to be executed when
* detecting channel changes.
*
* @return [AutoCloseable] interface that lets you stop receiving channel-related updates (objects events)
* and clean up resources by invoking the close() method.
*/
fun Channel.Companion.streamUpdatesOn(
channels: Collection<Channel>,
callback: (channels: Collection<Channel>) -> Unit,
): AutoCloseable = BaseChannel.streamUpdatesOn(channels, callback)

/**
* Receives updates on list of [Channel] object.
*
* @param channels Collection of channels to get updates.
* @param callback Function that takes a single Channel object. It defines the custom behavior to be executed when
* detecting channel changes.
*
* @return [AutoCloseable] interface that lets you stop receiving channel-related updates (objects events)
* and clean up resources by invoking the close() method.
*/
fun ThreadChannel.Companion.streamUpdatesOn(
channels: Collection<Channel>,
callback: (channels: Collection<Channel>) -> Unit,
Expand Down

0 comments on commit 96a7682

Please sign in to comment.