Skip to content

Commit

Permalink
Create new endpoints to get older replies
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed May 8, 2024
1 parent fa62521 commit 0108c5a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ internal interface ChatApi {
@CheckResult
fun getReplies(messageId: String, limit: Int): Call<List<Message>>

@CheckResult
fun getNewerReplies(
parentId: String,
limit: Int,
lastId: String?,
): Call<List<Message>>

@CheckResult
fun getReactions(
messageId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.getstream.chat.android.client.api.models.PinnedMessagesPagination
import io.getstream.chat.android.client.api.models.QueryChannelRequest
import io.getstream.chat.android.client.api.models.QueryChannelsRequest
import io.getstream.chat.android.client.api2.optimisation.hash.ChannelQueryKey
import io.getstream.chat.android.client.api2.optimisation.hash.GetNewerRepliesHash
import io.getstream.chat.android.client.api2.optimisation.hash.GetPinnedMessagesHash
import io.getstream.chat.android.client.api2.optimisation.hash.GetReactionsHash
import io.getstream.chat.android.client.api2.optimisation.hash.GetRepliesHash
Expand Down Expand Up @@ -78,6 +79,16 @@ internal class DistinctChatApi(
}
}

override fun getNewerReplies(parentId: String, limit: Int, lastId: String?): Call<List<Message>> {
val uniqueKey = GetNewerRepliesHash(parentId, limit, lastId).hashCode()
StreamLog.d(TAG) {
"[getNewerReplies] parentId: $parentId, limit: $limit, lastId: $lastId, uniqueKey: $uniqueKey"
}
return getOrCreate(uniqueKey) {
delegate.getNewerReplies(parentId, limit, lastId)
}
}

override fun getReactions(messageId: String, offset: Int, limit: Int): Call<List<Reaction>> {
val uniqueKey = GetReactionsHash(messageId, offset, limit).hashCode()
StreamLog.d(TAG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ internal class DistinctChatApiEnabler(
return getApi().getReplies(messageId, limit)
}

override fun getNewerReplies(parentId: String, limit: Int, lastId: String?): Call<List<Message>> {
return getApi().getNewerReplies(parentId, limit, lastId)
}

override fun getReactions(messageId: String, offset: Int, limit: Int): Call<List<Reaction>> {
return getApi().getReactions(messageId, offset, limit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,16 @@ constructor(
}
}

override fun getNewerReplies(
parentId: String,
limit: Int,
lastId: String?,
): Call<List<Message>> = messageApi.getNewerReplies(
parentId = parentId,
limit = limit,
lastId = lastId,
).map { response -> response.messages.map(DownstreamMessageDto::toDomain) }

override fun getReplies(messageId: String, limit: Int): Call<List<Message>> {
return messageApi.getReplies(
messageId = messageId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ internal interface MessageApi {
@Query("limit") limit: Int,
): RetrofitCall<MessagesResponse>

@GET("/messages/{parent_id}/replies?sort=[{\"field\":\"created_at\",\"direction\":1}]")
fun getNewerReplies(
@Path("parent_id") parentId: String,
@Query("limit") limit: Int,
@Query("id_gt") lastId: String?,
): RetrofitCall<MessagesResponse>

@GET("/messages/{parent_id}/replies")
fun getRepliesMore(
@Path("parent_id") messageId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2014-2022 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.client.api2.optimisation.hash

internal data class GetNewerRepliesHash(
val parentId: String,
val limit: Int,
val lastId: String?,
)

0 comments on commit 0108c5a

Please sign in to comment.