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

feat: Delete group as admin [WPB-11559] #3115

Closed
wants to merge 1 commit into from
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 @@ -299,7 +299,7 @@ sealed class ConversationDetails(open val conversation: Conversation) {
override val conversation: Conversation,
val hasOngoingCall: Boolean = false,
val isSelfUserMember: Boolean,
val isSelfUserCreator: Boolean,
val selfUserTeamId: TeamId?,
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to add the user self team ID to the conversation model, since it is fixed and is not really conversation related, if you need it in the UI part to get whether a conversation can be deleted or not, please expose it as its own use case and use it in the UI

val selfRole: Conversation.Member.Role?
// val isTeamAdmin: Boolean, TODO kubaz
) : ConversationDetails(conversation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ interface ConversationMapper {
fun fromApiModel(mlsPublicKeysDTO: MLSPublicKeysDTO?): MLSPublicKeys?
fun fromDaoModel(daoModel: ConversationViewEntity): Conversation
fun fromDaoModel(daoModel: ConversationEntity): Conversation
fun fromDaoModelToDetails(daoModel: ConversationViewEntity): ConversationDetails
fun fromDaoModelToDetailsWithEvents(daoModel: ConversationDetailsWithEventsEntity): ConversationDetailsWithEvents
fun fromDaoModelToDetails(daoModel: ConversationViewEntity, selfUserTeamId: TeamId?): ConversationDetails
fun fromDaoModelToDetailsWithEvents(
daoModel: ConversationDetailsWithEventsEntity,
selfUserTeamId: TeamId?
): ConversationDetailsWithEvents
fun fromDaoModel(daoModel: ProposalTimerEntity): ProposalTimer
fun toDAOAccess(accessList: Set<ConversationAccessDTO>): List<ConversationEntity.Access>
fun toDAOAccessRole(accessRoleList: Set<ConversationAccessRoleDTO>): List<ConversationEntity.AccessRole>
Expand Down Expand Up @@ -233,7 +236,10 @@ internal class ConversationMapperImpl(
}

@Suppress("ComplexMethod", "LongMethod")
override fun fromDaoModelToDetails(daoModel: ConversationViewEntity): ConversationDetails =
override fun fromDaoModelToDetails(
daoModel: ConversationViewEntity,
selfUserTeamId: TeamId?
): ConversationDetails =
with(daoModel) {
when (type) {
ConversationEntity.Type.SELF -> {
Expand Down Expand Up @@ -271,7 +277,7 @@ internal class ConversationMapperImpl(
conversation = fromConversationViewToEntity(daoModel),
hasOngoingCall = callStatus != null, // todo: we can do better!
isSelfUserMember = isMember,
isSelfUserCreator = isCreator == 1L,
selfUserTeamId = selfUserTeamId,
selfRole = selfRole?.let { conversationRoleMapper.fromDAO(it) }
)
}
Expand Down Expand Up @@ -318,9 +324,12 @@ internal class ConversationMapperImpl(
}
}

override fun fromDaoModelToDetailsWithEvents(daoModel: ConversationDetailsWithEventsEntity): ConversationDetailsWithEvents =
ConversationDetailsWithEvents(
conversationDetails = fromDaoModelToDetails(daoModel.conversationViewEntity),
override fun fromDaoModelToDetailsWithEvents(
daoModel: ConversationDetailsWithEventsEntity,
selfUserTeamId: TeamId?
): ConversationDetailsWithEvents {
return ConversationDetailsWithEvents(
conversationDetails = fromDaoModelToDetails(daoModel.conversationViewEntity, selfUserTeamId),
unreadEventCount = daoModel.unreadEvents.unreadEvents.mapKeys {
when (it.key) {
UnreadEventTypeEntity.KNOCK -> UnreadEventType.KNOCK
Expand All @@ -338,6 +347,7 @@ internal class ConversationMapperImpl(
},
hasNewActivitiesToShow = daoModel.hasNewActivitiesToShow
)
}

override fun fromDaoModel(daoModel: ProposalTimerEntity): ProposalTimer =
ProposalTimer(idMapper.fromGroupIDEntity(daoModel.groupID), daoModel.firingDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,11 @@ internal class ConversationDataSource internal constructor(
private val protocolInfoMapper: ProtocolInfoMapper = MapperProvider.protocolInfoMapper(),
private val receiptModeMapper: ReceiptModeMapper = MapperProvider.receiptModeMapper()
) : ConversationRepository {
override val extensions: ConversationRepositoryExtensions =
ConversationRepositoryExtensionsImpl(conversationDAO, conversationMapper)
override val extensions: ConversationRepositoryExtensions = ConversationRepositoryExtensionsImpl(
conversationDAO = conversationDAO,
conversationMapper = conversationMapper,
selfTeamIdProvider = selfTeamIdProvider
)

// region Get/Observe by id

Expand Down Expand Up @@ -366,7 +369,7 @@ internal class ConversationDataSource internal constructor(
.map { eitherConversationView ->
eitherConversationView.flatMap {
try {
Either.Right(conversationMapper.fromDaoModelToDetails(it))
Either.Right(conversationMapper.fromDaoModelToDetails(it, selfTeamIdProvider().getOrNull()))
} catch (error: IllegalArgumentException) {
kaliumLogger.e("require field in conversation Details", error)
Either.Left(StorageFailure.DataNotFound)
Expand Down Expand Up @@ -529,7 +532,9 @@ internal class ConversationDataSource internal constructor(
conversationFilter: ConversationFilter
): Flow<List<ConversationDetails>> =
conversationDAO.getAllConversationDetails(fromArchive, conversationFilter.toDao()).map { conversationViewEntityList ->
conversationViewEntityList.map { conversationViewEntity -> conversationMapper.fromDaoModelToDetails(conversationViewEntity) }
conversationViewEntityList.map { conversationViewEntity ->
conversationMapper.fromDaoModelToDetails(conversationViewEntity, selfTeamIdProvider().getOrNull())
}
}

override suspend fun observeConversationListDetailsWithEvents(
Expand All @@ -553,7 +558,8 @@ internal class ConversationDataSource internal constructor(
lastMessage = lastMessageMap[conversation.id],
messageDraft = messageDraftMap[conversation.id],
unreadEvents = unreadEventsMap[conversation.id] ?: ConversationUnreadEventEntity(conversation.id, mapOf()),
)
),
selfTeamIdProvider().getOrNull()
)
}
}
Expand Down Expand Up @@ -1010,7 +1016,7 @@ internal class ConversationDataSource internal constructor(

override suspend fun getConversationDetailsByMLSGroupId(mlsGroupId: GroupID): Either<CoreFailure, ConversationDetails> =
wrapStorageRequest { conversationDAO.getConversationDetailsByGroupID(mlsGroupId.value) }
.map { conversationMapper.fromDaoModelToDetails(it) }
.map { conversationMapper.fromDaoModelToDetails(it, selfTeamIdProvider().getOrNull()) }

override suspend fun observeUnreadArchivedConversationsCount(): Flow<Long> =
conversationDAO.observeUnreadArchivedConversationsCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package com.wire.kalium.logic.data.conversation
import app.cash.paging.PagingConfig
import app.cash.paging.PagingData
import app.cash.paging.map
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.functional.getOrNull
import com.wire.kalium.persistence.dao.conversation.ConversationDAO
import com.wire.kalium.persistence.dao.conversation.ConversationDetailsWithEventsEntity
import com.wire.kalium.persistence.dao.conversation.ConversationExtensions.QueryConfig
Expand All @@ -37,7 +39,8 @@ interface ConversationRepositoryExtensions {

class ConversationRepositoryExtensionsImpl internal constructor(
private val conversationDAO: ConversationDAO,
private val conversationMapper: ConversationMapper
private val conversationMapper: ConversationMapper,
private val selfTeamIdProvider: SelfTeamIdProvider
) : ConversationRepositoryExtensions {
override suspend fun getPaginatedConversationDetailsWithEventsBySearchQuery(
queryConfig: ConversationQueryConfig,
Expand All @@ -61,7 +64,8 @@ class ConversationRepositoryExtensionsImpl internal constructor(
pagingData
.map { conversationDetailsWithEventsEntity ->
conversationMapper.fromDaoModelToDetailsWithEvents(
conversationDetailsWithEventsEntity
daoModel = conversationDetailsWithEventsEntity,
selfUserTeamId = selfTeamIdProvider().getOrNull()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import com.wire.kalium.logic.data.conversation.ConversationMapper
import com.wire.kalium.logic.data.conversation.FolderType
import com.wire.kalium.logic.data.conversation.FolderWithConversations
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.flatMapLeft
import com.wire.kalium.logic.functional.getOrNull
import com.wire.kalium.logic.functional.map
import com.wire.kalium.logic.functional.onFailure
import com.wire.kalium.logic.functional.onSuccess
Expand Down Expand Up @@ -57,6 +59,7 @@ internal class ConversationFolderDataSource internal constructor(
private val conversationFolderDAO: ConversationFolderDAO,
private val userPropertiesApi: PropertiesApi,
private val selfUserId: QualifiedID,
private val selfTeamIdProvider: SelfTeamIdProvider,
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId)
) : ConversationFolderRepository {

Expand All @@ -72,7 +75,7 @@ internal class ConversationFolderDataSource internal constructor(
override suspend fun observeConversationsFromFolder(folderId: String): Flow<List<ConversationDetailsWithEvents>> =
conversationFolderDAO.observeConversationListFromFolder(folderId).map { conversationDetailsWithEventsEntityList ->
conversationDetailsWithEventsEntityList.map {
conversationMapper.fromDaoModelToDetailsWithEvents(it)
conversationMapper.fromDaoModelToDetailsWithEvents(it, selfTeamIdProvider().getOrNull())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,10 @@ class UserSessionScope internal constructor(

private val conversationFolderRepository: ConversationFolderRepository
get() = ConversationFolderDataSource(
userStorage.database.conversationFolderDAO,
authenticatedNetworkContainer.propertiesApi,
userId
conversationFolderDAO = userStorage.database.conversationFolderDAO,
userPropertiesApi = authenticatedNetworkContainer.propertiesApi,
selfUserId = userId,
selfTeamIdProvider = selfTeamId
)

private val conversationGroupRepository: ConversationGroupRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class CallRepositoryTest {
Arrangement.groupConversation,
false,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down Expand Up @@ -212,7 +212,7 @@ class CallRepositoryTest {
ConversationDetails.Group(
Arrangement.groupConversation,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down Expand Up @@ -266,7 +266,7 @@ class CallRepositoryTest {
ConversationDetails.Group(
Arrangement.groupConversation,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down Expand Up @@ -309,7 +309,7 @@ class CallRepositoryTest {
ConversationDetails.Group(
Arrangement.groupConversation,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down Expand Up @@ -366,7 +366,7 @@ class CallRepositoryTest {
ConversationDetails.Group(
Arrangement.groupConversation,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class ConversationMapperTest {
messageDraft = messageDraft,
unreadEvents = ConversationUnreadEventEntity(TestConversation.VIEW_ENTITY.id, mapOf()),
)
assertion(conversationMapper.fromDaoModelToDetailsWithEvents(conversation).lastMessage)
assertion(conversationMapper.fromDaoModelToDetailsWithEvents(conversation, selfUserTeamId = null).lastMessage)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import app.cash.paging.Pager
import app.cash.paging.PagingConfig
import app.cash.paging.PagingSource
import app.cash.paging.PagingState
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.data.message.MessageMapper
import com.wire.kalium.logic.framework.TestConversationDetails
import com.wire.kalium.logic.framework.TestMessage
Expand Down Expand Up @@ -90,18 +91,21 @@ class ConversationRepositoryExtensionsTest {
@Mock
private val conversationMapper: ConversationMapper = mock(ConversationMapper::class)

@Mock
private val selfTeamIdProvider: SelfTeamIdProvider = mock(SelfTeamIdProvider::class)

@Mock
private val messageMapper: MessageMapper = mock(MessageMapper::class)
private val conversationRepositoryExtensions: ConversationRepositoryExtensions by lazy {
ConversationRepositoryExtensionsImpl(conversationDAO, conversationMapper)
ConversationRepositoryExtensionsImpl(conversationDAO, conversationMapper, selfTeamIdProvider)
}

init {
every {
messageMapper.fromEntityToMessage(any())
}.returns(TestMessage.TEXT_MESSAGE)
every {
conversationMapper.fromDaoModelToDetails(any())
conversationMapper.fromDaoModelToDetails(any(), any())
}.returns(TestConversationDetails.CONVERSATION_GROUP)
every {
conversationDAO.platformExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ package com.wire.kalium.logic.data.conversation.folders
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.data.conversation.FolderType
import com.wire.kalium.logic.data.conversation.FolderWithConversations
import com.wire.kalium.logic.data.id.SelfTeamIdProvider
import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.logic.framework.TestConversation
import com.wire.kalium.logic.framework.TestUser
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.util.shouldFail
import com.wire.kalium.logic.util.shouldSucceed
import com.wire.kalium.network.api.authenticated.properties.LabelListResponseDTO
Expand Down Expand Up @@ -81,13 +83,17 @@ class ConversationFolderRepositoryTest {

val conversations = listOf(conversation)
val arrangement = Arrangement().withConversationsFromFolder(folderId, conversations)
.withEmptySelfTeamId()

// when
val resultFlow = arrangement.repository.observeConversationsFromFolder(folderId)

// then
val emittedConversations = resultFlow.first()
assertEquals(arrangement.conversationMapper.fromDaoModelToDetailsWithEvents(conversations.first()), emittedConversations.first())
assertEquals(
arrangement.conversationMapper.fromDaoModelToDetailsWithEvents(conversations.first(), selfUserTeamId = null),
emittedConversations.first()
)
}

@Test
Expand Down Expand Up @@ -163,14 +169,18 @@ class ConversationFolderRepositoryTest {
@Mock
val userPropertiesApi = mock(PropertiesApi::class)

@Mock
val selfTeamIdProvider = mock(SelfTeamIdProvider::class)

private val selfUserId = TestUser.SELF.id

val conversationMapper = MapperProvider.conversationMapper(selfUserId)

val repository = ConversationFolderDataSource(
conversationFolderDAO = conversationFolderDAO,
userPropertiesApi = userPropertiesApi,
selfUserId = selfUserId
selfUserId = selfUserId,
selfTeamIdProvider = selfTeamIdProvider
)

suspend fun withFavoriteConversationFolder(folder: ConversationFolderEntity): Arrangement {
Expand All @@ -183,6 +193,11 @@ class ConversationFolderRepositoryTest {
return this
}

suspend fun withEmptySelfTeamId(): Arrangement {
coEvery { selfTeamIdProvider() }.returns(Either.Right(null))
return this
}

suspend fun withSuccessfulFolderUpdate(): Arrangement {
coEvery { conversationFolderDAO.updateConversationFolders(any()) }.returns(Unit)
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class EndCallOnConversationChangeUseCaseTest {
conversation = conversation,
hasOngoingCall = true,
isSelfUserMember = false,
isSelfUserCreator = false,
selfUserTeamId = null,
selfRole = null
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class ObserveConversationDetailsUseCaseTest {
ConversationDetails.Group(
conversation,
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
),
Either.Right(
ConversationDetails.Group(
conversation.copy(name = "New Name"),
isSelfUserMember = true,
isSelfUserCreator = true,
selfUserTeamId = null,
selfRole = Conversation.Member.Role.Member
)
)
Expand Down
Loading
Loading