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 @@ -28,7 +28,6 @@ import io.getstream.chat.android.client.api2.model.dto.DeviceDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamChannelDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamChannelMuteDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamChannelUserRead
import io.getstream.chat.android.client.api2.model.dto.DownstreamChatPreferencesDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamDraftDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamFlagDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamLocationDto
Expand Down Expand Up @@ -1365,16 +1364,6 @@ internal class DomainMapping(
chatPreferences = chat_preferences?.toDomain(),
)

internal fun DownstreamChatPreferencesDto.toDomain(): ChatPreferences = ChatPreferences(
directMentions = ChatPreferenceToggle.fromValue(direct_mentions),
roleMentions = ChatPreferenceToggle.fromValue(role_mentions),
groupMentions = ChatPreferenceToggle.fromValue(group_mentions),
hereMentions = ChatPreferenceToggle.fromValue(here_mentions),
channelMentions = ChatPreferenceToggle.fromValue(channel_mentions),
threadReplies = ChatPreferenceToggle.fromValue(thread_replies),
defaultPreference = ChatPreferenceToggle.fromValue(default_preference),
)

internal fun PushPreferencesResponse.toDomain(): PushPreference = PushPreference(
level = PushPreferenceLevel.fromValue(chatLevel),
disabledUntil = disabledUntil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.getstream.chat.android.client.api2.model.dto

import com.squareup.moshi.JsonClass
import io.getstream.chat.android.network.models.ChatPreferencesResponse
import java.util.Date

/**
Expand All @@ -28,18 +29,7 @@
*/
@JsonClass(generateAdapter = true)
internal data class DownstreamPushPreferenceDto(
val chat_level: String?,

Check warning on line 32 in stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/DownstreamPushPreferenceDto.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this parameter to match the regular expression ^`?[_a-z][a-zA-Z0-9]*`?$

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AaBcf7M2kZtwr73qaWv8&open=AaBcf7M2kZtwr73qaWv8&pullRequest=6677
val disabled_until: Date?,

Check warning on line 33 in stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/DownstreamPushPreferenceDto.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this parameter to match the regular expression ^`?[_a-z][a-zA-Z0-9]*`?$

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AaBcf7M2kZtwr73qaWv9&open=AaBcf7M2kZtwr73qaWv9&pullRequest=6677
val chat_preferences: DownstreamChatPreferencesDto? = null,
)

@JsonClass(generateAdapter = true)
internal data class DownstreamChatPreferencesDto(
val direct_mentions: String? = null,
val role_mentions: String? = null,
val group_mentions: String? = null,
val here_mentions: String? = null,
val channel_mentions: String? = null,
val thread_replies: String? = null,
val default_preference: String? = null,
val chat_preferences: ChatPreferencesResponse? = null,

Check warning on line 34 in stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/DownstreamPushPreferenceDto.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this parameter to match the regular expression ^`?[_a-z][a-zA-Z0-9]*`?$

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AaBcf7M2kZtwr73qaWv-&open=AaBcf7M2kZtwr73qaWv-&pullRequest=6677
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import io.getstream.chat.android.client.Mother.randomUserGroupMemberDto
import io.getstream.chat.android.client.Mother.randomUserGroupResponse
import io.getstream.chat.android.client.Mother.randomUserResponse
import io.getstream.chat.android.client.api2.mapping.DomainMappingTest.Companion.toSortDomainArguments
import io.getstream.chat.android.client.api2.model.dto.DownstreamPushPreferenceDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserGroupDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserGroupMemberDto
import io.getstream.chat.android.client.api2.model.response.MessageResponse
Expand All @@ -89,6 +90,7 @@ import io.getstream.chat.android.models.ChannelMute
import io.getstream.chat.android.models.ChannelTransformer
import io.getstream.chat.android.models.ChannelUserRead
import io.getstream.chat.android.models.ChatPreferenceToggle
import io.getstream.chat.android.models.ChatPreferences
import io.getstream.chat.android.models.Command
import io.getstream.chat.android.models.Config
import io.getstream.chat.android.models.Device
Expand All @@ -109,6 +111,7 @@ import io.getstream.chat.android.models.NoOpUserTransformer
import io.getstream.chat.android.models.Option
import io.getstream.chat.android.models.PendingMessage
import io.getstream.chat.android.models.Poll
import io.getstream.chat.android.models.PushPreference
import io.getstream.chat.android.models.PushPreferenceLevel
import io.getstream.chat.android.models.PushProvider
import io.getstream.chat.android.models.QueryPollVotesResult
Expand Down Expand Up @@ -1683,6 +1686,42 @@ internal class DomainMappingTest {
)
}

@Test
fun `DownstreamPushPreferenceDto keeps every chat preference toggle`() {
Comment thread
andremion marked this conversation as resolved.
val sut = Fixture().get()

val result = with(sut) {
DownstreamPushPreferenceDto(
chat_level = "all",
disabled_until = Date(1000),
chat_preferences = ChatPreferencesResponse(
directMentions = "all",
roleMentions = "none",
groupMentions = "all",
hereMentions = "none",
channelMentions = "all",
threadReplies = "none",
defaultPreference = "all",
),
).toDomain()
}

val expected = PushPreference(
level = PushPreferenceLevel.all,
disabledUntil = Date(1000),
chatPreferences = ChatPreferences(
directMentions = ChatPreferenceToggle.all,
roleMentions = ChatPreferenceToggle.none,
groupMentions = ChatPreferenceToggle.all,
hereMentions = ChatPreferenceToggle.none,
channelMentions = ChatPreferenceToggle.all,
threadReplies = ChatPreferenceToggle.none,
defaultPreference = ChatPreferenceToggle.all,
),
)
assertEquals(expected, result)
}

@Test
fun `Channel push preferences keep their chat preferences`() {
val sut = Fixture().get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.getstream.chat.android.client.api2.model.dto.PrivacySettingsDto
import io.getstream.chat.android.client.api2.model.dto.ReadReceiptsDto
import io.getstream.chat.android.client.api2.model.dto.TypingIndicatorsDto
import io.getstream.chat.android.client.api2.model.dto.UpstreamUserDto
import io.getstream.chat.android.network.models.ChatPreferencesResponse
import io.getstream.chat.android.network.models.UserResponse
import org.intellij.lang.annotations.Language
import java.util.Date
Expand Down Expand Up @@ -191,7 +192,16 @@ internal object UserDtoTestData {
"avg_response_time": 1000,
"push_preferences": {
"chat_level": "default",
"disabled_until": "2020-06-10T11:04:31.588Z"
"disabled_until": "2020-06-10T11:04:31.588Z",
"chat_preferences": {
"direct_mentions": "all",
"role_mentions": "none",
"group_mentions": "all",
"here_mentions": "none",
"channel_mentions": "all",
"thread_replies": "none",
"default_preference": "all"
}
}
}"""
const val userResponseJson =
Expand Down Expand Up @@ -275,6 +285,16 @@ internal object UserDtoTestData {
push_preferences = DownstreamPushPreferenceDto(
chat_level = "default",
disabled_until = Date(1591787071588),
// Toggles alternate so a key read into the wrong property cannot look correct.
chat_preferences = ChatPreferencesResponse(
directMentions = "all",
roleMentions = "none",
groupMentions = "all",
hereMentions = "none",
channelMentions = "all",
threadReplies = "none",
defaultPreference = "all",
),
),
extraData = emptyMap(),
)
Expand Down
Loading