Skip to content

Commit

Permalink
Revert "fix: always update group info when a new member joins [WPB-44…
Browse files Browse the repository at this point in the history
…64] (#2710)"

This reverts commit a0bb7fa
  • Loading branch information
MohamadJaara committed Jul 23, 2024
1 parent af5cba8 commit 714007b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
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

0 comments on commit 714007b

Please sign in to comment.