Fix delete propogation

This commit is contained in:
Jackson Harper
2023-05-29 10:30:23 +08:00
parent 0466451019
commit 048facb7ca
4 changed files with 25 additions and 17 deletions

View File

@ -51,29 +51,29 @@ suspend fun DataService.createWebHighlight(jsonString: String) {
suspend fun DataService.createNoteHighlight(savedItemId: String, note: String) {
val shortId = UUID.randomUUID().toString()
val createHighlightId = UUID.randomUUID().toString()
val createHighlightParams = CreateHighlightParams(
type = HighlightType.NOTE,,
shortId = shortId,
id = createHighlightId,
quote = null,
patch = null,
articleId = null,
annotation = note,
)
// val createHighlightParams = CreateHighlightParams(
// type = HighlightType.NOTE,,
// shortId = shortId,
// id = createHighlightId,
// quote = null,
// patch = null,
// articleId = null,
// annotation = note,
// )
withContext(Dispatchers.IO) {
val highlight = Highlight(
type = "HIGHLIGHT",
highlightId = createHighlightInput.id,
shortId = createHighlightInput.shortId,
quote = createHighlightInput.quote.getOrNull(),
highlightId = createHighlightId,
shortId = shortId,
quote = null,
prefix = null,
suffix = null,
patch = createHighlightInput.patch.getOrNull(),
annotation = createHighlightInput.annotation.getOrNull(),
patch =null,
annotation = note,
createdAt = null,
updatedAt = null,
createdByMe = false
createdByMe = true
)
highlight.serverSyncStatus = ServerSyncStatus.NEEDS_CREATION.rawValue
@ -87,6 +87,7 @@ suspend fun DataService.createNoteHighlight(savedItemId: String, note: String) {
db.savedItemAndHighlightCrossRefDao().insertAll(listOf(crossRef))
val newHighlight = networker.createHighlight(input = CreateHighlightParams(
type = HighlightType.HIGHLIGHT,
shortId = shortId,
id = createHighlightId,
quote = null,

View File

@ -34,6 +34,10 @@ suspend fun DataService.sync(since: String, cursor: String?, limit: Int = 20): S
val syncResult = networker.savedItemUpdates(cursor = cursor, limit = limit, since = since)
?: return SavedItemSyncResult.errorResult
if (syncResult.deletedItemIDs.isNotEmpty()) {
db.savedItemDao().deleteByIds(syncResult.deletedItemIDs)
}
val savedItems = syncResult.items.map {
val savedItem = SavedItem(
savedItemId = it.id,

View File

@ -23,8 +23,8 @@ data class CreateHighlightParams(
val `annotation`: String?
) {
fun asCreateHighlightInput() = CreateHighlightInput(
type = type,
annotation = Optional.presentIfNotNull(`annotation`),
type = Optional.presentIfNotNull(type),
annotation = Optional.presentIfNotNull(annotation),
articleId = articleId ?: "",
id = id ?: "",
patch = Optional.presentIfNotNull(patch),

View File

@ -142,6 +142,9 @@ interface SavedItemDao {
@Query("DELETE FROM savedItem WHERE savedItemId = :itemID")
fun deleteById(itemID: String)
@Query("DELETE FROM savedItem WHERE savedItemId in (:itemIDs)")
fun deleteByIds(itemIDs: List<String>)
@Update
fun update(savedItem: SavedItem)