use of com.meisolsson.githubsdk.service.issues.IssueCommentService in project gh4a by slapperwan.
the class EditIssueCommentActivity method editComment.
@Override
protected Single<GitHubCommentBase> editComment(String repoOwner, String repoName, long commentId, String body) {
IssueCommentService service = ServiceFactory.get(IssueCommentService.class, false);
CommentRequest request = CommentRequest.builder().body(body).build();
return service.editIssueComment(repoOwner, repoName, commentId, request).map(ApiHelpers::throwOnFailure);
}
use of com.meisolsson.githubsdk.service.issues.IssueCommentService 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.IssueCommentService in project gh4a by slapperwan.
the class ReviewFragment method handleDeleteComment.
private void handleDeleteComment(GitHubCommentBase comment) {
final Single<Response<Void>> responseSingle;
if (comment instanceof ReviewComment) {
PullRequestReviewCommentService service = ServiceFactory.get(PullRequestReviewCommentService.class, false);
responseSingle = service.deleteComment(mRepoOwner, mRepoName, comment.id());
} else {
IssueCommentService service = ServiceFactory.get(IssueCommentService.class, false);
responseSingle = service.deleteIssueComment(mRepoOwner, mRepoName, comment.id());
}
responseSingle.map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.deleting_msg, R.string.error_delete_comment)).subscribe(result -> reloadComments(false), error -> handleActionFailure("Deleting comment failed", error));
}
use of com.meisolsson.githubsdk.service.issues.IssueCommentService 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;
});
}
use of com.meisolsson.githubsdk.service.issues.IssueCommentService in project gh4a by slapperwan.
the class IssueFragmentBase method onEditorDoSend.
@Override
public Single<?> onEditorDoSend(String comment) {
IssueCommentService service = ServiceFactory.get(IssueCommentService.class, false);
CommentRequest request = CommentRequest.builder().body(comment).build();
return service.createIssueComment(mRepoOwner, mRepoName, mIssue.number(), request).map(ApiHelpers::throwOnFailure);
}
Aggregations