Skip to content
Draft
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 @@ -47,7 +47,6 @@ import io.getstream.chat.android.client.api2.mapping.DomainMapping
import io.getstream.chat.android.client.api2.mapping.DtoMapping
import io.getstream.chat.android.client.api2.mapping.EventMapping
import io.getstream.chat.android.client.api2.mapping.toFilterDomainWithFields
import io.getstream.chat.android.client.api2.model.dto.UpstreamPushPreferenceInputDto
import io.getstream.chat.android.client.api2.model.requests.BanUserRequest
import io.getstream.chat.android.client.api2.model.requests.FlagMessageRequest
import io.getstream.chat.android.client.api2.model.requests.FlagRequest
Expand All @@ -60,7 +59,6 @@ import io.getstream.chat.android.client.api2.model.requests.SendMessageRequest
import io.getstream.chat.android.client.api2.model.requests.SyncHistoryRequest
import io.getstream.chat.android.client.api2.model.requests.TruncateChannelRequest
import io.getstream.chat.android.client.api2.model.requests.UpdateMessageRequest
import io.getstream.chat.android.client.api2.model.requests.UpsertPushPreferencesRequest
import io.getstream.chat.android.client.api2.model.response.ChannelResponse
import io.getstream.chat.android.client.call.RetrofitCall
import io.getstream.chat.android.client.events.ChatEvent
Expand Down Expand Up @@ -145,7 +143,9 @@ import io.getstream.chat.android.network.models.MessageRequest
import io.getstream.chat.android.network.models.MuteChannelRequest
import io.getstream.chat.android.network.models.PollOptionInput
import io.getstream.chat.android.network.models.PollOptionRequest
import io.getstream.chat.android.network.models.PushPreferenceInput
import io.getstream.chat.android.network.models.QueryDraftsRequest
import io.getstream.chat.android.network.models.QueryMembersPayload
import io.getstream.chat.android.network.models.QueryPollVotesRequest
import io.getstream.chat.android.network.models.QueryPollsRequest
import io.getstream.chat.android.network.models.QueryReactionsRequest
Expand All @@ -172,6 +172,7 @@ import io.getstream.chat.android.network.models.UpdateUserGroupResponse
import io.getstream.chat.android.network.models.UpdateUserPartialRequest
import io.getstream.chat.android.network.models.UpdateUsersPartialRequest
import io.getstream.chat.android.network.models.UpdateUsersRequest
import io.getstream.chat.android.network.models.UpsertPushPreferencesRequest
import io.getstream.chat.android.network.models.UpsertPushPreferencesResponse
import io.getstream.chat.android.network.models.UserGroupResponse
import io.getstream.chat.android.network.models.UserRequest
Expand Down Expand Up @@ -495,11 +496,11 @@ constructor(
}

override fun setUserPushPreference(level: PushPreferenceLevel): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = null,
chat_level = level.value,
disabled_until = null,
remove_disable = true,
val input = PushPreferenceInput(
channelCid = null,
chatLevel = PushPreferenceInput.ChatLevel.fromString(level.value),
disabledUntil = null,
removeDisable = true,
)
val request = UpsertPushPreferencesRequest(listOf(input))
return pushPreferencesApi
Expand All @@ -508,11 +509,11 @@ constructor(
}

override fun snoozeUserPushNotifications(until: Date): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = null,
chat_level = null,
disabled_until = until,
remove_disable = null,
val input = PushPreferenceInput(
channelCid = null,
chatLevel = null,
disabledUntil = until,
removeDisable = null,
)
val request = UpsertPushPreferencesRequest(listOf(input))
return pushPreferencesApi
Expand All @@ -521,11 +522,11 @@ constructor(
}

override fun setChannelPushPreference(cid: String, level: PushPreferenceLevel): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = cid,
chat_level = level.value,
disabled_until = null,
remove_disable = true,
val input = PushPreferenceInput(
channelCid = cid,
chatLevel = PushPreferenceInput.ChatLevel.fromString(level.value),
disabledUntil = null,
removeDisable = true,
)
val request = UpsertPushPreferencesRequest(listOf(input))
return pushPreferencesApi
Expand All @@ -534,11 +535,11 @@ constructor(
}

