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 @@ -1698,12 +1698,16 @@ constructor(
prev = query.prev,
replyLimit = query.replyLimit,
),
).mapDomain { response ->
QueryThreadsResult(
threads = response.threads.map { it.toDomain() },
prev = response.prev,
next = response.next,
)
).flatMapDomain { response ->
val threads = response.threads.mapNotNull { it.toDomain() }
if (threads.size == response.threads.size) {
CoroutineCall(coroutineScope) {
val result = QueryThreadsResult(threads = threads, prev = response.prev, next = response.next)
Result.Success(result)
}
} else {
ErrorCall(coroutineScope, Error.GenericError(MISSING_THREAD_FIELDS))
}
}
}
return if (connectionId.isBlank() && query.watch) {
Expand All @@ -1726,8 +1730,10 @@ constructor(
messageId,
connectionId,
options.toMap(),
).mapDomain { response ->
).flatMapDomain { response ->
response.thread.toDomain()
?.let { thread -> CoroutineCall(coroutineScope) { Result.Success(thread) } }
?: ErrorCall(coroutineScope, Error.GenericError(MISSING_THREAD_FIELDS))
}
}
return if (connectionId.isBlank() && options.watch) {
Expand Down Expand Up @@ -2069,3 +2075,6 @@ internal fun QuerySorter<*>.toSortParams(): List<SortParamRequest> =
type = it[QuerySorter.KEY_TYPE] as? String,
)
}

// A thread always has a parent message and a last message date, so a thread missing either cannot be mapped.
private const val MISSING_THREAD_FIELDS = "A thread in the response carried no parent message or last message date"
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,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.model.response.QueryThreadsResponse
import io.getstream.chat.android.client.api2.model.response.ThreadInfoResponse
import io.getstream.chat.android.client.api2.model.response.ThreadResponse
import io.getstream.chat.android.client.call.RetrofitCall
import io.getstream.chat.android.network.models.GetThreadResponse
import io.getstream.chat.android.network.models.QueryThreadsRequest
import io.getstream.chat.android.network.models.QueryThreadsResponse
import io.getstream.chat.android.network.models.UpdateThreadPartialRequest
import io.getstream.chat.android.network.models.UpdateThreadPartialResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PATCH
Expand Down Expand Up @@ -52,7 +52,7 @@ internal interface ThreadsApi {
@Path("message_id") messageId: String,
@Query(QueryParams.CONNECTION_ID) connectionId: String,
@QueryMap options: Map<String, String>,
): RetrofitCall<ThreadResponse>
): RetrofitCall<GetThreadResponse>

