Sitelet https://github.com/GetStream/stream-chat-android/commit/f4a08c94fcdef2a7f08f54e100ed70b18e814338
Skip to content

Commit f4a08c9

Browse files
committed
Swap the message moderation and reaction groups to the generated models
1 parent 6a0536d commit f4a08c9

11 files changed

Lines changed: 226 additions & 104 deletions

File tree

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ import io.getstream.chat.android.client.api2.model.dto.DownstreamMemberDto
3434
import io.getstream.chat.android.client.api2.model.dto.DownstreamMemberInfoDto
3535
import io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto
3636
import io.getstream.chat.android.client.api2.model.dto.DownstreamModerationDetailsDto
37-
import io.getstream.chat.android.client.api2.model.dto.DownstreamModerationDto
3837
import io.getstream.chat.android.client.api2.model.dto.DownstreamMuteDto
3938
import io.getstream.chat.android.client.api2.model.dto.DownstreamPendingMessageDto
4039
import io.getstream.chat.android.client.api2.model.dto.DownstreamPollDto
4140
import io.getstream.chat.android.client.api2.model.dto.DownstreamPollOptionDto
4241
import io.getstream.chat.android.client.api2.model.dto.DownstreamPushPreferenceDto
4342
import io.getstream.chat.android.client.api2.model.dto.DownstreamReactionDto
44-
import io.getstream.chat.android.client.api2.model.dto.DownstreamReactionGroupDto
4543
import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderDto
4644
import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderInfoDto
4745
import io.getstream.chat.android.client.api2.model.dto.DownstreamThreadDto
@@ -136,13 +134,15 @@ import io.getstream.chat.android.network.models.DeviceResponse
136134
import io.getstream.chat.android.network.models.FullUserResponse
137135
import io.getstream.chat.android.network.models.GetApplicationResponse
138136
import io.getstream.chat.android.network.models.GetOGResponse
137+
import io.getstream.chat.android.network.models.ModerationV2Response
139138
import io.getstream.chat.android.network.models.PollOptionResponseData
140139
import io.getstream.chat.android.network.models.PollResponseData
141140
import io.getstream.chat.android.network.models.PollVoteResponseData
142141
import io.getstream.chat.android.network.models.PollVotesResponse
143142
import io.getstream.chat.android.network.models.PrivacySettingsResponse
144143
import io.getstream.chat.android.network.models.PushPreferencesResponse
145144
import io.getstream.chat.android.network.models.QueryPollsResponse
145+
import io.getstream.chat.android.network.models.ReactionGroupResponse
146146
import io.getstream.chat.android.network.models.ReactionResponse
147147
import io.getstream.chat.android.network.models.UnreadCountsChannel
148148
import io.getstream.chat.android.network.models.UnreadCountsChannelType
@@ -530,15 +530,15 @@ internal class DomainMapping(
530530
)
531531

532532
/**
533-
* Transforms [DownstreamReactionGroupDto] to [ReactionGroup].
533+
* Transforms [ReactionGroupResponse] to [ReactionGroup].
534534
*/
535-
internal fun DownstreamReactionGroupDto.toDomain(type: String): ReactionGroup =
535+
internal fun ReactionGroupResponse.toDomain(type: String): ReactionGroup =
536536
ReactionGroup(
537537
type = type,
538538
count = count,
539-
sumScore = sum_scores,
540-
firstReactionAt = first_reaction_at,
541-
lastReactionAt = last_reaction_at,
539+
sumScore = sumScores,
540+
firstReactionAt = firstReactionAt,
541+
lastReactionAt = lastReactionAt,
542542
)
543543

