Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package io.getstream.chat.android.client.api2.mapping
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorClearEventDto
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorStopEventDto
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorUpdatedEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelHiddenEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelVisibleEventDto
import io.getstream.chat.android.client.api2.model.dto.ChatEventDto
import io.getstream.chat.android.client.api2.model.dto.ConnectedEventDto
import io.getstream.chat.android.client.api2.model.dto.ConnectingEventDto
Expand Down Expand Up @@ -111,8 +109,10 @@ import io.getstream.chat.android.network.models.PollResponseData
import io.getstream.chat.android.network.models.PollVoteResponseData
import io.getstream.chat.android.network.models.WSEvent
import io.getstream.chat.android.network.models.ChannelDeletedEvent as GeneratedChannelDeletedEvent
import io.getstream.chat.android.network.models.ChannelHiddenEvent as GeneratedChannelHiddenEvent
import io.getstream.chat.android.network.models.ChannelTruncatedEvent as GeneratedChannelTruncatedEvent
import io.getstream.chat.android.network.models.ChannelUpdatedEvent as GeneratedChannelUpdatedEvent
import io.getstream.chat.android.network.models.ChannelVisibleEvent as GeneratedChannelVisibleEvent
import io.getstream.chat.android.network.models.DraftDeletedEvent as GeneratedDraftDeletedEvent
import io.getstream.chat.android.network.models.DraftUpdatedEvent as GeneratedDraftUpdatedEvent
import io.getstream.chat.android.network.models.MemberAddedEvent as GeneratedMemberAddedEvent
Expand Down Expand Up @@ -174,8 +174,6 @@ internal class EventMapping(
@Suppress("LongMethod")
internal fun ChatEventDto.toDomain(): ChatEvent {
return when (this) {
is ChannelHiddenEventDto -> toDomain()
is ChannelVisibleEventDto -> toDomain()
is ConnectedEventDto -> toDomain()
is ConnectionErrorEventDto -> toDomain()
is ConnectingEventDto -> toDomain()
Expand All @@ -192,35 +190,39 @@ internal class EventMapping(
}

/**
* Transforms [ChannelHiddenEventDto] to [ChannelHiddenEvent].
* Transforms the generated [GeneratedChannelHiddenEvent] to [ChannelHiddenEvent].
*/
private fun ChannelHiddenEventDto.toDomain(): ChannelHiddenEvent = with(domainMapping) {
ChannelHiddenEvent(
private fun GeneratedChannelHiddenEvent.toDomain(): ChannelHiddenEvent = with(domainMapping) {
val cid = requireNotNull(cid)
val (channelType, channelId) = cid.cidToTypeAndId()
return ChannelHiddenEvent(
type = type,
createdAt = created_at.date,
rawCreatedAt = created_at.rawDate,
createdAt = createdAt.date,
rawCreatedAt = createdAt.raw,
cid = cid,
channelType = channel_type,
channelId = channel_id,
user = user.toDomain(),
channelType = channelType,
channelId = channelId,
user = requireNotNull(user).toDomain(),
channel = channel.toDomain(),
clearHistory = clear_history,
clearHistory = clearHistory ?: false,
)
}

/**
* Transforms [ChannelVisibleEventDto] to [ChannelVisibleEvent].
* Transforms the generated [GeneratedChannelVisibleEvent] to [ChannelVisibleEvent].
*/
private fun ChannelVisibleEventDto.toDomain(): ChannelVisibleEvent = with(domainMapping) {
ChannelVisibleEvent(
private fun GeneratedChannelVisibleEvent.toDomain(): ChannelVisibleEvent = with(domainMapping) {
val cid = requireNotNull(cid)
val (channelType, channelId) = cid.cidToTypeAndId()
return ChannelVisibleEvent(
type = type,
createdAt = created_at.date,
rawCreatedAt = created_at.rawDate,
createdAt = createdAt.date,
rawCreatedAt = createdAt.raw,
cid = cid,
channelType = channel_type,
channelId = channel_id,
user = user.toDomain(),
channel = channel?.toDomain() ?: Channel(id = channel_id, type = channel_type),
channelType = channelType,
channelId = channelId,
user = requireNotNull(user).toDomain(),
channel = channel?.toDomain() ?: Channel(id = channelId, type = channelType),
)
}

Expand Down Expand Up @@ -495,6 +497,8 @@ internal class EventMapping(
is GeneratedChannelUpdatedEvent -> toDomain()
is GeneratedChannelTruncatedEvent -> toDomain()
is GeneratedChannelDeletedEvent -> toDomain()
is GeneratedChannelHiddenEvent -> toDomain()
is GeneratedChannelVisibleEvent -> toDomain()
is GeneratedNotificationRemovedFromChannelEvent -> toDomain()
is GeneratedUserUpdatedEvent -> toDomain()
is GeneratedUserMessagesDeletedEvent -> toDomain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,6 @@ import java.util.Date

internal sealed class ChatEventDto

@JsonClass(generateAdapter = true)
internal data class ChannelHiddenEventDto(
val type: String,
val created_at: ExactDate,
val cid: String,
val channel_type: String,
val channel_id: String,
val user: DownstreamUserDto,
val channel: DownstreamChannelDto,
// Events replayed by /sync on backends before v239.47.0 omit it.
val clear_history: Boolean = false,
) : ChatEventDto()

@JsonClass(generateAdapter = true)
internal data class ChannelVisibleEventDto(
val type: String,
val created_at: ExactDate,
val cid: String,
val channel_type: String,
val channel_id: String,
val user: DownstreamUserDto,
// Events replayed by /sync on backends before v239.47.0 omit it.
val channel: DownstreamChannelDto?,
) : ChatEventDto()

@JsonClass(generateAdapter = true)
internal data class HealthEventDto(
val type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import com.squareup.moshi.rawType
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorClearEventDto
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorStopEventDto
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorUpdatedEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelHiddenEventDto
import io.getstream.chat.android.client.api2.model.dto.ChannelVisibleEventDto
import io.getstream.chat.android.client.api2.model.dto.ChatEventDto
import io.getstream.chat.android.client.api2.model.dto.ConnectedEventDto
import io.getstream.chat.android.client.api2.model.dto.ConnectionErrorEventDto
Expand All @@ -39,8 +37,10 @@ import io.getstream.chat.android.client.api2.model.dto.UnknownEventDto
import io.getstream.chat.android.client.api2.model.dto.utils.internal.ExactDate
import io.getstream.chat.android.models.EventType
import io.getstream.chat.android.network.models.ChannelDeletedEvent
import io.getstream.chat.android.network.models.ChannelHiddenEvent
import io.getstream.chat.android.network.models.ChannelTruncatedEvent
import io.getstream.chat.android.network.models.ChannelUpdatedEvent
import io.getstream.chat.android.network.models.ChannelVisibleEvent
import io.getstream.chat.android.network.models.DraftDeletedEvent
import io.getstream.chat.android.network.models.DraftUpdatedEvent
import io.getstream.chat.android.network.models.MemberAddedEvent
Expand Down Expand Up @@ -150,9 +150,11 @@ internal class EventDtoAdapter(
private val memberUpdatedEventAdapter =
generatedEventAdapter<MemberUpdatedEvent> { mapOf("cid" to cid, "user" to user) }
private val channelUpdatedEventAdapter = generatedEventAdapter<ChannelUpdatedEvent> { mapOf("cid" to cid) }
private val channelHiddenEventAdapter = moshi.adapter(ChannelHiddenEventDto::class.java)
private val channelHiddenEventAdapter =
generatedEventAdapter<ChannelHiddenEvent> { mapOf("cid" to cid, "user" to user) }
private val channelDeletedEventAdapter = generatedEventAdapter<ChannelDeletedEvent> { mapOf("cid" to cid) }
private val channelVisibleEventAdapter = moshi.adapter(ChannelVisibleEventDto::class.java)
private val channelVisibleEventAdapter =
generatedEventAdapter<ChannelVisibleEvent> { mapOf("cid" to cid, "user" to user) }
private val channelTruncatedEventAdapter = generatedEventAdapter<ChannelTruncatedEvent> { mapOf("cid" to cid) }
private val userStartWatchingEventAdapter = generatedEventAdapter<UserWatchingStartEvent> { mapOf("cid" to cid) }
private val userStopWatchingEventAdapter = generatedEventAdapter<UserWatchingStopEvent> { mapOf("cid" to cid) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport",
)

package io.getstream.chat.android.network.models

import com.squareup.moshi.Json

/**
* Emitted when a channel is successfully hidden.
*/
@com.squareup.moshi.JsonClass(generateAdapter = true)
internal data class ChannelHiddenEvent(
// Patched: the spec marks `clear_history` required, but backends before v239.47.0 (CHA-3482, chat#17545) replay
// channel.hidden on /sync without it, and a parse failure fails the whole /sync response. On regen, make it
// required again only once every region runs v239.47.0 or later.
@Json(name = "clear_history")
internal val clearHistory: Boolean? = null,

@Json(name = "created_at")
internal val createdAt: io.getstream.chat.android.network.infrastructure.ExactDate,

@Json(name = "channel")
internal val channel: io.getstream.chat.android.network.models.ChannelResponse,

@Json(name = "custom")
internal val custom: Map<String, Any?> = emptyMap(),

@Json(name = "type")
internal val type: String = "channel.hidden",

@Json(name = "channel_id")
internal val channelId: String? = null,

@Json(name = "channel_member_count")
internal val channelMemberCount: Int? = null,

@Json(name = "channel_message_count")
internal val channelMessageCount: Int? = null,

@Json(name = "channel_type")
internal val channelType: String? = null,

@Json(name = "cid")
internal val cid: String? = null,

@Json(name = "received_at")
internal val receivedAt: java.util.Date? = null,

@Json(name = "team")
internal val team: String? = null,

@Json(name = "channel_custom")
internal val channelCustom: Map<String, Any?>? = null,

@Json(name = "user")
internal val user: io.getstream.chat.android.network.models.UserResponseCommonFields? = null,
) :
io.getstream.chat.android.network.models.WSClientEvent, io.getstream.chat.android.network.models.WSEvent {

override fun getWSClientEventType(): String {
return type
}

override fun getWSEventType(): String {
return type
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport",
)

package io.getstream.chat.android.network.models

import com.squareup.moshi.Json

/**
* Emitted when a channel is successfully shown.
*/
@com.squareup.moshi.JsonClass(generateAdapter = true)
internal data class ChannelVisibleEvent(
@Json(name = "created_at")
internal val createdAt: io.getstream.chat.android.network.infrastructure.ExactDate,

// Patched: the spec marks `channel` required, but backends before v239.47.0 (CHA-3482, chat#17545) replay
// channel.visible on /sync without it, and a parse failure fails the whole /sync response. On regen, make it
// required again only once every region runs v239.47.0 or later.
@Json(name = "channel")
internal val channel: io.getstream.chat.android.network.models.ChannelResponse? = null,

@Json(name = "custom")
internal val custom: Map<String, Any?> = emptyMap(),

@Json(name = "type")
internal val type: String = "channel.visible",

@Json(name = "channel_id")
internal val channelId: String? = null,

@Json(name = "channel_member_count")
internal val channelMemberCount: Int? = null,

@Json(name = "channel_message_count")
internal val channelMessageCount: Int? = null,

@Json(name = "channel_type")
internal val channelType: String? = null,

@Json(name = "cid")
internal val cid: String? = null,

@Json(name = "received_at")
internal val receivedAt: java.util.Date? = null,

@Json(name = "team")
internal val team: String? = null,

@Json(name = "channel_custom")
internal val channelCustom: Map<String, Any?>? = null,

@Json(name = "user")
internal val user: io.getstream.chat.android.network.models.UserResponseCommonFields? = null,
) :
io.getstream.chat.android.network.models.WSClientEvent, io.getstream.chat.android.network.models.WSEvent {

override fun getWSClientEventType(): String {
return type
}

override fun getWSEventType(): String {
return type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ internal fun createChannelHiddenEventStringJson() =
createChatEventStringJson(
"channel.hidden",
"""
"user": ${createUserJsonString()},
"user": ${createCommonFieldsUserJsonString()},
"channel_type": "channelType",
"channel_id": "channelId",
"cid": "channelType:channelId",
"clear_history": true,
"channel": ${createChannelJsonString()},
"channel": ${createGeneratedChannelJsonString()},
"channel_last_message_at": "2020-06-29T06:14:28.000Z"
""".trimIndent(),
)
Expand All @@ -49,11 +49,11 @@ internal fun createChannelHiddenSyncReplayEventStringJson() =
createChatEventStringJson(
"channel.hidden",
"""
"user": ${createUserJsonString()},
"user": ${createCommonFieldsUserJsonString()},
"channel_type": "channelType",
"channel_id": "channelId",
"cid": "channelType:channelId",
"channel": ${createChannelJsonString()}
"channel": ${createGeneratedChannelJsonString()}
""".trimIndent(),
)

Expand Down Expand Up @@ -117,8 +117,8 @@ internal fun createChannelVisibleEventStringJson() =
"channel_type": "channelType",
"channel_id": "channelId",
"cid": "channelType:channelId",
"user": ${createUserJsonString()},
"channel": ${createChannelJsonString()},
"user": ${createCommonFieldsUserJsonString()},
"channel": ${createGeneratedChannelJsonString()},
"channel_last_message_at": "2020-06-29T06:14:28.000Z"
""".trimIndent(),
)
Expand All @@ -130,7 +130,7 @@ internal fun createChannelVisibleSyncReplayEventStringJson() =
"channel_type": "channelType",
"channel_id": "channelId",
"cid": "channelType:channelId",
"user": ${createUserJsonString()}
"user": ${createCommonFieldsUserJsonString()}
""".trimIndent(),
)

Expand Down
Loading
Loading