Skip to content

Commit

Permalink
Expose method 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 0108c5a commit 05e2f79
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stream-chat-android-client/api/stream-chat-android-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public final class io/getstream/chat/android/client/ChatClient {
public final fun getMessage (Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun getMessagesWithAttachments (Ljava/lang/String;Ljava/lang/String;IILjava/util/List;)Lio/getstream/result/call/Call;
public static final fun getOFFLINE_SUPPORT_ENABLED ()Z
public final fun getOlderReplies (Ljava/lang/String;ILjava/lang/String;)Lio/getstream/result/call/Call;
public static synthetic fun getOlderReplies$default (Lio/getstream/chat/android/client/ChatClient;Ljava/lang/String;ILjava/lang/String;ILjava/lang/Object;)Lio/getstream/result/call/Call;
public final fun getPinnedMessages (Ljava/lang/String;Ljava/lang/String;ILio/getstream/chat/android/models/querysort/QuerySorter;Lio/getstream/chat/android/client/api/models/PinnedMessagesPagination;)Lio/getstream/result/call/Call;
public final fun getReactions (Ljava/lang/String;II)Lio/getstream/result/call/Call;
public final fun getReplies (Ljava/lang/String;I)Lio/getstream/result/call/Call;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import io.getstream.chat.android.client.api.models.identifier.SendMessageIdentif
import io.getstream.chat.android.client.api.models.identifier.SendReactionIdentifier
import io.getstream.chat.android.client.api.models.identifier.ShuffleGiphyIdentifier
import io.getstream.chat.android.client.api.models.identifier.UpdateMessageIdentifier
import io.getstream.chat.android.client.api.models.identifier.getNewerRepliesIdentifier
import io.getstream.chat.android.client.api2.model.dto.AttachmentDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamChannelDto
import io.getstream.chat.android.client.api2.model.dto.DownstreamMessageDto
Expand Down Expand Up @@ -1549,6 +1550,28 @@ internal constructor(
.share(userScope) { GetRepliesIdentifier(messageId, limit) }
}

/**
* Fetch replies to the specified message with id [parentId] that are newer than the message with [lastId].
* If [lastId] is null, the oldest replies are returned.
*
* @param parentId The id of the parent message.
* @param limit The number of replies to fetch.
* @param lastId The id of the last message to fetch.
*
* @return Executable async [Call] responsible for fetching newer replies.
*/
@CheckResult
public fun getNewerReplies(
parentId: String,
limit: Int,
lastId: String? = null,
): Call<List<Message>> {
logger.d { "[getNewerReplies] parentId: $parentId, limit: $limit, lastId: $lastId" }

return api.getNewerReplies(parentId, limit, lastId)
.share(userScope) { getNewerRepliesIdentifier(parentId, limit, lastId) }
}

@CheckResult
public fun getRepliesMore(
messageId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ internal fun GetRepliesIdentifier(
return result
}

/**
* Identifier for a [ChatClient.getNewerReplies] call.
*/
@Suppress("FunctionName", "MagicNumber")
internal fun getNewerRepliesIdentifier(
parentId: String,
limit: Int,
lastId: String? = null,
): Int {
var result = "GetOlderReplies".hashCode()
result = 31 * result + parentId.hashCode()
result = 31 * result + limit.hashCode()
result = 31 * result + (lastId?.hashCode() ?: 0)
return result
}

/**
* Identifier for a [ChatClient.getRepliesMore] call.
*/
Expand Down

0 comments on commit 05e2f79

Please sign in to comment.