544544
/**
@@ -1124,16 +1124,16 @@ internal class DomainMapping(
11241124
)
11251125

11261126
/**
1127-
* Maps the network [DownstreamModerationDto] to the domain model [Moderation].
1127+
* Maps the network [ModerationV2Response] to the domain model [Moderation].
11281128
*/
1129-
internal fun DownstreamModerationDto.toDomain() = Moderation(
1130-
action = ModerationAction.fromValue(this.action),
1131-
originalText = this.original_text,
1132-
textHarms = this.text_harms.orEmpty(),
1133-
imageHarms = this.image_harms.orEmpty(),
1134-
blocklistMatched = this.blocklist_matched,
1135-
semanticFilterMatched = this.semantic_filter_matched,
1136-
platformCircumvented = this.platform_circumvented ?: false,
1129+
internal fun ModerationV2Response.toDomain() = Moderation(
1130+
action = ModerationAction.fromValue(action),
1131+
originalText = originalText,
1132+
textHarms = textHarms.orEmpty(),
1133+
imageHarms = imageHarms.orEmpty(),
1134+
blocklistMatched = blocklistMatched,
1135+
semanticFilterMatched = semanticFilterMatched,
1136+
platformCircumvented = platformCircumvented ?: false,
11371137
)
11381138

11391139
/**

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/ReactionDtos.kt renamed to stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/DownstreamReactionDto.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,3 @@ internal data class DownstreamReactionDto(
4343
val emoji_code: String?,
4444
val extraData: Map<String, Any>,
4545
) : ExtraDataDto
46-
47-
@JsonClass(generateAdapter = true)
48-
internal data class DownstreamReactionGroupDto(
49-
val count: Int,
50-
val sum_scores: Int,
51-
val first_reaction_at: Date,
52-
val last_reaction_at: Date,
53-
)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package io.getstream.chat.android.client.api2.model.dto
1919
import com.squareup.moshi.JsonClass
2020
import io.getstream.chat.android.core.internal.StreamHandsOff
2121
import io.getstream.chat.android.network.models.Attachment
22+
import io.getstream.chat.android.network.models.ModerationV2Response
2223
import io.getstream.chat.android.network.models.PollResponseData
24+
import io.getstream.chat.android.network.models.ReactionGroupResponse
2325
import java.util.Date
2426

2527
/**
@@ -58,7 +60,7 @@ internal data class DownstreamMessageDto(
5860
val quoted_message_id: String?,
5961
val reaction_counts: Map<String, Int>?,
6062
val reaction_scores: Map<String, Int>?,
61-
val reaction_groups: Map<String, DownstreamReactionGroupDto>?,
63+
val reaction_groups: Map<String, ReactionGroupResponse>?,
6264
val reply_count: Int,
6365
val deleted_reply_count: Int,
6466
val shadowed: Boolean = false,
@@ -70,7 +72,7 @@ internal data class DownstreamMessageDto(
7072
val updated_at: Date,
7173
val user: DownstreamUserDto,
7274
val moderation_details: DownstreamModerationDetailsDto? = null, // Used for Moderation V1
73-
val moderation: DownstreamModerationDto? = null, // Used for Moderation V2
75+
val moderation: ModerationV2Response? = null, // Used for Moderation V2
7476
val poll: PollResponseData? = null,
7577
val reminder: DownstreamReminderInfoDto? = null,
7678
val shared_location: DownstreamLocationDto? = null,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 ModerationV2Response(
33+
@Json(name = "action")
34+
internal val action: String,
35+
36+
@Json(name = "original_text")
37+
internal val originalText: String,
38+
39+
@Json(name = "blocklist_matched")
40+
internal val blocklistMatched: String? = null,
41+
42+
@Json(name = "platform_circumvented")
43+
internal val platformCircumvented: Boolean? = null,
44+
45+
@Json(name = "semantic_filter_matched")
46+
internal val semanticFilterMatched: String? = null,
47+
48+
@Json(name = "blocklists_matched")
49+
internal val blocklistsMatched: List<String>? = emptyList(),
50+
51+
@Json(name = "image_harms")
52+
internal val imageHarms: List<String>? = emptyList(),
53+
54+
@Json(name = "text_harms")
55+
internal val textHarms: List<String>? = emptyList(),
56+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
* ReactionGroupResponse contains all information about a reaction of the same type.
30+
*/
31+
@com.squareup.moshi.JsonClass(generateAdapter = true)
32+
internal data class ReactionGroupResponse(
33+
@Json(name = "count")
34+
internal val count: Int,
35+
36+
@Json(name = "first_reaction_at")
37+
internal val firstReactionAt: java.util.Date,
38+
39+
@Json(name = "last_reaction_at")
40+
internal val lastReactionAt: java.util.Date,
41+
42+
@Json(name = "sum_scores")
43+
internal val sumScores: Int,
44+
45+
@Json(name = "latest_reactions_by")
46+
internal val latestReactionsBy: List<io.getstream.chat.android.network.models.ReactionGroupUserResponse> = emptyList(),
47+
)

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/DownstreamModerationDto.kt renamed to stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ReactionGroupUserResponse.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.getstream.chat.android.client.api2.model.dto
17+
@file:Suppress(
18+
"ArrayInDataClass",
19+
"EnumEntryName",
20+
"RemoveRedundantQualifierName",
21+
"UnusedImport",
22+
)
23+
24+
package io.getstream.chat.android.network.models
1825

19-
import com.squareup.moshi.JsonClass
26+
import com.squareup.moshi.Json
2027

2128
/**
22-
* Downstream JSON holding the data related to Moderation V2.
29+
* Contains information about a user who reacted with this reaction type.
2330
*/
24-
@JsonClass(generateAdapter = true)
25-
internal data class DownstreamModerationDto(
26-
val action: String,
27-
val original_text: String,
28-
val text_harms: List<String>?,
29-
val image_harms: List<String>?,
30-
val blocklist_matched: String?,
31-
val semantic_filter_matched: String?,
32-
val platform_circumvented: Boolean?,
31+
@com.squareup.moshi.JsonClass(generateAdapter = true)
32+
internal data class ReactionGroupUserResponse(
33+
@Json(name = "created_at")
34+
internal val createdAt: java.util.Date,
35+
36+
@Json(name = "user_id")
37+
internal val userId: String,
38+
39+
@Json(name = "user")
40+
internal val user: io.getstream.chat.android.network.models.UserResponse? = null,
3341
)

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ import io.getstream.chat.android.client.api2.model.dto.DownstreamMemberDto
3636
import io.getstream.chat.android.client.api2.model.dto.DownstreamMemberInfoDto
3737
import io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto
3838
import io.getstream.chat.android.client.api2.model.dto.DownstreamModerationDetailsDto
39-
import io.getstream.chat.android.client.api2.model.dto.DownstreamModerationDto
4039
import io.getstream.chat.android.client.api2.model.dto.DownstreamMuteDto
4140
import io.getstream.chat.android.client.api2.model.dto.DownstreamPendingMessageDto
4241
import io.getstream.chat.android.client.api2.model.dto.DownstreamPollDto
4342
import io.getstream.chat.android.client.api2.model.dto.DownstreamPollOptionDto
4443
import io.getstream.chat.android.client.api2.model.dto.DownstreamPushPreferenceDto
4544
import io.getstream.chat.android.client.api2.model.dto.DownstreamReactionDto
46-
import io.getstream.chat.android.client.api2.model.dto.DownstreamReactionGroupDto
4745
import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderDto
4846
import io.getstream.chat.android.client.api2.model.dto.DownstreamThreadDto
4947
import io.getstream.chat.android.client.api2.model.dto.DownstreamThreadInfoDto
@@ -100,11 +98,13 @@ import io.getstream.chat.android.network.models.FileUploadResponse
10098
import io.getstream.chat.android.network.models.FullUserResponse
10199
import io.getstream.chat.android.network.models.GetApplicationResponse
102100
import io.getstream.chat.android.network.models.GetOGResponse
101+
import io.getstream.chat.android.network.models.ModerationV2Response
103102
import io.getstream.chat.android.network.models.PollOptionResponseData
104103
import io.getstream.chat.android.network.models.PollResponseData
105104
import io.getstream.chat.android.network.models.PollVoteResponseData
106105
import io.getstream.chat.android.network.models.PollVotesResponse
107106
import io.getstream.chat.android.network.models.QueryPollsResponse
107+
import io.getstream.chat.android.network.models.ReactionGroupResponse
108108
import io.getstream.chat.android.network.models.ReactionResponse
109109
import io.getstream.chat.android.network.models.ThreadParticipant
110110
import io.getstream.chat.android.network.models.UnblockUsersResponse
@@ -320,7 +320,7 @@ internal object Mother {
320320
quoted_message_id: String? = randomString(),
321321
reaction_counts: Map<String, Int>? = emptyMap(),
322322
reaction_scores: Map<String, Int>? = emptyMap(),
323-
reaction_groups: Map<String, DownstreamReactionGroupDto>? = emptyMap(),
323+
reaction_groups: Map<String, ReactionGroupResponse>? = emptyMap(),
324324
reply_count: Int = randomInt(),
325325
deleted_reply_count: Int = randomInt(),
326326
shadowed: Boolean = randomBoolean(),
@@ -332,7 +332,7 @@ internal object Mother {
332332
updated_at: Date = randomDate(),
333333
user: DownstreamUserDto = randomDownstreamUserDto(),
334334
moderation_details: DownstreamModerationDetailsDto? = null,
335-
moderation: DownstreamModerationDto? = null,
335+
moderation: ModerationV2Response? = null,
336336
poll: PollResponseData? = null,
337337
member: DownstreamMemberInfoDto? = randomDownstreamMemberInfoDto(),
338338
deleted_for_me: Boolean? = null,
@@ -698,16 +698,16 @@ internal object Mother {
698698
expires = expires,
699699
)
700700

701-
fun randomDownstreamReactionGroupDto(
701+
fun randomReactionGroupResponse(
702702
count: Int = randomInt(),
703703
sumScores: Int = randomInt(),
704704
firstReactionAt: Date = randomDate(),
705705
lastReactionAt: Date = randomDate(),
706-
): DownstreamReactionGroupDto = DownstreamReactionGroupDto(
706+
): ReactionGroupResponse = ReactionGroupResponse(
707707
count = count,
708-
sum_scores = sumScores,
709-
first_reaction_at = firstReactionAt,
710-
last_reaction_at = lastReactionAt,
708+
sumScores = sumScores,
709+
firstReactionAt = firstReactionAt,
710+
lastReactionAt = lastReactionAt,
711711
)
712712

713713
fun randomChannelMemberResponse(
@@ -942,22 +942,22 @@ internal object Mother {
942942
extraData = extraData,
943943
)
944944

945-
fun randomDownstreamModerationDto(
945+
fun randomModerationV2Response(
946946
action: String = randomString(),
947947
originalText: String = randomString(),
948948
textHarms: List<String> = listOf(randomString()),
949949
imageHarms: List<String> = listOf(randomString()),
950950
blocklistMatched: String = randomString(),
951951
semanticFilterMatched: String = randomString(),
952952
platformCircumvented: Boolean = randomBoolean(),
953-
): DownstreamModerationDto = DownstreamModerationDto(
953+
): ModerationV2Response = ModerationV2Response(
954954
action = action,
955-
original_text = originalText,
956-
text_harms = textHarms,
957-
image_harms = imageHarms,
958-
blocklist_matched = blocklistMatched,
959-
semantic_filter_matched = semanticFilterMatched,
960-
platform_circumvented = platformCircumvented,
955+
originalText = originalText,
956+
textHarms = textHarms,
957+
imageHarms = imageHarms,
958+
blocklistMatched = blocklistMatched,
959+
semanticFilterMatched = semanticFilterMatched,
960+
platformCircumvented = platformCircumvented,
961961
)
962962

963963
fun randomPrivacySettingsDto(

0 commit comments

Comments
 (0)