Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

NT-2069:Refactor Comment Pagination code #1308

Merged
merged 2 commits into from
Jun 30, 2021
Merged
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 @@ -101,6 +101,7 @@ interface CommentsViewModel {
private var commentableId: String? = null

private val isFetchingComments = BehaviorSubject.create<Boolean>()
private lateinit var project: Project

init {

Expand Down Expand Up @@ -141,7 +142,10 @@ interface CommentsViewModel {
)
}.map {
requireNotNull(it)
}.share()
}.doOnNext {
this.project = it
}
.share()

initialProject
.compose(combineLatestPair(currentUser.observable()))
Expand Down Expand Up @@ -301,7 +305,7 @@ interface CommentsViewModel {
.distinctUntilChanged(true)
.startOverWith(startOverWith)
.envelopeToListOfData {
mapToCommentCardDataList(Pair(it, null))
mapToCommentCardDataList(Pair(it, this.project))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since project can technically be null, I think it would be best if we put a null check here to guarantee that no crash happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed map method to not allow null

}
.loadWithParams {
loadWithProjectOrUpdateComments(Observable.just(it.first), it.second)
Expand Down Expand Up @@ -375,7 +379,7 @@ interface CommentsViewModel {
.onErrorResumeNext(Observable.empty())
}

private fun mapToCommentCardDataList(it: Pair<CommentEnvelope, Project?>) =
private fun mapToCommentCardDataList(it: Pair<CommentEnvelope, Project>) =
it.first.comments?.map { comment: Comment ->
CommentCardData.builder()
.comment(comment)
Expand Down