Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Aug 7, 2024
1 parent 9f55d57 commit 383c939
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ interface Channel {
count: Int = 25,
): PNFuture<GetEventsHistoryResult>

fun streamMessageReports(callback: (event: EventContent.Report) -> Unit): AutoCloseable
fun streamMessageReports(callback: (event: Event<EventContent.Report>) -> Unit): AutoCloseable

/**
* Get a new `Channel` instance that is a copy of this `Channel` with its properties updated with information coming from `update`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,9 @@ abstract class BaseChannel<C : Channel, M : Message>(
)
}

override fun streamMessageReports(callback: (event: EventContent.Report) -> Unit): AutoCloseable {
val channelId = "${INTERNAL_MODERATION_PREFIX}${this.id}"
return chat.listenForEvents<EventContent.Report>(channelId = channelId, callback = { event: Event<EventContent.Report> ->
callback(event.payload)
})
override fun streamMessageReports(callback: (event: Event<EventContent.Report>) -> Unit): AutoCloseable {
val channelId = "${INTERNAL_MODERATION_PREFIX}${id}"
return chat.listenForEvents<EventContent.Report>(channelId = channelId, callback = callback)
}

internal fun getRestrictions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() {
val then = Instant.fromEpochSeconds(chat.pubNub.time().await().timetoken / 10000000)
val channel = chat.createChannel(randomString()).await()

val lastReadMessage = channel.join().await().membership.lastReadMessageTimetoken
val lastReadMessage: Long = channel.join().await().membership.lastReadMessageTimetoken ?: 0

assertNotNull(lastReadMessage)
assertTrue(lastReadMessage > 0)
assertContains(then..Clock.System.now(), Instant.fromEpochSeconds(lastReadMessage / 10000000))
}

Expand Down Expand Up @@ -441,14 +441,15 @@ class ChannelIntegrationTest : BaseChatIntegrationTest() {
val message = channel01.getMessage(timetoken).await()!!
val assertionErrorInCallback = CompletableDeferred<AssertionError?>()

val streamMessageReports = channel01.streamMessageReports { reportEvent: EventContent.Report ->
val streamMessageReports = channel01.streamMessageReports { reportEvent: Event<EventContent.Report> ->
try {
// we need to have try/catch here because assertion error will not cause test to fail
numberOfReports.incrementAndGet()
println("-= reason: ${reportEvent.reason}")
assertTrue(reportEvent.reason == reason01 || reportEvent.reason == reason02)
assertEquals(messageText, reportEvent.text)
assertTrue(reportEvent.reportedMessageChannelId?.contains(INTERNAL_MODERATION_PREFIX)!!)
val reportReason = reportEvent.payload.reason
assertTrue(reportReason == reason01 || reportReason == reason02)
assertEquals(messageText, reportEvent.payload.text)
assertTrue(reportEvent.payload.reportedMessageChannelId?.contains(INTERNAL_MODERATION_PREFIX)!!)
assertTrue(reportEvent.channelId.contains(INTERNAL_MODERATION_PREFIX))
if (numberOfReports.value == 2) {
assertionErrorInCallback.complete(null)
}
Expand Down
2 changes: 1 addition & 1 deletion pubnub-kotlin
Submodule pubnub-kotlin updated 0 files

0 comments on commit 383c939

Please sign in to comment.