Skip to content

Commit

Permalink
review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas committed Dec 16, 2024
1 parent f0f1415 commit 06bd773
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ internal class ConversationDataSource internal constructor(
val isNewConversation = conversationDAO.getConversationById(conversation.id.toDao()) == null
if (isNewConversation) {
val mlsGroupState = conversation.groupId?.let { mlsGroupState(idMapper.fromGroupIDEntity(it), originatedFromEvent) }
// if group state is left, then we don't want to persist the conversation
if (mlsGroupState?.fold({ true }, { false }) != true) {
if (shouldPersistMLSConversation(mlsGroupState)) {
conversationDAO.insertConversation(
conversationMapper.fromApiModelToDaoModel(
conversation,
Expand All @@ -461,15 +460,14 @@ internal class ConversationDataSource internal constructor(
val mlsGroupState = conversationResponse.groupId?.let {
mlsGroupState(idMapper.fromGroupIDEntity(it), originatedFromEvent)
}
// if group state is left, then we don't want to persist the conversation
if (mlsGroupState?.fold({ true }, { false }) == true) {
null
} else {
if (shouldPersistMLSConversation(mlsGroupState)) {
conversationMapper.fromApiModelToDaoModel(
conversationResponse,
mlsGroupState = mlsGroupState?.getOrNull(),
selfTeamIdProvider().getOrNull(),
)
} else {
null
}
}
conversationDAO.insertConversations(conversationEntities)
Expand Down Expand Up @@ -514,6 +512,10 @@ internal class ConversationDataSource internal constructor(
}
}

// if group state is not null and is left, then we don't want to persist the MLS conversation
private fun shouldPersistMLSConversation(groupState: Either<CoreFailure, ConversationEntity.GroupState>?): Boolean =
groupState?.fold({ true }, { false }) != true

@DelicateKaliumApi("This function does not get values from cache")
override suspend fun getProteusSelfConversationId(): Either<StorageFailure, ConversationId> =
wrapStorageRequest { conversationDAO.getSelfConversationId(ConversationEntity.Protocol.PROTEUS) }
Expand Down

0 comments on commit 06bd773

Please sign in to comment.