Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NT-2000: Retrying posting a failed reply Scrolling bug (#1327)
* Fix reply bug * Update failing tests * More broken tests * Linter * Fix scrolling to top issue and remove TODO * Merge comment and postsuccessful streams * Fix broken test * Add scrolling * Update success post * Update test Co-authored-by: Leigh Douglas <leighcdouglas1@gmail.com>
- Loading branch information
1 parent
031e392
commit 1fb18b6
Showing
8 changed files
with
347 additions
and
29 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/kickstarter/models/extensions/CommentExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.kickstarter.models.extensions | ||
|
||
import com.kickstarter.models.Comment | ||
import com.kickstarter.ui.data.CommentCardData | ||
import com.kickstarter.ui.views.CommentCardStatus | ||
|
||
/** | ||
* Update the internal persisted list of comments with the successful response | ||
* from calling the Post Mutation | ||
*/ | ||
fun Comment.updateCommentAfterSuccessfulPost( | ||
listOfComments: List<CommentCardData> | ||
): List<CommentCardData> { | ||
|
||
val position = listOfComments.indexOfFirst { commentCardData -> | ||
( | ||
commentCardData.commentCardState == CommentCardStatus.TRYING_TO_POST.commentCardStatus || | ||
commentCardData.commentCardState == CommentCardStatus.FAILED_TO_SEND_COMMENT.commentCardStatus | ||
) && | ||
commentCardData.comment?.body() == this.body() && | ||
commentCardData.comment?.author()?.id() == this.author().id() | ||
} | ||
|
||
if (position >= 0 && position < listOfComments.size) { | ||
return listOfComments.toMutableList().apply { | ||
this[position] = listOfComments[position].toBuilder() | ||
.commentCardState(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS.commentCardStatus) | ||
.comment(this@updateCommentAfterSuccessfulPost) | ||
.build() | ||
} | ||
} | ||
|
||
return listOfComments | ||
} | ||
|
||
/** | ||
* Update the internal persisted list of comments with the failed response | ||
* from calling the Post Mutation | ||
*/ | ||
fun Comment.updateCommentFailedToPost( | ||
listOfComments: List<CommentCardData> | ||
): List<CommentCardData> { | ||
|
||
val position = listOfComments.indexOfFirst { commentCardData -> | ||
commentCardData.commentCardState == CommentCardStatus.TRYING_TO_POST.commentCardStatus && | ||
commentCardData.comment?.body() == this.body() && | ||
commentCardData.comment?.author()?.id() == this.author().id() | ||
} | ||
|
||
if (position >= 0 && position < listOfComments.size) { | ||
return listOfComments.toMutableList().apply { | ||
this[position] = listOfComments[position].toBuilder() | ||
.commentCardState(CommentCardStatus.FAILED_TO_SEND_COMMENT.commentCardStatus) | ||
.comment(this@updateCommentFailedToPost) | ||
.build() | ||
} | ||
} | ||
|
||
return listOfComments | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.