/**
* [REST documentation](https://getstream.github.io/protocol/#/product%3Achat/UpdateThreadPartial)
Expand All @@ -61,5 +61,5 @@ internal interface ThreadsApi {
fun partialUpdateThread(
@Path("message_id") messageId: String,
@Body body: UpdateThreadPartialRequest,
): RetrofitCall<ThreadInfoResponse>
): RetrofitCall<UpdateThreadPartialResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import io.getstream.chat.android.client.api2.model.dto.DownstreamModerationDetai
import io.getstream.chat.android.client.api2.model.dto.DownstreamPendingMessageDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamReminderInfoDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamThreadDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamThreadInfoDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserDto
import io.getstream.chat.android.client.extensions.enrichWithCid
import io.getstream.chat.android.client.extensions.internal.sortedByLastReply
Expand Down Expand Up @@ -132,6 +130,8 @@ import io.getstream.chat.android.network.models.ReminderResponseData
import io.getstream.chat.android.network.models.SharedLocationResponse
import io.getstream.chat.android.network.models.SharedLocationResponseData
import io.getstream.chat.android.network.models.SortParamRequest
import io.getstream.chat.android.network.models.ThreadResponse
import io.getstream.chat.android.network.models.ThreadStateResponse
import io.getstream.chat.android.network.models.UnreadCountsChannel
import io.getstream.chat.android.network.models.UnreadCountsChannelType
import io.getstream.chat.android.network.models.UnreadCountsThread
Expand Down Expand Up @@ -1159,55 +1159,56 @@ internal class DomainMapping(
)

/**
* Transforms [DownstreamThreadDto] into [Thread]
* Transforms [ThreadStateResponse] into [Thread], or null when it lacks the parent message or the last
* message date the domain thread requires.
*/
internal fun DownstreamThreadDto.toDomain(): Thread =
Thread(
activeParticipantCount = active_participant_count ?: 0,
cid = channel_cid,
internal fun ThreadStateResponse.toDomain(): Thread? {
val parent = parentMessage ?: return null
val lastMessage = lastMessageAt ?: return null
val channelInfo = channel?.toChannelInfo()
return Thread(
activeParticipantCount = activeParticipantCount,
cid = channelCid,
channel = channel?.toDomain(),
parentMessageId = parent_message_id,
parentMessage = parent_message.toDomain(channel?.toChannelInfo()),
createdByUserId = created_by_user_id,
createdBy = created_by?.toDomain(),
participantCount = participant_count,
threadParticipants = thread_participants.orEmpty().map { it.toDomain() }.sortedByLastReply(),
lastMessageAt = last_message_at,
createdAt = created_at,
updatedAt = updated_at,
deletedAt = deleted_at,
parentMessageId = parentMessageId,
parentMessage = parent.toDomain(channelInfo),
createdByUserId = createdByUserId,
createdBy = createdBy?.toDomain(),
participantCount = participantCount,
threadParticipants = threadParticipants.orEmpty().map { it.toDomain() }.sortedByLastReply(),
lastMessageAt = lastMessage,
createdAt = createdAt,
updatedAt = updatedAt,
deletedAt = deletedAt,
title = title,
latestReplies = latest_replies.map { it.toDomain(channel?.toChannelInfo()) },
read = read.orEmpty().map {
it.toDomain(
lastReceivedEventDate = last_message_at,
)
},
draft = draft?.toDomain(channel?.toChannelInfo()),
extraData = extraData,
latestReplies = latestReplies.map { it.toDomain(channelInfo) },
read = read.orEmpty().map { it.toDomain(lastReceivedEventDate = lastMessage) },
draft = draft?.toDomain(channelInfo),
extraData = custom.mapNotNull { (key, value) -> value?.let { key to it } }.toMap(),
)
}

/**
* Transforms [DownstreamThreadInfoDto] into [ThreadInfo]
* Transforms [ThreadResponse] into [ThreadInfo]
*/
internal fun DownstreamThreadInfoDto.toDomain(): ThreadInfo =
internal fun ThreadResponse.toDomain(): ThreadInfo =
ThreadInfo(
activeParticipantCount = active_participant_count ?: 0,
cid = channel_cid,
createdAt = created_at,
createdBy = created_by?.toDomain(),
createdByUserId = created_by_user_id,
deletedAt = deleted_at,
lastMessageAt = last_message_at,
parentMessage = parent_message?.toDomain(channel?.toChannelInfo()),
parentMessageId = parent_message_id,
participantCount = participant_count ?: 0,
replyCount = reply_count ?: 0,
activeParticipantCount = activeParticipantCount,
cid = channelCid,
createdAt = createdAt,
createdBy = createdBy?.toDomain(),
createdByUserId = createdByUserId,
deletedAt = deletedAt,
lastMessageAt = lastMessageAt,
parentMessage = parentMessage?.toDomain(channel?.toChannelInfo()),
parentMessageId = parentMessageId,
participantCount = participantCount,
replyCount = replyCount,
title = title,
updatedAt = updated_at,
updatedAt = updatedAt,
channel = channel?.toDomain(),
threadParticipants = thread_participants.orEmpty().map { it.toDomain() }.sortedByLastReply(),
extraData = extraData,
threadParticipants = threadParticipants.orEmpty().map { it.toDomain() }.sortedByLastReply(),
extraData = custom.mapNotNull { (key, value) -> value?.let { key to it } }.toMap(),
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.getstream.chat.android.network.models.ChannelMemberResponse
import io.getstream.chat.android.network.models.DraftResponse
import io.getstream.chat.android.network.models.OwnUserResponse
import io.getstream.chat.android.network.models.ReactionResponse
import io.getstream.chat.android.network.models.ThreadResponse
import io.getstream.chat.android.network.models.UserResponseCommonFields
import io.getstream.chat.android.network.models.UserResponsePrivacyFields
import io.getstream.chat.android.network.models.WSEvent
Expand Down Expand Up @@ -174,7 +175,7 @@ internal data class MessageReadEventDto(
val cid: String,
val channel_type: String,
val channel_id: String,
val thread: DownstreamThreadInfoDto? = null,
val thread: ThreadResponse? = null,
val last_read_message_id: String?,
val team: String? = null,
) : ChatEventDto()
Expand Down Expand Up @@ -314,7 +315,7 @@ internal data class NotificationMarkReadEventDto(
val total_unread_count: Int = 0,
val unread_channels: Int = 0,
val thread_id: String? = null,
val thread: DownstreamThreadInfoDto? = null,
val thread: ThreadResponse? = null,
val unread_threads: Int? = null,
val unread_thread_messages: Int? = null,
val last_read_message_id: String?,
Expand Down Expand Up @@ -371,7 +372,7 @@ internal data class ThreadUpdatedEventDto(
val cid: String,
val channel_type: String,
val channel_id: String,
val thread: DownstreamThreadInfoDto,
val thread: ThreadResponse,
) : ChatEventDto()

@JsonClass(generateAdapter = true)
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading