Parse the socket hello and keep-alive with the generated event models · GetStream/stream-chat-android@7b82516 · GitHub
Skip to content

Commit 7b82516

Browse files
committed
Parse the socket hello and keep-alive with the generated event models
1 parent 26d5fa2 commit 7b82516

8 files changed

Lines changed: 269 additions & 62 deletions

File tree

‎stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/EventMapping.kt‎

Lines changed: 19 additions & 17 deletions

‎stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/EventDtos.kt‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,13 @@ import com.squareup.moshi.JsonClass
2020
import io.getstream.chat.android.client.api2.model.dto.utils.internal.ExactDate
2121
import io.getstream.chat.android.network.models.ChannelMemberResponse
2222
import io.getstream.chat.android.network.models.ChannelResponse
23-
import io.getstream.chat.android.network.models.OwnUserResponse
2423
import io.getstream.chat.android.network.models.UserResponseCommonFields
2524
import io.getstream.chat.android.network.models.WSEvent
2625
import io.getstream.result.Error
2726
import java.util.Date
2827

2928
internal sealed class ChatEventDto
3029

31-
@JsonClass(generateAdapter = true)
32-
internal data class HealthEventDto(
33-
val type: String,
34-
val created_at: ExactDate,
35-
val connection_id: String,
36-
) : ChatEventDto()
37-
3830
@JsonClass(generateAdapter = true)
3931
internal data class NotificationAddedToChannelEventDto(
4032
val type: String,
@@ -79,14 +71,6 @@ internal data class AIIndicatorStopEventDto(
7971
val created_at: ExactDate,
8072
) : ChatEventDto()
8173

82-
@JsonClass(generateAdapter = true)
83-
internal data class ConnectedEventDto(
84-
val type: String,
85-
val created_at: ExactDate,
86-
val me: OwnUserResponse,
87-
val connection_id: String,
88-
) : ChatEventDto()
89-
9074
@JsonClass(generateAdapter = true)
9175
internal data class ConnectionErrorEventDto(
9276
val type: String,

‎stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventAdapter.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ import io.getstream.chat.android.client.api2.model.dto.AIIndicatorClearEventDto
2727
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorStopEventDto
2828
import io.getstream.chat.android.client.api2.model.dto.AIIndicatorUpdatedEventDto
2929
import io.getstream.chat.android.client.api2.model.dto.ChatEventDto
30-
import io.getstream.chat.android.client.api2.model.dto.ConnectedEventDto
3130
import io.getstream.chat.android.client.api2.model.dto.ConnectionErrorEventDto
3231
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserDto
3332
import io.getstream.chat.android.client.api2.model.dto.GeneratedEventDto
34-
import io.getstream.chat.android.client.api2.model.dto.HealthEventDto
3533
import io.getstream.chat.android.client.api2.model.dto.NotificationAddedToChannelEventDto
3634
import io.getstream.chat.android.client.api2.model.dto.UnknownEventDto
3735
import io.getstream.chat.android.client.api2.model.dto.utils.internal.ExactDate
@@ -41,8 +39,10 @@ import io.getstream.chat.android.network.models.ChannelHiddenEvent
4139
import io.getstream.chat.android.network.models.ChannelTruncatedEvent
4240
import io.getstream.chat.android.network.models.ChannelUpdatedEvent
4341
import io.getstream.chat.android.network.models.ChannelVisibleEvent
42+
import io.getstream.chat.android.network.models.ConnectedEvent
4443
import io.getstream.chat.android.network.models.DraftDeletedEvent
4544
import io.getstream.chat.android.network.models.DraftUpdatedEvent
45+
import io.getstream.chat.android.network.models.HealthCheckEvent
4646
import io.getstream.chat.android.network.models.MemberAddedEvent
4747
import io.getstream.chat.android.network.models.MemberRemovedEvent
4848
import io.getstream.chat.android.network.models.MemberUpdatedEvent
@@ -107,9 +107,9 @@ internal class EventDtoAdapter(
107107
private val mapAdapter: JsonAdapter<MutableMap<String, Any?>> =
108108
moshi.adapter(Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java))
109109

110-
private val connectedEventAdapter = moshi.adapter(ConnectedEventDto::class.java)
110+
private val connectedEventAdapter = generatedEventAdapter<ConnectedEvent> { emptyMap() }
111111
private val connectionErrorEventAdapter = moshi.adapter(ConnectionErrorEventDto::class.java)
112-
private val healthEventAdapter = moshi.adapter(HealthEventDto::class.java)
112+
private val healthEventAdapter = generatedEventAdapter<HealthCheckEvent> { emptyMap() }
113113
private val draftMessageUpdatedEventAdapter = generatedEventAdapter<DraftUpdatedEvent> { mapOf("draft" to draft) }
114114
private val draftMessageDeletedEventAdapter = generatedEventAdapter<DraftDeletedEvent> { mapOf("draft" to draft) }
115115
private val newMessageEventAdapter = generatedEventAdapter<MessageNewEvent> { mapOf("cid" to cid, "user" to user) }
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@file:Suppress(
18+
"ArrayInDataClass",
19+
"EnumEntryName",
20+
"RemoveRedundantQualifierName",
21+
"UnusedImport",
22+
)
23+
24+
package io.getstream.chat.android.network.models
25+
26+
import com.squareup.moshi.Json
27+
28+
/**
29+
* This event is sent when the WS connection is established and authenticated, this event contains the full user object as it is stored on the server
30+
*/
31+
@com.squareup.moshi.JsonClass(generateAdapter = true)
32+
internal data class ConnectedEvent(
33+
@Json(name = "connection_id")
34+
internal val connectionId: String,
35+
36+
@Json(name = "created_at")
37+
internal val createdAt: io.getstream.chat.android.network.infrastructure.ExactDate,
38+
39+
@Json(name = "me")
40+
internal val me: io.getstream.chat.android.network.models.OwnUserResponse,
41+
42+
@Json(name = "type")
43+
internal val type: String = "connection.ok",
44+
) :
45+
io.getstream.chat.android.network.models.WSEvent {
46+
47+
override fun getWSEventType(): String {
48+
return type
49+
}
50+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@file:Suppress(
18+
"ArrayInDataClass",
19+
"EnumEntryName",
20+
"RemoveRedundantQualifierName",
21+
"UnusedImport",
22+
)
23+
24+
package io.getstream.chat.android.network.models
25+
26+
import com.squareup.moshi.Json
27+
28+
/**
29+
*
30+
*/
31+
@com.squareup.moshi.JsonClass(generateAdapter = true)
32+
internal data class HealthCheckEvent(
33+
@Json(name = "connection_id")
34+
internal val connectionId: String,
35+
36+
@Json(name = "created_at")
37+
internal val createdAt: io.getstream.chat.android.network.infrastructure.ExactDate,
38+
39+
@Json(name = "custom")
40+
internal val custom: Map<String, Any?> = emptyMap(),
41+
42+
@Json(name = "type")
43+
internal val type: String = "health.check",
44+
45+
@Json(name = "cid")
46+
internal val cid: String? = null,
47+
48+
@Json(name = "received_at")
49+
internal val receivedAt: java.util.Date? = null,
50+
51+
@Json(name = "me")
52+
internal val me: io.getstream.chat.android.network.models.OwnUserResponse? = null,
53+
) :
54+
io.getstream.chat.android.network.models.WSClientEvent, io.getstream.chat.android.network.models.WSEvent {
55+
56+
override fun getWSClientEventType(): String {
57+
return type
58+
}
59+
60+
override fun getWSEventType(): String {
61+
return type
62+
}
63+
}

‎stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt‎

Lines changed: 8 additions & 7 deletions

0 commit comments

Comments
 (0)