From 4823b880670b98cdab6528b0c7feb5c8baa5ced8 Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Wed, 7 Oct 2026 17:29:15 +0200 Subject: [PATCH 1/2] Parse the channel hidden and visible events with the generated event models --- .../client/api2/mapping/EventMapping.kt | 48 +++++----- .../client/api2/model/dto/EventDtos.kt | 25 ------ .../client/parser2/adapters/EventAdapter.kt | 10 ++- .../network/models/ChannelHiddenEvent.kt | 87 +++++++++++++++++++ .../network/models/ChannelVisibleEvent.kt | 84 ++++++++++++++++++ .../android/client/EventChatJsonProvider.kt | 14 +-- .../api2/mapping/EventMappingTestArguments.kt | 76 +++++++++------- .../android/client/parser/EventArguments.kt | 8 +- .../GeneratedChannelEventParsingTest.kt | 15 +++- 9 files changed, 271 insertions(+), 96 deletions(-) create mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt create mode 100644 stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt index ca10680d937..8e1c88798c0 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt @@ -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 @@ -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 @@ -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() @@ -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), ) } @@ -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() diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt index b9f2ae91167..82c13cca3fe 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt @@ -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, diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventAdapter.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventAdapter.kt index c34b362e45f..9148000f205 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventAdapter.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventAdapter.kt @@ -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 @@ -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 @@ -150,9 +150,11 @@ internal class EventDtoAdapter( private val memberUpdatedEventAdapter = generatedEventAdapter { mapOf("cid" to cid, "user" to user) } private val channelUpdatedEventAdapter = generatedEventAdapter { mapOf("cid" to cid) } - private val channelHiddenEventAdapter = moshi.adapter(ChannelHiddenEventDto::class.java) + private val channelHiddenEventAdapter = + generatedEventAdapter { mapOf("cid" to cid, "user" to user) } private val channelDeletedEventAdapter = generatedEventAdapter { mapOf("cid" to cid) } - private val channelVisibleEventAdapter = moshi.adapter(ChannelVisibleEventDto::class.java) + private val channelVisibleEventAdapter = + generatedEventAdapter { mapOf("cid" to cid, "user" to user) } private val channelTruncatedEventAdapter = generatedEventAdapter { mapOf("cid" to cid) } private val userStartWatchingEventAdapter = generatedEventAdapter { mapOf("cid" to cid) } private val userStopWatchingEventAdapter = generatedEventAdapter { mapOf("cid" to cid) } diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt new file mode 100644 index 00000000000..6744056e0a4 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt @@ -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 = 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? = 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 + } +} diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt new file mode 100644 index 00000000000..5ed89e721b0 --- /dev/null +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt @@ -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 = 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? = 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 + } +} diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/EventChatJsonProvider.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/EventChatJsonProvider.kt index 17001fb9f15..411a6c33e3d 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/EventChatJsonProvider.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/EventChatJsonProvider.kt @@ -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(), ) @@ -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(), ) @@ -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(), ) @@ -130,7 +130,7 @@ internal fun createChannelVisibleSyncReplayEventStringJson() = "channel_type": "channelType", "channel_id": "channelId", "cid": "channelType:channelId", - "user": ${createUserJsonString()} + "user": ${createCommonFieldsUserJsonString()} """.trimIndent(), ) diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/EventMappingTestArguments.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/EventMappingTestArguments.kt index 46ba4103cf4..910b1809406 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/EventMappingTestArguments.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/EventMappingTestArguments.kt @@ -20,8 +20,6 @@ import io.getstream.chat.android.client.Mother 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.ConnectedEventDto import io.getstream.chat.android.client.api2.model.dto.ConnectingEventDto import io.getstream.chat.android.client.api2.model.dto.ConnectionErrorEventDto @@ -113,8 +111,10 @@ import org.junit.jupiter.params.provider.Arguments import java.util.Date import io.getstream.chat.android.network.infrastructure.ExactDate as GeneratedExactDate 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 @@ -288,17 +288,22 @@ internal object EventMappingTestArguments { private val channelDeletedDto = GeneratedEventDto(channelDeletedEvent) - private val channelHiddenDto = ChannelHiddenEventDto( + private val channelHiddenEvent = GeneratedChannelHiddenEvent( type = EventType.CHANNEL_HIDDEN, - created_at = EXACT_DATE, + createdAt = GENERATED_EXACT_DATE, cid = CID, - channel_type = CHANNEL_TYPE, - channel_id = CHANNEL_ID, - user = USER, - channel = CHANNEL, - clear_history = CLEAR_HISTORY, + channelType = CHANNEL_TYPE, + channelId = CHANNEL_ID, + user = COMMON_USER, + channel = GENERATED_CHANNEL, + clearHistory = CLEAR_HISTORY, ) + private val channelHiddenDto = GeneratedEventDto(channelHiddenEvent) + + // As /sync replays it on backends before v239.47.0: no clear_history. + private val channelHiddenWithoutClearHistoryDto = GeneratedEventDto(channelHiddenEvent.copy(clearHistory = null)) + private val channelTruncatedEvent = GeneratedChannelTruncatedEvent( type = EventType.CHANNEL_TRUNCATED, createdAt = GENERATED_EXACT_DATE, @@ -351,17 +356,19 @@ internal object EventMappingTestArguments { private val channelUserUnbannedDto = GeneratedEventDto(channelUserUnbannedEvent) - private val channelVisibleDto = ChannelVisibleEventDto( + private val channelVisibleEvent = GeneratedChannelVisibleEvent( type = EventType.CHANNEL_VISIBLE, - created_at = EXACT_DATE, + createdAt = GENERATED_EXACT_DATE, cid = CID, - channel_type = CHANNEL_TYPE, - channel_id = CHANNEL_ID, - channel = CHANNEL, - user = USER, + channelType = CHANNEL_TYPE, + channelId = CHANNEL_ID, + channel = GENERATED_CHANNEL, + user = COMMON_USER, ) - private val channelVisibleWithoutChannelDto = channelVisibleDto.copy(channel = null) + private val channelVisibleDto = GeneratedEventDto(channelVisibleEvent) + + private val channelVisibleWithoutChannelDto = GeneratedEventDto(channelVisibleEvent.copy(channel = null)) private val connectedDto = ConnectedEventDto( type = EventType.CONNECTION_CONNECTING, @@ -1030,17 +1037,19 @@ internal object EventMappingTestArguments { ) private val channelHidden = ChannelHiddenEvent( - type = channelHiddenDto.type, - createdAt = channelHiddenDto.created_at.date, - rawCreatedAt = channelHiddenDto.created_at.rawDate, - user = with(domainMapping) { channelHiddenDto.user.toDomain() }, - cid = channelHiddenDto.cid, - channelType = channelHiddenDto.channel_type, - channelId = channelHiddenDto.channel_id, - channel = with(domainMapping) { channelHiddenDto.channel.toDomain() }, - clearHistory = channelHiddenDto.clear_history, + type = channelHiddenEvent.type, + createdAt = channelHiddenEvent.createdAt.date, + rawCreatedAt = channelHiddenEvent.createdAt.raw, + user = with(domainMapping) { COMMON_USER.toDomain() }, + cid = CID, + channelType = CHANNEL_TYPE, + channelId = CHANNEL_ID, + channel = with(domainMapping) { GENERATED_CHANNEL.toDomain() }, + clearHistory = CLEAR_HISTORY, ) + private val channelHiddenWithoutClearHistory = channelHidden.copy(clearHistory = false) + private val channelTruncated = ChannelTruncatedEvent( type = channelTruncatedEvent.type, createdAt = channelTruncatedEvent.createdAt.date, @@ -1099,14 +1108,14 @@ internal object EventMappingTestArguments { ) private val channelVisible = ChannelVisibleEvent( - type = channelVisibleDto.type, - createdAt = channelVisibleDto.created_at.date, - rawCreatedAt = channelVisibleDto.created_at.rawDate, - user = with(domainMapping) { channelVisibleDto.user.toDomain() }, - cid = channelVisibleDto.cid, - channelType = channelVisibleDto.channel_type, - channel = with(domainMapping) { CHANNEL.toDomain() }, - channelId = channelVisibleDto.channel_id, + type = channelVisibleEvent.type, + createdAt = channelVisibleEvent.createdAt.date, + rawCreatedAt = channelVisibleEvent.createdAt.raw, + user = with(domainMapping) { COMMON_USER.toDomain() }, + cid = CID, + channelType = CHANNEL_TYPE, + channel = with(domainMapping) { GENERATED_CHANNEL.toDomain() }, + channelId = CHANNEL_ID, ) private val channelVisibleWithoutChannel = channelVisible.copy( @@ -1735,6 +1744,7 @@ internal object EventMappingTestArguments { Arguments.of(draftMessageDeletedDto, draftMessageDeletedEvent), Arguments.of(channelDeletedDto, channelDeleted), Arguments.of(channelHiddenDto, channelHidden), + Arguments.of(channelHiddenWithoutClearHistoryDto, channelHiddenWithoutClearHistory), Arguments.of(channelTruncatedDto, channelTruncated), Arguments.of(channelUpdatedByUserDto, channelUpdatedByUser), Arguments.of(channelUpdatedDto, channelUpdated), diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser/EventArguments.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser/EventArguments.kt index bc62e8b8ad9..4c4cedfc93e 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser/EventArguments.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser/EventArguments.kt @@ -439,8 +439,8 @@ internal object EventArguments { cid = cid, channelType = channelType, channelId = channelId, - user = user, - channel = channel, + user = commonFieldsUser, + channel = wireChannel, clearHistory = true, ) @@ -494,8 +494,8 @@ internal object EventArguments { cid = cid, channelType = channelType, channelId = channelId, - channel = channel, - user = user, + channel = wireChannel, + user = commonFieldsUser, ) private val memberAddedEvent = MemberAddedEvent( type = EventType.MEMBER_ADDED, diff --git a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/GeneratedChannelEventParsingTest.kt b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/GeneratedChannelEventParsingTest.kt index 556e47f47d7..1d42122754b 100644 --- a/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/GeneratedChannelEventParsingTest.kt +++ b/stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/GeneratedChannelEventParsingTest.kt @@ -18,15 +18,21 @@ package io.getstream.chat.android.client.parser2 import com.squareup.moshi.JsonDataException import io.getstream.chat.android.client.createChannelDeletedEventStringJson +import io.getstream.chat.android.client.createChannelHiddenEventStringJson +import io.getstream.chat.android.client.createChannelHiddenSyncReplayEventStringJson import io.getstream.chat.android.client.createChannelTruncatedEventStringJson import io.getstream.chat.android.client.createChannelTruncatedServerSideEventStringJson import io.getstream.chat.android.client.createChannelUpdatedByUserEventStringJson import io.getstream.chat.android.client.createChannelUpdatedEventStringJson +import io.getstream.chat.android.client.createChannelVisibleEventStringJson +import io.getstream.chat.android.client.createChannelVisibleSyncReplayEventStringJson import io.getstream.chat.android.client.createNotificationRemovedFromChannelEventStringJson import io.getstream.chat.android.client.events.ChannelDeletedEvent +import io.getstream.chat.android.client.events.ChannelHiddenEvent import io.getstream.chat.android.client.events.ChannelTruncatedEvent import io.getstream.chat.android.client.events.ChannelUpdatedByUserEvent import io.getstream.chat.android.client.events.ChannelUpdatedEvent +import io.getstream.chat.android.client.events.ChannelVisibleEvent import io.getstream.chat.android.client.events.ChatEvent import io.getstream.chat.android.client.events.NotificationRemovedFromChannelEvent import org.amshove.kluent.shouldBeEqualTo @@ -104,6 +110,10 @@ internal class GeneratedChannelEventParsingTest { createNotificationRemovedFromChannelEventStringJson(), NotificationRemovedFromChannelEvent::class, ), + Arguments.of(createChannelHiddenEventStringJson(), ChannelHiddenEvent::class), + Arguments.of(createChannelHiddenSyncReplayEventStringJson(), ChannelHiddenEvent::class), + Arguments.of(createChannelVisibleEventStringJson(), ChannelVisibleEvent::class), + Arguments.of(createChannelVisibleSyncReplayEventStringJson(), ChannelVisibleEvent::class), ) @JvmStatic @@ -114,6 +124,9 @@ internal class GeneratedChannelEventParsingTest { createChannelDeletedEventStringJson(), createNotificationRemovedFromChannelEventStringJson(), ).flatMap { json -> listOf("cid", "channel").map { Arguments.of(json, it) } } + - Arguments.of(createNotificationRemovedFromChannelEventStringJson(), "member") + Arguments.of(createNotificationRemovedFromChannelEventStringJson(), "member") + + listOf(createChannelHiddenEventStringJson(), createChannelVisibleEventStringJson()) + .flatMap { json -> listOf("cid", "user").map { Arguments.of(json, it) } } + + Arguments.of(createChannelHiddenEventStringJson(), "channel") } } From 9def7f35c9959c6e0c1483df0785740242fb7ede Mon Sep 17 00:00:00 2001 From: Gian <47775302+gpunto@users.noreply.github.com> Date: Thu, 8 Oct 2026 15:06:24 +0200 Subject: [PATCH 2/2] Wrap the channel hidden and visible patch comments at 120 columns --- .../chat/android/network/models/ChannelHiddenEvent.kt | 6 +++--- .../chat/android/network/models/ChannelVisibleEvent.kt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt index 6744056e0a4..e06ce3d9571 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelHiddenEvent.kt @@ -30,9 +30,9 @@ import com.squareup.moshi.Json */ @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. + // 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, diff --git a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt index 5ed89e721b0..6150edf0240 100644 --- a/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt +++ b/stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ChannelVisibleEvent.kt @@ -33,9 +33,9 @@ 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. + // 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,