Keep cached post's collectionAlias from being set to nil by fetched post

This commit is contained in:
Angelo Stavrow 2020-10-06 08:40:52 -04:00
parent b0d440edd5
commit 50c521ea8f
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -324,6 +324,10 @@ private extension WriteFreelyModel {
}
func publishHandler(result: Result<WFPost, Error>) {
// NOTE:
// The API does not return a collection alias, so we take care not to overwrite the
// cached post's collection alias with the 'nil' value from the fetched post.
// See: https://github.com/writeas/writefreely-swift/issues/20
do {
let fetchedPost = try result.get()
let foundPostIndex = posts.userPosts.firstIndex(where: {
@ -333,7 +337,6 @@ private extension WriteFreelyModel {
let cachedPost = self.posts.userPosts[index]
cachedPost.appearance = fetchedPost.appearance
cachedPost.body = fetchedPost.body
cachedPost.collectionAlias = fetchedPost.collectionAlias
cachedPost.createdDate = fetchedPost.createdDate
cachedPost.language = fetchedPost.language
cachedPost.postId = fetchedPost.postId