Skip to content

Commit a4a3a0d

Browse files
committed
Tests fixed
1 parent 0a9a748 commit a4a3a0d

File tree

17 files changed

+140
-100
lines changed

17 files changed

+140
-100
lines changed

api/pubnub-chat.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public final class com/pubnub/chat/MediatorsKt {
66
public static final fun streamUpdatesOn (Lcom/pubnub/chat/Channel$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
77
public static final fun streamUpdatesOn (Lcom/pubnub/chat/Membership$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
88
public static final fun streamUpdatesOn (Lcom/pubnub/chat/Message$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
9-
public static final fun streamUpdatesOn (Lcom/pubnub/chat/ThreadChannel$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
109
public static final fun streamUpdatesOn (Lcom/pubnub/chat/ThreadMessage$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
1110
public static final fun streamUpdatesOn (Lcom/pubnub/chat/User$Companion;Ljava/util/Collection;Lkotlin/jvm/functions/Function1;)Ljava/lang/AutoCloseable;
1211
}

pubnub-chat-api/api/pubnub-chat-api.api

Lines changed: 94 additions & 62 deletions
Large diffs are not rendered by default.

pubnub-chat-api/src/commonMain/kotlin/com/pubnub/chat/Membership.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ interface Membership {
6060
* @param message Last read message on a given channel with the timestamp that gets added to the user-channel membership as the [lastReadMessageTimetoken] property.
6161
* @return A [PNFuture] that returns an updated [Membership] object.
6262
*/
63-
fun setLastReadMessage(message: BaseMessage<*,*>): PNFuture<Membership>
63+
fun setLastReadMessage(message: BaseMessage<*, *>): PNFuture<Membership>
6464

6565
/**
6666
* Updates the channel membership information for a given user.

pubnub-chat-api/src/commonMain/kotlin/com/pubnub/chat/MessageDraft.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface MessageDraft {
3939
/**
4040
* Can be used to set a [Message] to quote when sending this [MessageDraft].
4141
*/
42-
var quotedMessage: BaseMessage<*,*>?
42+
var quotedMessage: BaseMessage<*, *>?
4343

4444
/**
4545
* Can be used to attach files to send with this [MessageDraft].

pubnub-chat-api/src/commonMain/kotlin/com/pubnub/chat/User.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ interface User {
179179
* @return [PNFuture] indicating the result of setting the restriction.
180180
*/
181181
fun setRestrictions(
182-
channel: BaseChannel<*,*>,
182+
channel: BaseChannel<*, *>,
183183
ban: Boolean = false,
184184
mute: Boolean = false,
185185
reason: String? = null,
@@ -191,7 +191,7 @@ interface User {
191191
* @param channel The [Channel] for which to retrieve the restrictions.
192192
* @return [PNFuture] containing the [Restriction] applied to the user in the specified channel.
193193
*/
194-
fun getChannelRestrictions(channel: BaseChannel<*,*>): PNFuture<Restriction>
194+
fun getChannelRestrictions(channel: BaseChannel<*, *>): PNFuture<Restriction>
195195

196196
/**
197197
* Retrieves all restrictions applied to the user on all channels they are a member of.

pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/ChatImpl.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,13 @@ class ChatImpl(
278278
}
279279
awaitAll(
280280
chat.pubNub.removeMessageAction(message.channelId, message.timetoken, actionTimetoken),
281-
threadChannel.delete(soft)
281+
performDeleteChannel(threadChannel.id, soft).then {
282+
if (it != null) {
283+
threadChannel + it.data
284+
} else {
285+
null
286+
}
287+
}
282288
)
283289
}
284290
}

pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/MembershipImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.pubnub.api.models.consumer.pubsub.objects.PNSetMembershipEventMessage
1010
import com.pubnub.chat.BaseMessage
1111
import com.pubnub.chat.Channel
1212
import com.pubnub.chat.Membership
13-
import com.pubnub.chat.Message
1413
import com.pubnub.chat.User
1514
import com.pubnub.chat.internal.channel.ChannelImpl
1615
import com.pubnub.chat.internal.error.PubNubErrorMessage.CAN_NOT_STREAM_MEMBERSHIP_UPDATES_ON_EMPTY_LIST
@@ -44,7 +43,7 @@ data class MembershipImpl(
4443
return custom?.get(METADATA_LAST_READ_MESSAGE_TIMETOKEN).tryLong()
4544
}
4645

47-
override fun setLastReadMessage(message: BaseMessage<*,*>): PNFuture<Membership> {
46+
override fun setLastReadMessage(message: BaseMessage<*, *>): PNFuture<Membership> {
4847
return setLastReadMessageTimetoken(message.timetoken)
4948
}
5049

pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/MessageDraftImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.pubnub.chat.BaseChannel
66
import com.pubnub.chat.BaseMessage
77
import com.pubnub.chat.Channel
88
import com.pubnub.chat.MentionTarget
9-
import com.pubnub.chat.Message
109
import com.pubnub.chat.MessageDraft
1110
import com.pubnub.chat.MessageDraftChangeListener
1211
import com.pubnub.chat.MessageElement
@@ -40,7 +39,7 @@ class MessageDraftImpl(
4039
override val userLimit: Int = 10,
4140
override val channelLimit: Int = 10
4241
) : MessageDraft {
43-
override var quotedMessage: BaseMessage<*,*>? = null
42+
override var quotedMessage: BaseMessage<*, *>? = null
4443
set(value) {
4544
if (value != null && value.channelId != this.channel.id) {
4645
log.pnError(PubNubErrorMessage.CANNOT_QUOTE_MESSAGE_FROM_OTHER_CHANNELS)

pubnub-chat-impl/src/commonMain/kotlin/com/pubnub/chat/internal/UserImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import com.pubnub.api.utils.Instant
1818
import com.pubnub.api.utils.PatchValue
1919
import com.pubnub.api.v2.callbacks.Result
2020
import com.pubnub.chat.BaseChannel
21-
import com.pubnub.chat.Channel
2221
import com.pubnub.chat.Membership
2322
import com.pubnub.chat.User
2423
import com.pubnub.chat.internal.error.PubNubErrorMessage
@@ -141,7 +140,7 @@ data class UserImpl(
141140
}
142141
}
143142

144-
override fun setRestrictions(channel: BaseChannel<*,*>, ban: Boolean, mute: Boolean, reason: String?): PNFuture<Unit> {
143+
override fun setRestrictions(channel: BaseChannel<*, *>, ban: Boolean, mute: Boolean, reason: String?): PNFuture<Unit> {
145144
if (chat.pubNub.configuration.secretKey.isEmpty()) {
146145
return log.logErrorAndReturnException(MODERATION_CAN_BE_SET_ONLY_BY_CLIENT_HAVING_SECRET_KEY).asFuture()
147146
}
@@ -156,7 +155,7 @@ data class UserImpl(
156155
)
157156
}
158157

159-
override fun getChannelRestrictions(channel: BaseChannel<*,*>): PNFuture<Restriction> {
158+
override fun getChannelRestrictions(channel: BaseChannel<*, *>): PNFuture<Restriction> {
160159
return getRestrictions(channel).then { pnChannelMembershipArrayResult ->
161160
val firstMembership: PNChannelMembership = pnChannelMembershipArrayResult.data.first()
162161
RestrictionImpl.fromChannelMembershipDTO(id, firstMembership)
@@ -204,7 +203,7 @@ data class UserImpl(
204203
}
205204

206205
internal fun getRestrictions(
207-
channel: BaseChannel<*,*>?,
206+
channel: BaseChannel<*, *>?,
208207
limit: Int? = null,
209208
page: PNPage? = null,
210209
sort: Collection<PNSortKey<PNMembershipKey>> = listOf(),

pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/ChannelTest.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ class ChannelTest : BaseTest() {
126126

127127
@Test
128128
fun canUpdateChannel() {
129-
every { chat.updateChannel(any(), any(), any(), any(), any(), any()) } returns objectUnderTest.asFuture()
129+
every { chat.setChannelMetadata(any(), any(), any(), any(), any(), any()) } returns PNChannelMetadataResult(
130+
200,
131+
PNChannelMetadata("a")
132+
).asFuture()
130133

131134
objectUnderTest.update(
132135
name = name,
@@ -136,19 +139,18 @@ class ChannelTest : BaseTest() {
136139
type = type,
137140
).async {}
138141

139-
verify { chat.updateChannel(channelId, name, custom, description, status, type) }
142+
verify { chat.setChannelMetadata(channelId, name, description, custom, type, status) }
140143
}
141144

142145
@Test
143146
fun canSoftDeleteChannel() {
144147
val softDelete = true
145-
val channelFutureMock: PNFuture<Channel> = mock(MockMode.strict)
146-
every { chat.deleteChannel(any(), any()) } returns channelFutureMock
148+
val channelFutureMock: PNFuture<PNChannelMetadataResult?> = mock(MockMode.strict)
149+
every { chat.performDeleteChannel(any(), any()) } returns channelFutureMock
147150

148-
val deleteChannelFuture: PNFuture<Channel?> = objectUnderTest.delete(soft = softDelete)
151+
objectUnderTest.delete(soft = softDelete)
149152

150-
assertEquals(channelFutureMock, deleteChannelFuture)
151-
verify { chat.deleteChannel(id = channelId, soft = softDelete) }
153+
verify { chat.performDeleteChannel(id = channelId, soft = softDelete) }
152154
}
153155

154156
@Test
@@ -961,11 +963,11 @@ class ChannelTest : BaseTest() {
961963

962964
@Test
963965
fun update_calls_chat() {
964-
every { chat.updateChannel(any(), any(), any(), any(), any(), any()) } returns mock()
966+
every { chat.setChannelMetadata(any(), any(), any(), any(), any(), any()) } returns mock()
965967

966968
objectUnderTest.update(name, custom, description, status, type)
967969

968-
verify { chat.updateChannel(channelId, name, custom, description, status, type) }
970+
verify { chat.setChannelMetadata(channelId, name, description, custom, type, status) }
969971
}
970972

971973
@Test

pubnub-chat-impl/src/jsMain/kotlin/BaseChannelJs.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.pubnub.chat.Channel
55
import com.pubnub.chat.MessageDraft
66
import com.pubnub.chat.ThreadChannel
77
import com.pubnub.chat.internal.MessageDraftImpl
8-
import com.pubnub.chat.internal.channel.BaseChannelImpl
98
import com.pubnub.chat.types.ChannelType
109
import com.pubnub.chat.types.InputFile
1110
import com.pubnub.kmp.JsMap
@@ -21,7 +20,7 @@ import kotlin.js.json
2120

2221
@JsExport
2322
@JsName("BaseChannel")
24-
open class BaseChannelJs internal constructor(internal val baseChannel: BaseChannel<*,*>, internal val chatJs: ChatJs) : ChannelFields {
23+
open class BaseChannelJs internal constructor(internal val baseChannel: BaseChannel<*, *>, internal val chatJs: ChatJs) : ChannelFields {
2524
override val id: String by baseChannel::id
2625
override val name: String? by baseChannel::name
2726
override val custom: Any? get() = baseChannel.custom?.toJsMap()
@@ -273,7 +272,7 @@ open class BaseChannelJs internal constructor(internal val baseChannel: BaseChan
273272
}
274273
}
275274

276-
internal fun BaseChannel<*,*>.asJs(chat: ChatJs): BaseChannelJs = when (this) {
275+
internal fun BaseChannel<*, *>.asJs(chat: ChatJs): BaseChannelJs = when (this) {
277276
is Channel -> ChannelJs(this, chat)
278277
is ThreadChannel -> ThreadChannelJs(this, chat)
279278
else -> error("Unexpected error. $this is not a `Channel` or `ThreadChannel`")

pubnub-chat-impl/src/jsMain/kotlin/BaseMessageJs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import kotlin.js.json
1919

2020
@JsExport
2121
@JsName("BaseMessage")
22-
open class BaseMessageJs internal constructor(internal val baseMessage: BaseMessage<*,*>, internal val chatJs: ChatJs) {
22+
open class BaseMessageJs internal constructor(internal val baseMessage: BaseMessage<*, *>, internal val chatJs: ChatJs) {
2323
val timetoken: String get() = baseMessage.timetoken.toString()
2424
val content: JsMap<Any?>
2525
get() {
@@ -147,7 +147,7 @@ open class BaseMessageJs internal constructor(internal val baseMessage: BaseMess
147147
}
148148
}
149149

150-
internal fun BaseMessage<*,*>.asJs(chat: ChatJs) = when (this) {
150+
internal fun BaseMessage<*, *>.asJs(chat: ChatJs) = when (this) {
151151
is Message -> MessageJs(this, chat)
152152
is ThreadMessage -> ThreadMessageJs(this, chat)
153153
else -> error("Unexpected error. $this is not a `Message` or `ThreadMessage`")

pubnub-chat-impl/src/jsMain/kotlin/ChannelJs.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import com.pubnub.kmp.then
1010
import com.pubnub.kmp.toJsMap
1111
import kotlin.js.Promise
1212

13-
1413
@JsExport
1514
@JsName("Channel")
1615
class ChannelJs internal constructor(private val channel: Channel, chatJs: ChatJs) : BaseChannelJs(channel, chatJs) {
@@ -71,13 +70,15 @@ class ChannelJs internal constructor(private val channel: Channel, chatJs: ChatJ
7170
@JsStatic
7271
fun streamUpdatesOn(channels: Array<ChannelJs>, callback: (Array<ChannelJs>) -> Unit): () -> Unit {
7372
val chatJs = channels.first().chatJs
74-
val closeable = BaseChannelImpl.streamUpdatesOn(channels.map { jsChannel -> jsChannel.channel },
75-
ChannelImpl::fromDTO) {
73+
val closeable = BaseChannelImpl.streamUpdatesOn(
74+
channels.map { jsChannel -> jsChannel.channel },
75+
ChannelImpl::fromDTO
76+
) {
7677
callback(it.map { kmpChannel -> ChannelJs(kmpChannel, chatJs) }.toTypedArray())
7778
}
7879
return closeable::close
7980
}
8081
}
8182
}
8283

83-
internal fun Channel.asJs(chat: ChatJs) = ChannelJs(this, chat)
84+
internal fun Channel.asJs(chat: ChatJs) = ChannelJs(this, chat)

pubnub-chat-impl/src/jsMain/kotlin/CryptoUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CryptoUtils {
1414
val decryptedContentJs = params.decryptor(params.message.baseMessage.text)
1515
val decryptedContent: EventContent.TextMessageContent = PNDataEncoder.decode(createJsonElement(decryptedContentJs))
1616

17-
val message = params.message.baseMessage as BaseMessageImpl<*,*>
17+
val message = params.message.baseMessage as BaseMessageImpl<*, *>
1818
val newMessage = message.copyWithContent(decryptedContent)
1919
return (newMessage as? ThreadMessage)?.asJs(params.chat) ?: newMessage.asJs(params.chat)
2020
}

pubnub-chat-impl/src/jsMain/kotlin/MessageJs.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import com.pubnub.chat.Message
44
import com.pubnub.chat.internal.message.BaseMessageImpl
5-
import com.pubnub.chat.internal.message.MessageImpl
65
import com.pubnub.kmp.then
76
import kotlin.js.Promise
87

9-
108
@JsExport
119
@JsName("Message")
1210
class MessageJs internal constructor(private val message: Message, chatJs: ChatJs) : BaseMessageJs(message, chatJs) {
@@ -39,4 +37,4 @@ class MessageJs internal constructor(private val message: Message, chatJs: ChatJ
3937
}::close
4038
}
4139
}
42-
}
40+
}

pubnub-chat-impl/src/jsMain/kotlin/ThreadChannelJs.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import kotlin.js.Promise
1414

1515
@JsExport
1616
@JsName("ThreadChannel")
17-
class ThreadChannelJs internal constructor(internal val threadChannel: ThreadChannel, chatJs: ChatJs) : BaseChannelJs(threadChannel, chatJs) {
17+
class ThreadChannelJs internal constructor(
18+
internal val threadChannel: ThreadChannel,
19+
chatJs: ChatJs
20+
) : BaseChannelJs(threadChannel, chatJs) {
1821
val parentChannelId by threadChannel::parentChannelId
1922

2023
override fun pinMessage(message: BaseMessageJs): Promise<BaseChannelJs> {

pubnub-chat-impl/src/jsMain/kotlin/ThreadMessageJs.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import kotlin.js.Promise
77

88
@JsExport
99
@JsName("ThreadMessage")
10-
class ThreadMessageJs internal constructor(internal val threadMessage: ThreadMessage, chatJs: ChatJs) : BaseMessageJs(threadMessage, chatJs) {
10+
class ThreadMessageJs internal constructor(
11+
internal val threadMessage: ThreadMessage,
12+
chatJs: ChatJs
13+
) : BaseMessageJs(threadMessage, chatJs) {
1114
val parentChannelId by threadMessage::parentChannelId
1215

1316
fun pinToParentChannel(): Promise<ChannelJs> {

0 commit comments

Comments
 (0)