use of com.meisolsson.githubsdk.service.issues.IssueEventService in project gh4a by slapperwan.
the class IssueFragment method onCreateDataSingle.
@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
final int issueNumber = mIssue.number();
final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
Single<List<TimelineItem>> commentSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
Single<List<TimelineItem>> eventSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
return Single.zip(commentSingle, eventSingle, (comments, events) -> {
ArrayList<TimelineItem> result = new ArrayList<>();
result.addAll(comments);
result.addAll(events);
Collections.sort(result, TimelineItem.COMPARATOR);
return result;
});
}
use of com.meisolsson.githubsdk.service.issues.IssueEventService in project gh4a by slapperwan.
the class PullRequestFragment method onCreateDataSingle.
@Override
protected Single<List<TimelineItem>> onCreateDataSingle(boolean bypassCache) {
final int issueNumber = mIssue.number();
final IssueEventService eventService = ServiceFactory.get(IssueEventService.class, bypassCache);
final IssueCommentService commentService = ServiceFactory.get(IssueCommentService.class, bypassCache);
final PullRequestService prService = ServiceFactory.get(PullRequestService.class, bypassCache);
final PullRequestReviewService reviewService = ServiceFactory.get(PullRequestReviewService.class, bypassCache);
final PullRequestReviewCommentService prCommentService = ServiceFactory.get(PullRequestReviewCommentService.class, bypassCache);
Single<List<TimelineItem>> issueCommentItemSingle = ApiHelpers.PageIterator.toSingle(page -> commentService.getIssueComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.mapList(TimelineItem.TimelineComment::new));
Single<List<TimelineItem>> eventItemSingle = ApiHelpers.PageIterator.toSingle(page -> eventService.getIssueEvents(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.filter(event -> INTERESTING_EVENTS.contains(event.event()))).compose((RxUtils.mapList(TimelineItem.TimelineEvent::new)));
Single<Map<String, GitHubFile>> filesByNameSingle = ApiHelpers.PageIterator.toSingle(page -> prService.getPullRequestFiles(mRepoOwner, mRepoName, issueNumber, page)).map(files -> {
Map<String, GitHubFile> filesByName = new HashMap<>();
for (GitHubFile file : files) {
filesByName.put(file.filename(), file);
}
return filesByName;
}).cache();
Single<List<Review>> reviewSingle = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviews(mRepoOwner, mRepoName, issueNumber, page)).cache();
Single<List<ReviewComment>> prCommentSingle = ApiHelpers.PageIterator.toSingle(page -> prCommentService.getPullRequestComments(mRepoOwner, mRepoName, issueNumber, page)).compose(RxUtils.sortList(ApiHelpers.COMMENT_COMPARATOR)).cache();
Single<LongSparseArray<List<ReviewComment>>> reviewCommentsByIdSingle = reviewSingle.compose(RxUtils.filter(r -> r.state() == ReviewState.Pending)).toObservable().flatMap(reviews -> {
List<Observable<Pair<Long, List<ReviewComment>>>> obsList = new ArrayList<>();
for (Review r : reviews) {
Single<List<ReviewComment>> single = ApiHelpers.PageIterator.toSingle(page -> reviewService.getReviewComments(mRepoOwner, mRepoName, issueNumber, r.id()));
obsList.add(Single.zip(Single.just(r.id()), single, Pair::create).toObservable());
}
return Observable.concat(obsList);
}).toList().map(list -> {
LongSparseArray<List<ReviewComment>> result = new LongSparseArray<>();
for (Pair<Long, List<ReviewComment>> pair : list) {
result.put(pair.first, pair.second);
}
return result;
});
Single<List<TimelineItem.TimelineReview>> reviewTimelineSingle = Single.zip(reviewSingle, filesByNameSingle, prCommentSingle, reviewCommentsByIdSingle, (prReviews, filesByName, commitComments, pendingCommentsById) -> {
LongSparseArray<TimelineItem.TimelineReview> reviewsById = new LongSparseArray<>();
List<TimelineItem.TimelineReview> reviews = new ArrayList<>();
for (Review review : prReviews) {
TimelineItem.TimelineReview timelineReview = new TimelineItem.TimelineReview(review);
reviewsById.put(review.id(), timelineReview);
reviews.add(timelineReview);
if (review.state() == ReviewState.Pending) {
for (ReviewComment pendingComment : pendingCommentsById.get(review.id())) {
GitHubFile commitFile = filesByName.get(pendingComment.path());
timelineReview.addComment(pendingComment, commitFile, true);
}
}
}
Map<String, TimelineItem.TimelineReview> reviewsBySpecialId = new HashMap<>();
for (ReviewComment commitComment : commitComments) {
GitHubFile file = filesByName.get(commitComment.path());
if (commitComment.pullRequestReviewId() != null) {
String id = TimelineItem.Diff.getDiffHunkId(commitComment);
TimelineItem.TimelineReview review = reviewsBySpecialId.get(id);
if (review == null) {
review = reviewsById.get(commitComment.pullRequestReviewId());
reviewsBySpecialId.put(id, review);
}
review.addComment(commitComment, file, true);
}
}
return reviews;
}).compose(RxUtils.filter(item -> {
// noinspection CodeBlock2Expr
return item.review().state() != ReviewState.Commented || !TextUtils.isEmpty(item.review().body()) || !item.getDiffHunks().isEmpty();
}));
Single<List<TimelineItem.TimelineComment>> commitCommentWithoutReviewSingle = Single.zip(prCommentSingle.compose(RxUtils.filter(comment -> comment.pullRequestReviewId() == 0)), filesByNameSingle, (comments, files) -> {
List<TimelineItem.TimelineComment> items = new ArrayList<>();
for (ReviewComment comment : comments) {
items.add(new TimelineItem.TimelineComment(comment, files.get(comment.path())));
}
return items;
});
return Single.zip(issueCommentItemSingle, eventItemSingle, reviewTimelineSingle, commitCommentWithoutReviewSingle, (comments, events, reviewItems, commentsWithoutReview) -> {
ArrayList<TimelineItem> result = new ArrayList<>();
result.addAll(comments);
result.addAll(events);
result.addAll(reviewItems);
result.addAll(commentsWithoutReview);
Collections.sort(result, TimelineItem.COMPARATOR);
return result;
});
}
Aggregations