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

fix: newly created 1:1 with bots are not displayed #2895

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,8 @@ class UserSessionScope internal constructor(
conversationRepository = conversationRepository,
userRepository = userRepository,
persistMessage = persistMessage,
legalHoldHandler = legalHoldHandler
legalHoldHandler = legalHoldHandler,
selfUserId = userId
)
private val memberLeaveHandler: MemberLeaveEventHandler
get() = MemberLeaveEventHandlerImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.event.Event
import com.wire.kalium.logic.data.event.EventLoggingStatus
import com.wire.kalium.logic.data.event.logEventProcessing
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.message.PersistMessageUseCase
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.onFailure
Expand All @@ -50,11 +53,13 @@ internal class MemberJoinEventHandlerImpl(

override suspend fun handle(event: Event.Conversation.MemberJoin): Either<CoreFailure, Unit> {
val eventLogger = logger.createEventProcessingLogger(event)
// the group info need to be fetched for the following cases:
// 1. self user is added/re-added to a group and we need to update the group info in case something changed form last time
// 2. the new member is a bot in that case we need to make the group a bot 1:1
// 3. fetch group info in case it is not stored in the first place
return conversationRepository.fetchConversation(event.conversationId)
// we need to force fetching conversation when self user rejoined to conversation,
// because he may not received member change events
if (event.members.map { it.id }.contains(selfUserId)) {
conversationRepository.fetchConversation(event.conversationId)
} else {
conversationRepository.fetchConversationIfUnknown(event.conversationId)
}
.run {
onSuccess {
val logMap = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,29 @@ import kotlin.test.Test

class MemberJoinEventHandlerTest {

@Test
fun givenMemberJoinEventWithoutSelfUser_whenHandlingIt_thenShouldFetchConversationIfUnknown() = runTest {
val newMembers = listOf(Member(TestUser.OTHER_FEDERATED_USER_ID, Member.Role.Member))
val event = TestEvent.memberJoin(members = newMembers)

val (arrangement, eventHandler) = Arrangement()
.withPersistingMessageReturning(Either.Right(Unit))
.withFetchConversationIfUnknownSucceeding()
.withPersistMembersSucceeding()
.withFetchUsersIfUnknownByIdsReturning(Either.Right(Unit))
.arrange()

eventHandler.handle(event)

coVerify {
arrangement.conversationRepository.fetchConversationIfUnknown(eq(event.conversationId))
}.wasInvoked(exactly = once)

coVerify {
arrangement.conversationRepository.fetchConversation(eq(event.conversationId))
}.wasNotInvoked()
}

@Test
fun givenMemberJoinEventWithSelfUser_whenHandlingIt_thenShouldFetchConversation() = runTest {
val newMembers = listOf(Member(TestUser.SELF.id, Member.Role.Member))
Expand Down
Loading