override fun snoozeChannelPushNotifications(cid: String, until: Date): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = cid,
chat_level = null,
disabled_until = until,
remove_disable = null,
val input = PushPreferenceInput(
channelCid = cid,
chatLevel = null,
disabledUntil = until,
removeDisable = null,
)
val request = UpsertPushPreferencesRequest(listOf(input))
return pushPreferencesApi
Expand All @@ -547,25 +548,25 @@ constructor(
}

override fun setUserChatPreferences(preferences: ChatPreferences): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = null,
chat_level = null,
disabled_until = null,
remove_disable = null,
chat_preferences = with(dtoMapping) { preferences.toDto() },
val input = PushPreferenceInput(
channelCid = null,
chatLevel = null,
disabledUntil = null,
removeDisable = null,
chatPreferences = with(dtoMapping) { preferences.toChatPreferencesInput() },
)
return pushPreferencesApi
.upsertPushPreferences(UpsertPushPreferencesRequest(listOf(input)))
.parseUserPushPreferencesResponse()
}

override fun setChannelChatPreferences(cid: String, preferences: ChatPreferences): Call<PushPreference> {
val input = UpstreamPushPreferenceInputDto(
channel_cid = cid,
chat_level = null,
disabled_until = null,
remove_disable = null,
chat_preferences = with(dtoMapping) { preferences.toDto() },
val input = PushPreferenceInput(
channelCid = cid,
chatLevel = null,
disabledUntil = null,
removeDisable = null,
chatPreferences = with(dtoMapping) { preferences.toChatPreferencesInput() },
)
return pushPreferencesApi
.upsertPushPreferences(UpsertPushPreferencesRequest(listOf(input)))
Expand Down Expand Up @@ -1645,14 +1646,14 @@ constructor(
members: List<Member>,
): Call<List<Member>> {
val request = with(dtoMapping) {
io.getstream.chat.android.client.api2.model.requests.QueryMembersRequest(
QueryMembersPayload(
type = channelType,
id = channelId,
filter_conditions = filter.toMap(),
filterConditions = filter.toMap(),
offset = offset,
limit = limit,
sort = sort.toDto(),
members = members.map { it.toDto() },
sort = sort.toSortParams(),
members = members.map { it.toChannelMemberRequest() },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package io.getstream.chat.android.client.api2.endpoint
import io.getstream.chat.android.client.api.AuthenticatedApi
import io.getstream.chat.android.client.api.QueryParams
import io.getstream.chat.android.client.api2.UrlQueryPayload
import io.getstream.chat.android.client.api2.model.requests.QueryMembersRequest
import io.getstream.chat.android.client.api2.model.requests.SyncHistoryRequest
import io.getstream.chat.android.client.api2.model.response.SearchMessagesResponse
import io.getstream.chat.android.client.api2.model.response.SyncHistoryResponse
import io.getstream.chat.android.client.call.RetrofitCall
import io.getstream.chat.android.network.models.MembersResponse
import io.getstream.chat.android.network.models.QueryMembersPayload
import io.getstream.chat.android.network.models.SearchPayload
import io.getstream.chat.android.network.models.WrappedUnreadCountsResponse
import okhttp3.ResponseBody
Expand Down Expand Up @@ -52,7 +52,7 @@ internal interface GeneralApi {

@GET("/members")
fun queryMembers(
@UrlQueryPayload @Query("payload") payload: QueryMembersRequest,
@UrlQueryPayload @Query("payload") payload: QueryMembersPayload,
): RetrofitCall<MembersResponse>

@GET("/unread")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.getstream.chat.android.client.api2.endpoint

import io.getstream.chat.android.client.api.AuthenticatedApi
import io.getstream.chat.android.client.api2.model.requests.UpsertPushPreferencesRequest
import io.getstream.chat.android.client.call.RetrofitCall
import io.getstream.chat.android.network.models.UpsertPushPreferencesRequest
import io.getstream.chat.android.network.models.UpsertPushPreferencesResponse
import retrofit2.http.Body
import retrofit2.http.POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import io.getstream.chat.android.client.api2.model.dto.DeviceDto
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.UpstreamChatPreferencesDto
import io.getstream.chat.android.client.api2.model.dto.UpstreamConnectedEventDto
import io.getstream.chat.android.client.api2.model.dto.UpstreamLocationDto
import io.getstream.chat.android.client.api2.model.dto.UpstreamMemberDataDto
Expand All @@ -51,6 +50,7 @@ import io.getstream.chat.android.models.User
import io.getstream.chat.android.models.UserGroup
import io.getstream.chat.android.models.UserTransformer
import io.getstream.chat.android.network.models.ChannelMemberRequest
import io.getstream.chat.android.network.models.ChatPreferencesInput
import io.getstream.chat.android.network.models.DeliveryReceiptsResponse
import io.getstream.chat.android.network.models.MessageRequest
import io.getstream.chat.android.network.models.PrivacySettingsResponse
Expand Down Expand Up @@ -216,6 +216,20 @@ internal class DtoMapping(
custom = extraData,
)

/**
* Maps the domain [Member] to the generated network [ChannelMemberRequest] model.
*
* The query endpoint hashes the user ids to resolve a distinct channel and reads nothing else, but the role
* and custom data are carried anyway since the domain member has them. `user` stays absent: the outgoing
* model embeds a read-only [io.getstream.chat.android.network.models.UserResponse].
*/
internal fun Member.toChannelMemberRequest(): ChannelMemberRequest = ChannelMemberRequest(
userId = getUserId(),
channelRole = channelRole,
user = null,
custom = extraData,
)

/**
* Maps the domain [Location] to the generated network [SharedLocation] model.
*/
Expand Down Expand Up @@ -394,13 +408,13 @@ internal class DtoMapping(
connection_id = connectionId,
)

internal fun ChatPreferences.toDto(): UpstreamChatPreferencesDto = UpstreamChatPreferencesDto(
direct_mentions = directMentions?.value,
role_mentions = roleMentions?.value,
group_mentions = groupMentions?.value,
here_mentions = hereMentions?.value,
channel_mentions = channelMentions?.value,
thread_replies = threadReplies?.value,
default_preference = defaultPreference?.value,
internal fun ChatPreferences.toChatPreferencesInput(): ChatPreferencesInput = ChatPreferencesInput(
directMentions = directMentions?.value?.let(ChatPreferencesInput.DirectMentions::fromString),
roleMentions = roleMentions?.value?.let(ChatPreferencesInput.RoleMentions::fromString),
groupMentions = groupMentions?.value?.let(ChatPreferencesInput.GroupMentions::fromString),
hereMentions = hereMentions?.value?.let(ChatPreferencesInput.HereMentions::fromString),
channelMentions = channelMentions?.value?.let(ChatPreferencesInput.ChannelMentions::fromString),
threadReplies = threadReplies?.value?.let(ChatPreferencesInput.ThreadReplies::fromString),
defaultPreference = defaultPreference?.value?.let(ChatPreferencesInput.DefaultPreference::fromString),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ package io.getstream.chat.android.client.api2.model.dto
import com.squareup.moshi.JsonClass
import java.util.Date

/**
* Upstream DTO for setting push notification preferences.
*
* @param channel_cid The channel ID (e.g., "messaging:123").
* @param chat_level The chat level preference ("all", "default", "mentions" or "none").
* @param disabled_until Timestamp until which notifications are disabled.
* @param remove_disable Whether to remove any existing disable setting.
* @param chat_preferences Per-category toggles. Setting this clears [chat_level] server-side.
*/
@JsonClass(generateAdapter = true)
internal data class UpstreamPushPreferenceInputDto(
val channel_cid: String?,
val chat_level: String?,
val disabled_until: Date?,
val remove_disable: Boolean?,
val chat_preferences: UpstreamChatPreferencesDto? = null,
)

/**
* Downstream DTO for receiving push notification preferences.
*
Expand All @@ -51,17 +33,6 @@ internal data class DownstreamPushPreferenceDto(
val chat_preferences: DownstreamChatPreferencesDto? = null,
)

@JsonClass(generateAdapter = true)
internal data class UpstreamChatPreferencesDto(
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,
)

@JsonClass(generateAdapter = true)
internal data class DownstreamChatPreferencesDto(
val direct_mentions: String? = null,
Expand Down

This file was deleted.

Loading
Loading