Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBE-3749] Implement ChatClient::markThreadRead operation. #5447

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- Avoid multiple `ChatClient::connectUser` invocations by sharing the `Call`. [#5439](https://github.com/GetStream/stream-chat-android/pull/5439)

### ✅ Added
- Add `ChatClient::markThreadRead` to mark a given thread as read. [#5447](https://github.com/GetStream/stream-chat-android/pull/5447)
- Add `ChannelClient::markThreadRead` to mark a given thread as read. [#5447](https://github.com/GetStream/stream-chat-android/pull/5447)

### ⚠️ Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public final class io/getstream/chat/android/client/ChatClient {
public final fun markAllRead ()Lio/getstream/result/call/Call;
public final fun markMessageRead (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun markRead (Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun markThreadRead (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun markUnread (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun muteChannel (Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun muteChannel (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)Lio/getstream/result/call/Call;
Expand Down Expand Up @@ -646,6 +647,7 @@ public final class io/getstream/chat/android/client/channel/ChannelClient {
public static synthetic fun keystroke$default (Lio/getstream/chat/android/client/channel/ChannelClient;Ljava/lang/String;ILjava/lang/Object;)Lio/getstream/result/call/Call;
public final fun markMessageRead (Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun markRead ()Lio/getstream/result/call/Call;
public final fun markThreadRead (Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun markUnread (Ljava/lang/String;)Lio/getstream/result/call/Call;
public final fun mute ()Lio/getstream/result/call/Call;
public final fun mute (Ljava/lang/Integer;)Lio/getstream/result/call/Call;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ internal constructor(
channelId: String,
messageId: String,
): Call<Unit> {
return api.markRead(channelType, channelId, messageId)
return api.markRead(channelType, channelId, messageId = messageId)
.doOnStart(userScope) {
logger.d { "[markMessageRead] #doOnStart; cid: $channelType:$channelId, msgId: $messageId" }
}
Expand All @@ -2196,6 +2196,22 @@ internal constructor(
}
}

/**
* Marks a given thread as read.
*
* @param channelType The type of the channel in which the thread resides.
* @param channelId The ID of the channel in which the thread resides.
* @param threadId The ID of the thread to mark as read.
*/
@CheckResult
public fun markThreadRead(
channelType: String,
channelId: String,
threadId: String,
): Call<Unit> {
return api.markRead(channelType, channelId, threadId = threadId)
}

@CheckResult
public fun showChannel(channelType: String, channelId: String): Call<Unit> {
return api.showChannel(channelType, channelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ internal interface ChatApi {
channelType: String,
channelId: String,
messageId: String = "",
threadId: String = "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this method accept empty messageId to mark the full channel as read, in another case mark the channel read until the messageId.

Now that it contains an extra argument (threadId) it is a bit confusing what it will does if, for example, we pass a messageId and a threadId...

It would be better to have a new markThreadRead() and then extract common logic on the MoshiChatApi to reuse whatever is needed

): Call<Unit>

@CheckResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,14 @@ constructor(
).map(this::flattenChannel)
}

override fun markRead(channelType: String, channelId: String, messageId: String): Call<Unit> {
override fun markRead(channelType: String, channelId: String, messageId: String, threadId: String): Call<Unit> {
return channelApi.markRead(
channelType = channelType,
channelId = channelId,
request = MarkReadRequest(messageId),
request = MarkReadRequest(
message_id = messageId,
thread_id = threadId,
),
).toUnitCall()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
internal data class MarkReadRequest(
val message_id: String,
val thread_id: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ public class ChannelClient internal constructor(
return client.markMessageRead(channelType, channelId, messageId)
}

/**
* Marks a given thread in the channel as read.
*
* @param threadId The ID of the thread to mark as read.
*/
@CheckResult
public fun markThreadRead(threadId: String): Call<Unit> {
return client.markThreadRead(channelType, channelId, threadId)
}

@CheckResult
public fun markUnread(messageId: String): Call<Unit> {
return client.markUnread(channelType, channelId, messageId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class WhenMarkReadChannel : BaseChatClientTest() {
private inner class Fixture {

init {
whenever(api.markRead(any(), any(), any())) doReturn mock<Unit>().asCall()
whenever(api.markRead(any(), any(), any(), any())) doReturn mock<Unit>().asCall()
}

fun givenPlugin(plugin: Plugin) = apply {
Expand Down
Loading