Skip to content

Commit 1b29103

Browse files
committed
Use PostModel for parent page in EditPostRepository
Instead of using another page model class (ParentPage), we should leverage the existing PostModel object, simplifying the logic and keeping things consistent.
1 parent 3e2e26a commit 1b29103

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostRepository.kt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class EditPostRepository
9898
get() = post!!.tagNameList
9999
val dateLocallyChanged: String
100100
get() = post!!.dateLocallyChanged
101-
private var parent: ParentPage = ParentPage(0L, EMPTY_STRING)
101+
private var parent: PostModel? = null
102102

103103
private var locked = false
104104

@@ -237,27 +237,19 @@ class EditPostRepository
237237

238238
fun getParentTitle(site: SiteModel): String {
239239
// update parent local field if parent ID of current post has changed
240-
if (parent.id != post?.parentId) {
240+
if (parent?.remotePostId != post?.parentId) {
241241
runBlocking {
242-
val parentId = post?.parentId ?: 0L
243-
val parentTitle = parentId
244-
.takeUnless { it == 0L }
245-
?.let { postStore.getPostByRemotePostId(it, site)?.title }
246-
?: EMPTY_STRING
247-
parent = ParentPage(parentId, parentTitle)
242+
parent = post?.parentId
243+
?.takeUnless { it == 0L }
244+
?.let { postStore.getPostByRemotePostId(it, site) }
248245
}
249246
}
250247

251-
return parent.title
248+
return parent?.title ?: EMPTY_STRING
252249
}
253250

254251
sealed class UpdatePostResult {
255252
object Updated : UpdatePostResult()
256253
object NoChanges : UpdatePostResult()
257254
}
258-
259-
private data class ParentPage(
260-
val id: Long,
261-
val title: String,
262-
)
263255
}

WordPress/src/test/java/org/wordpress/android/ui/posts/EditPostRepositoryTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,10 @@ class EditPostRepositoryTest {
581581
val site = SiteModel()
582582

583583
val parentTitle = "Parent"
584-
val parentPost = PostModel().apply { setTitle(parentTitle) }
584+
val parentPost = PostModel().apply {
585+
setRemotePostId(parentId)
586+
setTitle(parentTitle)
587+
}
585588

586589
whenever(postStore.getPostByRemotePostId(remoteId, site)).thenReturn(post)
587590
whenever(postStore.getPostByRemotePostId(parentId, site)).thenReturn(parentPost)

0 commit comments

Comments
 (0)