Skip to content
Merged
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 @@ -37,7 +37,7 @@ expect object AppDatabaseConstructor : RoomDatabaseConstructor<WriteopiaApplicat
UserEntity::class,
TokenEntity::class
],
version = 22,
version = 23,
exportSchema = false
)
@TypeConverters(IdListConverter::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ interface DocumentEntityDao {

@Query("UPDATE $DOCUMENT_ENTITY set user_id = :newUserId WHERE user_id = :oldUserId")
suspend fun moveDocumentsToNewUser(oldUserId: String, newUserId: String)

@Query("SELECT title FROM $DOCUMENT_ENTITY WHERE $DOCUMENT_ENTITY.id = :documentId")
suspend fun getDocumentTitleById(documentId: String): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.writeopia.sdk.persistence.dao.room
import io.writeopia.sdk.model.document.DocumentInfo
import io.writeopia.sdk.model.document.info
import io.writeopia.sdk.models.document.Document
import io.writeopia.sdk.models.link.DocumentLink
import io.writeopia.sdk.models.story.StoryStep
import io.writeopia.sdk.search.DocumentSearch
import io.writeopia.sdk.repository.DocumentRepository
Expand Down Expand Up @@ -168,13 +169,17 @@ class RoomDocumentRepository(
storyEntities.filter { entity -> entity.parentId == null }
.associateBy { entity -> entity.position }
.mapValues { (_, entity) ->
if (entity.linkToDocument != null) {
val title = documentEntityDao.getDocumentTitleById(entity.linkToDocument)
return@mapValues entity.toModel(documentLink = DocumentLink(entity.linkToDocument, title))
}

if (entity.hasInnerSteps) {
val innerSteps = storyUnitEntityDao?.queryInnerSteps(entity.id) ?: emptyList()

entity.toModel(innerSteps)
} else {
entity.toModel()
return@mapValues entity.toModel(innerSteps)
}

entity.toModel()
}

private suspend fun setFavorite(ids: Set<String>, isFavorite: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ data class StoryStepEntity(
@ColumnInfo(name = "background_color") val backgroundColor: Int?,
@ColumnInfo(name = "tags") val tags: String,
@ColumnInfo(name = "spans") val spans: String,
@ColumnInfo(name = "link_to_document") val linkToDocument: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.writeopia.sdk.persistence.parse

import io.writeopia.sdk.models.link.DocumentLink
import io.writeopia.sdk.models.span.SpanInfo
import io.writeopia.sdk.models.story.Decoration
import io.writeopia.sdk.models.story.StoryStep
Expand All @@ -23,7 +24,8 @@ fun StoryStepEntity.toModel(
steps: List<StoryStepEntity> = emptyList(),
nameToType: (String) -> StoryType = { typeName ->
StoryTypes.fromName(typeName).type
}
},
documentLink: DocumentLink? = null,
): StoryStep =
StoryStep(
id = id,
Expand All @@ -47,7 +49,8 @@ fun StoryStepEntity.toModel(
.split(",")
.filter { it.isNotEmpty() }
.map(SpanInfo::fromString)
.toSet()
.toSet(),
documentLink = documentLink
)

fun StoryStep.toEntity(position: Int, documentId: String): StoryStepEntity =
Expand All @@ -66,5 +69,6 @@ fun StoryStep.toEntity(position: Int, documentId: String): StoryStepEntity =
hasInnerSteps = this.steps.isNotEmpty(),
backgroundColor = this.decoration.backgroundColor,
tags = this.tags.joinToString(separator = ",") { it.tag.label },
spans = this.spans.joinToString(separator = ",") { it.toText() }
spans = this.spans.joinToString(separator = ",") { it.toText() },
linkToDocument = documentLink?.id
)