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 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
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 @@ -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.markThreadRead(channelType, channelId, 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 @@ -275,6 +275,13 @@ internal interface ChatApi {
messageId: String = "",
): Call<Unit>

@CheckResult
fun markThreadRead(
channelType: String,
channelId: String,
threadId: String,
): Call<Unit>

@CheckResult
fun markUnread(
channelType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,15 @@ constructor(
return channelApi.markRead(
channelType = channelType,
channelId = channelId,
request = MarkReadRequest(messageId),
request = MarkReadRequest(message_id = messageId),
).toUnitCall()
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
internal data class MarkReadRequest(
val message_id: String,
val message_id: String = "",
val thread_id: String? = null,
)
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
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2014-2024 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.chatclient

import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.test.TestCall
import io.getstream.chat.android.test.callFrom
import io.getstream.result.Error
import io.getstream.result.Result
import io.getstream.result.call.Call
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeInstanceOf
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.whenever

internal class WhenMarkReadThread : BaseChatClientTest() {

@Test
fun `Given markRead api call successful ChatClient should return success result`() = runTest {
val apiResult = callFrom { }
val sut = Fixture().givenMarkReadApiResult(apiResult).get()

val result = sut.markThreadRead("channelType", "channelId", "threadId").await()

result shouldBeInstanceOf Result.Success::class
}

@Test
fun `Given markRead api call fails ChatClient should return error result`() = runTest {
val apiResult = TestCall<Unit>(Result.Failure(Error.GenericError("Error")))
val sut = Fixture().givenMarkReadApiResult(apiResult).get()

val result = sut.markThreadRead("channelType", "channelId", "threadId").await()

result shouldBeInstanceOf Result.Failure::class
}

private inner class Fixture {

fun givenMarkReadApiResult(result: Call<Unit>) = apply {
whenever(api.markThreadRead(any(), any(), any())) doReturn result
}

fun get(): ChatClient = chatClient
}
}
Loading