Skip to content

Commit

Permalink
Refactor ThreadParticipants
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Nov 20, 2024
1 parent 9314706 commit c111fbc
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@ internal fun DownstreamThreadInfoDto.toDomain(currentUserId: UserId?): ThreadInf
)

internal fun DownstreamThreadParticipantDto.toDomain(currentUserId: UserId?): ThreadParticipant = ThreadParticipant(
user = user?.toDomain(currentUserId),
userId = user_id,
user = user.toDomain(currentUserId),
)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ internal data class DownstreamThreadInfoDto(
val parent_message_id: String,
val participant_count: Int?,
val reply_count: Int?,
val thread_participants: List<DownstreamThreadParticipantDto>?,
val title: String,
val updated_at: Date,
)
Expand All @@ -110,6 +109,6 @@ internal data class DownstreamThreadInfoDto(
@JsonClass(generateAdapter = true)
internal data class DownstreamThreadParticipantDto(
val channel_cid: String,
val user: DownstreamUserDto?,
val user: DownstreamUserDto,
val user_id: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ private fun ThreadItemPreview() {
replyCount = 3,
participantCount = 2,
threadParticipants = listOf(
ThreadParticipant(user1, user1.id),
ThreadParticipant(user2, user2.id),
ThreadParticipant(user1),
ThreadParticipant(user2),
),
lastMessageAt = Date(),
createdAt = Date(),
Expand Down
25 changes: 11 additions & 14 deletions stream-chat-android-core/api/stream-chat-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1732,13 +1732,12 @@ public final class io/getstream/chat/android/models/Thread {
}

public final class io/getstream/chat/android/models/ThreadInfo {
public fun <init> (ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/util/List;Ljava/lang/String;Ljava/util/Date;)V
public fun <init> (ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/lang/String;Ljava/util/Date;)V
public final fun component1 ()I
public final fun component10 ()I
public final fun component11 ()I
public final fun component12 ()Ljava/util/List;
public final fun component13 ()Ljava/lang/String;
public final fun component14 ()Ljava/util/Date;
public final fun component12 ()Ljava/lang/String;
public final fun component13 ()Ljava/util/Date;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/util/Date;
public final fun component4 ()Lio/getstream/chat/android/models/User;
Expand All @@ -1747,8 +1746,8 @@ public final class io/getstream/chat/android/models/ThreadInfo {
public final fun component7 ()Ljava/util/Date;
public final fun component8 ()Lio/getstream/chat/android/models/Message;
public final fun component9 ()Ljava/lang/String;
public final fun copy (ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/util/List;Ljava/lang/String;Ljava/util/Date;)Lio/getstream/chat/android/models/ThreadInfo;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/ThreadInfo;ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/util/List;Ljava/lang/String;Ljava/util/Date;ILjava/lang/Object;)Lio/getstream/chat/android/models/ThreadInfo;
public final fun copy (ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/lang/String;Ljava/util/Date;)Lio/getstream/chat/android/models/ThreadInfo;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/ThreadInfo;ILjava/lang/String;Ljava/util/Date;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/Date;Ljava/util/Date;Lio/getstream/chat/android/models/Message;Ljava/lang/String;IILjava/lang/String;Ljava/util/Date;ILjava/lang/Object;)Lio/getstream/chat/android/models/ThreadInfo;
public fun equals (Ljava/lang/Object;)Z
public final fun getActiveParticipantCount ()I
public final fun getCid ()Ljava/lang/String;
Expand All @@ -1761,22 +1760,20 @@ public final class io/getstream/chat/android/models/ThreadInfo {
public final fun getParentMessageId ()Ljava/lang/String;
public final fun getParticipantCount ()I
public final fun getReplyCount ()I
public final fun getThreadParticipants ()Ljava/util/List;
public final fun getTitle ()Ljava/lang/String;
public final fun getUpdatedAt ()Ljava/util/Date;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/getstream/chat/android/models/ThreadParticipant {
public fun <init> (Lio/getstream/chat/android/models/User;Ljava/lang/String;)V
public final class io/getstream/chat/android/models/ThreadParticipant : io/getstream/chat/android/models/UserEntity {
public fun <init> (Lio/getstream/chat/android/models/User;)V
public final fun component1 ()Lio/getstream/chat/android/models/User;
public final fun component2 ()Ljava/lang/String;
public final fun copy (Lio/getstream/chat/android/models/User;Ljava/lang/String;)Lio/getstream/chat/android/models/ThreadParticipant;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/ThreadParticipant;Lio/getstream/chat/android/models/User;Ljava/lang/String;ILjava/lang/Object;)Lio/getstream/chat/android/models/ThreadParticipant;
public final fun copy (Lio/getstream/chat/android/models/User;)Lio/getstream/chat/android/models/ThreadParticipant;
public static synthetic fun copy$default (Lio/getstream/chat/android/models/ThreadParticipant;Lio/getstream/chat/android/models/User;ILjava/lang/Object;)Lio/getstream/chat/android/models/ThreadParticipant;
public fun equals (Ljava/lang/Object;)Z
public final fun getUser ()Lio/getstream/chat/android/models/User;
public final fun getUserId ()Ljava/lang/String;
public fun getUser ()Lio/getstream/chat/android/models/User;
public fun getUserId ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import androidx.compose.runtime.Immutable
* Model holding info about a thread participant.
*
* @param user The [User] as a thread participant (not always delivered).
* @param userId The Id of the thread participant.
*/
@Immutable
public data class ThreadParticipant(
val user: User?,
val userId: String,
)
override val user: User,
) : UserEntity
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ internal class QueryThreadsStateLogic(private val mutableState: QueryThreadsMuta
// The new message could be from a new thread participant
val threadParticipants = if (isInsert) {
upsertThreadParticipantInList(
newParticipant = ThreadParticipant(user = reply.user, userId = reply.user.id),
newParticipant = ThreadParticipant(user = reply.user),
participants = thread.threadParticipants,
)
} else {
Expand Down Expand Up @@ -295,12 +295,12 @@ internal class QueryThreadsStateLogic(private val mutableState: QueryThreadsMuta
participants: List<ThreadParticipant>,
): List<ThreadParticipant> {
// Insert
if (participants.none { it.userId == newParticipant.userId }) {
if (participants.none { it.getUserId() == newParticipant.getUserId() }) {
return participants + listOf(newParticipant)
}
// Update
return participants.map { participant ->
if (participant.userId == newParticipant.userId) {
if (participant.getUserId() == newParticipant.getUserId()) {
newParticipant
} else {
participant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ internal class QueryThreadsLogicTest {
replyCount = 1,
participantCount = 2,
threadParticipants = listOf(
ThreadParticipant(User(id = "usrId1"), "usrId1"),
ThreadParticipant(User(id = "usrId2"), "usrId2"),
ThreadParticipant(User(id = "usrId1")),
ThreadParticipant(User(id = "usrId2")),
),
lastMessageAt = Date(),
createdAt = Date(),
Expand Down Expand Up @@ -371,7 +371,6 @@ internal class QueryThreadsLogicTest {
parentMessageId = "mId1",
participantCount = 2,
replyCount = 2,
threadParticipants = emptyList(),
title = "Thread 1",
updatedAt = Date(),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ internal class QueryThreadsStateLogicTest {
replyCount = 1,
participantCount = 2,
threadParticipants = listOf(
ThreadParticipant(User(id = "usrId1"), "usrId1"),
ThreadParticipant(User(id = "usrId2"), "usrId2"),
ThreadParticipant(User(id = "usrId1")),
ThreadParticipant(User(id = "usrId2")),
),
lastMessageAt = Date(),
createdAt = Date(),
Expand Down Expand Up @@ -416,7 +416,7 @@ internal class QueryThreadsStateLogicTest {
latestReplies = threadList[0].latestReplies + listOf(reply),
replyCount = 2,
participantCount = 3,
threadParticipants = threadList[0].threadParticipants + listOf(ThreadParticipant(User("usrId3"), "usrId3")),
threadParticipants = threadList[0].threadParticipants + listOf(ThreadParticipant(User("usrId3"))),
read = threadList[0].read.map { read ->
read.copy(unreadMessages = read.unreadMessages + 1)
},
Expand Down Expand Up @@ -476,7 +476,6 @@ internal class QueryThreadsStateLogicTest {
parentMessageId = "mId13", // not a loaded thread
participantCount = 2,
replyCount = 2,
threadParticipants = emptyList(),
title = "Unknown thread",
updatedAt = Date(),
),
Expand Down Expand Up @@ -506,10 +505,6 @@ internal class QueryThreadsStateLogicTest {
parentMessageId = "mId1", // loaded thread
participantCount = 2,
replyCount = 1,
threadParticipants = listOf(
ThreadParticipant(User(id = "usrId1"), "usrId1"),
ThreadParticipant(User(id = "usrId2"), "usrId2"),
),
title = "Thread 1",
updatedAt = Date(),
)
Expand All @@ -524,7 +519,6 @@ internal class QueryThreadsStateLogicTest {
parentMessage = threadInfo.parentMessage ?: threadList[0].parentMessage,
participantCount = threadInfo.participantCount,
replyCount = threadInfo.replyCount,
threadParticipants = threadInfo.threadParticipants,
title = threadInfo.title,
updatedAt = threadInfo.updatedAt,
read = threadList[0].read.map { read ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.cash.turbine.test
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.Thread
import io.getstream.chat.android.models.ThreadParticipant
import io.getstream.chat.android.models.User
import io.getstream.chat.android.test.TestCoroutineRule
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.`should be equal to`
Expand All @@ -44,8 +45,8 @@ internal class QueryThreadsMutableStateTest {
replyCount = 1,
participantCount = 2,
threadParticipants = listOf(
ThreadParticipant(null, "usrId1"),
ThreadParticipant(null, "usrId1"),
ThreadParticipant(User("usrId1")),
ThreadParticipant(User("usrId2")),
),
lastMessageAt = Date(),
createdAt = Date(),
Expand All @@ -69,8 +70,8 @@ internal class QueryThreadsMutableStateTest {
replyCount = 1,
participantCount = 2,
threadParticipants = listOf(
ThreadParticipant(null, "usrId1"),
ThreadParticipant(null, "usrId1"),
ThreadParticipant(User("usrId1")),
ThreadParticipant(User("usrId2")),
),
lastMessageAt = Date(),
createdAt = Date(),
Expand Down

0 comments on commit c111fbc

Please sign in to comment.