The Unified and Autonomous Development Platform
Inline comment.
robin shine6c833ec9fbc9
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.javadeleted file mode 100644index 19a5632606..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/BlobLoader.java+++ /dev/null@@ -1,22 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import javax.annotation.Nullable;--import com.pmease.commons.git.BlobInfo;--public interface BlobLoader {-- /**- * Load content of specified blob and convert to lines.- *- * @param blobInfo- * blob info to load- * @return- * lines of the blob, or null if the blob content can not be- * converted to text- */- @Nullable- List<String> loadBlob(BlobInfo blobInfo);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.javadeleted file mode 100644index 060599b628..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeLoader.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import com.pmease.commons.git.Change;--public interface ChangeLoader {- List<Change> loadChanges(String fromRev, String toRev);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/Comment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/Comment.javanew file mode 100644index 0000000000..0ab0870738--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/Comment.java@@ -0,0 +1,26 @@+package com.pmease.gitplex.core.comment;++import java.io.Serializable;+import java.util.Collection;+import java.util.Date;++import com.pmease.gitplex.core.model.Repository;+import com.pmease.gitplex.core.model.User;++public interface Comment extends Serializable {+ User getUser();++ Date getDate();++ String getContent();++ void saveContent(String content);++ Repository getRepository();++ void delete();++ Collection<? extends CommentReply> getReplies();++ CommentReply addReply(String content);+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.javadeleted file mode 100644index 3382626345..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentAwareChange.java+++ /dev/null@@ -1,283 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.ArrayList;-import java.util.HashMap;-import java.util.HashSet;-import java.util.Iterator;-import java.util.List;-import java.util.Map;-import java.util.Map.Entry;-import java.util.Set;--import javax.annotation.Nullable;--import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.RevAwareChange;-import com.pmease.commons.hibernate.dao.Dao;-import com.pmease.commons.util.Pair;-import com.pmease.commons.util.diff.DiffUtils;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;--@SuppressWarnings("serial")-public class CommentAwareChange extends RevAwareChange {-- private Map<Integer, List<CommitComment>> oldComments;-- private Map<Integer, List<CommitComment>> newComments;-- private final CommitComment concernedComment;-- public CommentAwareChange(RevAwareChange change, List<String> commits,- CommentLoader commentLoader, BlobLoader blobLoader,- CommitComment concernedComment) {- super(change);-- this.concernedComment = concernedComment;-- Map<String, Map<String, List<CommitComment>>> comments = new HashMap<>();- Map<BlobInfo, List<String>> blobs = new HashMap<>();-- int end = -1;- if (change.getNewPath() != null) {- end = commits.indexOf(change.getNewRevision());- if (end != -1 && getBlob(blobs, change.getNewBlobInfo(), blobLoader).isEmpty())- end = -1;- }-- int begin = -1;- if (change.getOldPath() != null) {- begin = commits.indexOf(change.getOldRevision());- if (begin != -1 && getBlob(blobs, change.getOldBlobInfo(), blobLoader).isEmpty())- begin = -1;- }-- if (end != -1) {- newComments = new HashMap<>();-- for (int i=end-1; i>begin; i--) {- String commit = commits.get(i);- Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);- BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());- if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());- } else {- commentsOnFile = commentsOnCommit.get(change.getOldPath());- if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());- }-- if (blobInfo != null) {- List<String> fileContent = getBlob(blobs, blobInfo, blobLoader);- if (!fileContent.isEmpty()) {- List<String> newContent = getBlob(blobs, change.getNewBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);- for (CommitComment comment: commentsOnFile) {- Integer lineNo = lineMap.get(comment.getPosition().getLineNo());- if (lineNo != null)- addLineComment(newComments, lineNo, comment);- }- }- }- }-- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), commentLoader).get(change.getNewPath());- if (commentsOnFile != null) {- for (CommitComment comment: commentsOnFile)- addLineComment(newComments, comment.getPosition().getLineNo(), comment);- }- }-- if (begin != -1) {- oldComments = new HashMap<>();-- Set<CommentKey> appliedComments = new HashSet<>();- if (newComments != null) {- for (List<CommitComment> list: newComments.values()) {- for (CommitComment comment: list)- appliedComments.add(new CommentKey(comment.getCommit(), comment.getPosition()));- }- }-- for (int i=begin+1; i<(end!=-1?end:commits.size()); i++) {- String commit = commits.get(i);- Map<String, List<CommitComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, commentLoader);- BlobInfo blobInfo = null;- List<CommitComment> commentsOnFile = commentsOnCommit.get(change.getOldPath());- if (commentsOnFile != null) {- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());- } else {- commentsOnFile = commentsOnCommit.get(change.getNewPath());- if (commentsOnFile != null)- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());- }-- if (blobInfo != null) {- boolean allApplied = true;- for (CommitComment comment: commentsOnFile) {- CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());- if (!appliedComments.contains(key)) {- allApplied = false;- break;- }- }- if (!allApplied) {- List<String> fileContent = blobLoader.loadBlob(blobInfo);- if (!fileContent.isEmpty()) {- List<String> oldContent = getBlob(blobs, change.getOldBlobInfo(), blobLoader);- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);- for (CommitComment comment: commentsOnFile) {- CommentKey key = new CommentKey(comment.getCommit(), comment.getPosition());- Integer lineNo = lineMap.get(comment.getPosition().getLineNo());- if (!appliedComments.contains(key) && lineNo != null)- addLineComment(oldComments, lineNo, comment);- }- }- }- }- }-- List<CommitComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), commentLoader).get(change.getOldPath());- if (commentsOnFile != null) {- for (CommitComment comment: commentsOnFile)- addLineComment(oldComments, comment.getPosition().getLineNo(), comment);- }- }-- }-- private void addLineComment(Map<Integer, List<CommitComment>> comments, int lineNo, CommitComment comment) {- List<CommitComment> commentsOnLine = comments.get(lineNo);- if (commentsOnLine == null) {- commentsOnLine = new ArrayList<>();- comments.put(lineNo, commentsOnLine);- }- commentsOnLine.add(comment);- }-- private Map<String, List<CommitComment>> getCommentsOnCommit(Map<String, Map<String, List<CommitComment>>> comments,- String commit, CommentLoader commentLoader) {- Map<String, List<CommitComment>> commentsOnCommit = comments.get(commit);- if (commentsOnCommit == null) {- commentsOnCommit = new HashMap<>();- for (CommitComment each: commentLoader.loadComments(commit)) {- if (each.getPosition() != null && each.getPosition().getLineNo() != null) {- List<CommitComment> commentsOnFile = commentsOnCommit.get(each.getPosition().getFilePath());- if (commentsOnFile == null) {- commentsOnFile = new ArrayList<>();- commentsOnCommit.put(each.getPosition().getFilePath(), commentsOnFile);- }- commentsOnFile.add(each);- }- }- comments.put(commit, commentsOnCommit);- }- return commentsOnCommit;- }-- @Nullable- public Map<Integer, List<CommitComment>> getOldComments() {- return oldComments;- }-- @Nullable- public Map<Integer, List<CommitComment>> getNewComments() {- return newComments;- }-- private List<String> getBlob(Map<BlobInfo, List<String>> blobs, BlobInfo blobInfo, BlobLoader blobLoader) {- List<String> blob = blobs.get(blobInfo);- if (blob == null) {- blob = blobLoader.loadBlob(blobInfo);- if (blob == null)- blob = new ArrayList<>();- blobs.put(blobInfo, blob);- }- return blob;- }-- public CommitComment getConcernedComment() {- return concernedComment;- }-- public boolean contains(CommitComment comment) {- if (oldComments != null) {- for (List<CommitComment> lineComments: oldComments.values()) {- for (CommitComment lineComment: lineComments) {- if (lineComment.equals(comment))- return true;- }- }- }- if (newComments != null) {- for (List<CommitComment> lineComments: newComments.values()) {- for (CommitComment lineComment: lineComments) {- if (lineComment.equals(comment))- return true;- }- }- }- return false;- }-- public void saveComment(CommitComment comment) {- boolean isNew = comment.isNew();- GitPlex.getInstance(Dao.class).persist(comment);-- if (isNew) {- if (oldComments != null && (comment.getCommit().equals(getOldRevision()) || contains(oldComments, comment.getCommit())))- addComment(oldComments, comment);- if (newComments != null && (comment.getCommit().equals(getNewRevision()) || contains(newComments, comment.getCommit())))- addComment(newComments, comment);- }- }-- private boolean contains(Map<Integer, List<CommitComment>> comments, String commit) {- for (List<CommitComment> lineComments: comments.values()) {- for (CommitComment lineComment: lineComments) {- if (lineComment.getCommit().equals(commit))- return true;- }- }- return false;- }-- public void removeComment(CommitComment comment) {- GitPlex.getInstance(Dao.class).remove(comment);-- if (oldComments != null)- removeComment(oldComments, comment);- if (newComments != null )- removeComment(newComments, comment);- }-- private void removeComment(Map<Integer, List<CommitComment>> comments, CommitComment comment) {- for (Iterator<Entry<Integer, List<CommitComment>>> it = comments.entrySet().iterator(); it.hasNext();) {- Entry<Integer, List<CommitComment>> entry = it.next();- entry.getValue().remove(comment);- if (entry.getValue().isEmpty())- it.remove();- }- }-- private void addComment(Map<Integer, List<CommitComment>> comments, CommitComment comment) {- int lineNo = comment.getPosition().getLineNo();- List<CommitComment> lineComments = comments.get(lineNo);- if (lineComments == null) {- lineComments = new ArrayList<>();- comments.put(lineNo, lineComments);- }- lineComments.add(comment);- }-- private static class CommentKey extends Pair<String, CommentPosition> {-- public CommentKey(String commit, CommentPosition position) {- super(commit, position);- }-- }--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.javadeleted file mode 100644index b82edabbfb..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentLoader.java+++ /dev/null@@ -1,20 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.List;--import com.pmease.gitplex.core.model.CommitComment;--public interface CommentLoader {- /**- * Load list of comments on specified commit, ordered by comment id.- *- * @param commit- * commit to load comments for- * @return- * list of commit comments on specified commit ordered by comment id,- * including comments on commit itself, comments on files in the commit,- * and comments on file lines in the commit. Empty list should be- * returned if there are no any comments on specified commit- */- List<CommitComment> loadComments(String commit);-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentReply.javanew file mode 100644index 0000000000..83f201b928--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentReply.java@@ -0,0 +1,20 @@+package com.pmease.gitplex.core.comment;++import java.io.Serializable;+import java.util.Date;++import com.pmease.gitplex.core.model.User;++public interface CommentReply extends Serializable {+ Comment getComment();++ User getUser();++ Date getDate();++ String getContent();++ void saveContent(String content);++ void delete();+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.javadeleted file mode 100644index beb453a143..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/CommentThread.java+++ /dev/null@@ -1,64 +0,0 @@-package com.pmease.gitplex.core.comment;--import java.util.ArrayList;-import java.util.Collections;-import java.util.HashMap;-import java.util.List;-import java.util.Map;--import javax.annotation.Nullable;--import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;--public class CommentThread implements Comparable<CommentThread> {-- private final CommentPosition position;-- private final List<CommitComment> comments;-- public CommentThread(@Nullable CommentPosition position, List<CommitComment> comments) {- this.position = position;- this.comments = comments;- }-- public CommentPosition getPosition() {- return position;- }-- public List<CommitComment> getComments() {- return comments;- }-- public CommitComment getFirstComment() {- return comments.get(0);- }-- public CommitComment getLastComment() {- return comments.get(comments.size()-1);- }-- @Override- public int compareTo(CommentThread o) {- return getLastComment().getId().compareTo(o.getLastComment().getId());- }-- public static List<CommentThread> asThreads(List<CommitComment> comments) {- Map<CommentPosition, List<CommitComment>> threadMap = new HashMap<>();- for (CommitComment comment: comments) {- List<CommitComment> threadComments = threadMap.get(comment.getPosition());- if (threadComments == null) {- threadComments = new ArrayList<>();- threadMap.put(comment.getPosition(), threadComments);- }- threadComments.add(comment);- }-- List<CommentThread> threads = new ArrayList<>();- for (Map.Entry<CommentPosition, List<CommitComment>> entry: threadMap.entrySet())- threads.add(new CommentThread(entry.getKey(), entry.getValue()));-- Collections.sort(threads);- return threads;- }-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineComment.javanew file mode 100644index 0000000000..1708c8d161--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineComment.java@@ -0,0 +1,8 @@+package com.pmease.gitplex.core.comment;++public interface LineComment extends Comment {++ String getCommit();++ int getLine();+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineCommentContext.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineCommentContext.javanew file mode 100644index 0000000000..a275ec6eb2--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/LineCommentContext.java@@ -0,0 +1,14 @@+package com.pmease.gitplex.core.comment;++import java.util.Map;++public interface LineCommentContext {++ Map<Integer, LineComment> getOldComments();++ Map<Integer, LineComment> getNewComments();++ LineComment addComment(String commit, String file, int line, String content);++ LineComment getConcernedComment();+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/AuthorizationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/AuthorizationManager.javaindex 993da234f7..c2f8c85053 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/AuthorizationManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/AuthorizationManager.java@@ -3,8 +3,8 @@ package com.pmease.gitplex.core.manager;import java.util.Collection;import com.google.inject.ImplementedBy;+import com.pmease.gitplex.core.comment.Comment;import com.pmease.gitplex.core.manager.impl.DefaultAuthorizationManager;-import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@@ -20,5 +20,5 @@ public interface AuthorizationManager {boolean canModify(Vote vote);- boolean canModify(CommitComment comment);+ boolean canModify(Comment comment);}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.javadeleted file mode 100644index a8c03f7dfb..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommentVisitManager.java+++ /dev/null@@ -1,42 +0,0 @@-package com.pmease.gitplex.core.manager;--import java.util.Date;-import java.util.List;--import javax.annotation.Nullable;--import com.google.inject.ImplementedBy;-import com.pmease.gitplex.core.manager.impl.DefaultCommentVisitManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommentVisit;-import com.pmease.gitplex.core.model.CommitComment;-import com.pmease.gitplex.core.model.Repository;-import com.pmease.gitplex.core.model.User;--@ImplementedBy(DefaultCommentVisitManager.class)-public interface CommentVisitManager {-- /**- * Find comment visits by specified commit date range.- *- * @param repository- * repository to find comment inside- * @param fromDate- * from date of associated commit- * @param toDate- * to date of associated commit- * @return- * list of found comment visits- */- List<CommentVisit> findByCommitDates(Repository repository, User user,- @Nullable Date fromDate, @Nullable Date toDate);-- List<CommentVisit> findByCommitOrDates(Repository repository, User user,- String commit, @Nullable Date fromDate, @Nullable Date toDate);-- CommentVisit find(Repository repository, User user,- String commit, @Nullable CommentPosition position);-- void visitComment(Repository repository, User user, CommitComment comment);--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.javanew file mode 100644index 0000000000..de43a271fe--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java@@ -0,0 +1,16 @@+package com.pmease.gitplex.core.manager;++import java.util.List;++import com.google.inject.ImplementedBy;+import com.pmease.commons.git.RevAwareChange;+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestCommentManager;+import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.PullRequestComment;++@ImplementedBy(DefaultPullRequestCommentManager.class)+public interface PullRequestCommentManager {++ List<PullRequestComment> findByChange(PullRequest request, RevAwareChange change);++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuthorizationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuthorizationManager.javaindex 262c0c4ae5..43a7931a23 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuthorizationManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuthorizationManager.java@@ -9,12 +9,12 @@ import javax.inject.Singleton;import org.apache.shiro.SecurityUtils;-import com.pmease.commons.hibernate.dao.EntityCriteria;import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.hibernate.dao.EntityCriteria;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.comment.Comment;import com.pmease.gitplex.core.manager.AuthorizationManager;import com.pmease.gitplex.core.manager.UserManager;-import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@@ -67,7 +67,7 @@ public class DefaultAuthorizationManager implements AuthorizationManager {}@Override- public boolean canModify(CommitComment comment) {+ public boolean canModify(Comment comment) {User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();if (currentUser == null) {return false;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.javadeleted file mode 100644index 601afd09c0..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommentVisitManager.java+++ /dev/null@@ -1,89 +0,0 @@-package com.pmease.gitplex.core.manager.impl;--import java.util.Date;-import java.util.List;--import javax.inject.Inject;-import javax.inject.Singleton;--import org.hibernate.criterion.Conjunction;-import org.hibernate.criterion.Order;-import org.hibernate.criterion.Restrictions;--import com.pmease.commons.hibernate.dao.Dao;-import com.pmease.commons.hibernate.dao.EntityCriteria;-import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.manager.CommentVisitManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommentVisit;-import com.pmease.gitplex.core.model.CommitComment;-import com.pmease.gitplex.core.model.Repository;-import com.pmease.gitplex.core.model.User;--@Singleton-public class DefaultCommentVisitManager implements CommentVisitManager {-- private final Dao dao;-- @Inject- public DefaultCommentVisitManager(Dao dao) {- this.dao = dao;- }-- @Override- public List<CommentVisit> findByCommitDates(Repository repository, User user,- Date fromDate, Date toDate) {- EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- criteria.add(Restrictions.eq("user", user));- criteria.add(Restrictions.eq("repository", repository));- if (fromDate != null)- criteria.add(Restrictions.ge("commitDate", fromDate));- if (toDate != null)- criteria.add(Restrictions.le("commitDate", toDate));- criteria.addOrder(Order.asc("id"));- return dao.query(criteria, 0, 0);- }-- @Override- public List<CommentVisit> findByCommitOrDates(Repository repository, User user,- String commit, Date fromDate, Date toDate) {- EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- criteria.add(Restrictions.eq("user", user));- criteria.add(Restrictions.eq("repository", repository));- Conjunction conjunction = Restrictions.conjunction();- if (fromDate != null)- conjunction.add(Restrictions.ge("commitDate", fromDate));- if (toDate != null)- conjunction.add(Restrictions.le("commitDate", toDate));- criteria.add(Restrictions.or(Restrictions.eq("commit", commit), conjunction));- criteria.addOrder(Order.asc("id"));- return dao.query(criteria, 0, 0);- }-- @Override- public CommentVisit find(Repository repository, User user, String commit, CommentPosition position) {- EntityCriteria<CommentVisit> criteria = EntityCriteria.of(CommentVisit.class);- criteria.add(Restrictions.eq("user", user));- criteria.add(Restrictions.eq("repository", repository));- criteria.add(Restrictions.eq("commit", commit));- criteria.add(Restrictions.eq("position", position));-- return dao.find(criteria);- }-- @Override- public void visitComment(Repository repository, User user, CommitComment comment) {- CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);- CommentVisit visit = manager.find(repository, user, comment.getCommit(), comment.getPosition());- if (visit == null) {- visit = new CommentVisit();- visit.setCommit(comment.getCommit());- visit.setCommitDate(repository.getCommit(comment.getCommit()).getCommitter().getWhen());- visit.setPosition(comment.getPosition());- visit.setRepository(repository);- visit.setUser(user);- }- visit.setVisitDate(comment.getCommentDate());- GitPlex.getInstance(Dao.class).persist(visit);- }-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.javanew file mode 100644index 0000000000..aa35902c74--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java@@ -0,0 +1,58 @@+package com.pmease.gitplex.core.manager.impl;++import static com.pmease.commons.git.Change.Status.ADDED;+import static com.pmease.commons.git.Change.Status.DELETED;++import java.util.List;++import javax.inject.Inject;+import javax.inject.Singleton;++import org.hibernate.criterion.Conjunction;+import org.hibernate.criterion.Restrictions;++import com.google.common.base.Preconditions;+import com.pmease.commons.git.GitUtils;+import com.pmease.commons.git.RevAwareChange;+import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.hibernate.dao.EntityCriteria;+import com.pmease.gitplex.core.manager.PullRequestCommentManager;+import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.PullRequestComment;++@Singleton+public class DefaultPullRequestCommentManager implements PullRequestCommentManager {++ private final Dao dao;++ @Inject+ public DefaultPullRequestCommentManager(Dao dao) {+ this.dao = dao;+ }++ @Override+ public List<PullRequestComment> findByChange(PullRequest request, RevAwareChange change) {+ Preconditions.checkArgument(GitUtils.isHash(change.getOldRevision()));+ Preconditions.checkArgument(GitUtils.isHash(change.getNewRevision()));+ EntityCriteria<PullRequestComment> criteria = EntityCriteria.of(PullRequestComment.class);+ criteria.add(Restrictions.eq("request", request));++ Conjunction oldConj = Restrictions.conjunction();+ oldConj.add(Restrictions.eq("inlineInfo.commit", change.getOldRevision()));+ oldConj.add(Restrictions.eq("inlineInfo.file", change.getOldPath()));++ Conjunction newConj = Restrictions.conjunction();+ oldConj.add(Restrictions.eq("inlineInfo.commit", change.getNewRevision()));+ oldConj.add(Restrictions.eq("inlineInfo.file", change.getNewPath()));++ if (change.getStatus() == ADDED)+ criteria.add(oldConj);+ else if (change.getStatus() == DELETED)+ criteria.add(newConj);+ else+ criteria.add(Restrictions.or(oldConj, newConj));++ return dao.query(criteria);+ }++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.javadeleted file mode 100644index b65f223255..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentVisit.java+++ /dev/null@@ -1,92 +0,0 @@-package com.pmease.gitplex.core.model;--import java.util.Date;--import javax.annotation.Nullable;-import javax.persistence.Column;-import javax.persistence.Embedded;-import javax.persistence.Entity;-import javax.persistence.JoinColumn;-import javax.persistence.ManyToOne;-import javax.persistence.Table;-import javax.persistence.UniqueConstraint;--import com.pmease.commons.hibernate.AbstractEntity;--@SuppressWarnings("serial")-@Entity-@Table(uniqueConstraints={- @UniqueConstraint(columnNames={"user", "repository", "commit", "filePath", "lineNo"})-})-public class CommentVisit extends AbstractEntity {-- @ManyToOne- @JoinColumn(nullable=false)- private Repository repository;-- @Column(nullable=false)- private String commit;-- @Column(nullable=false)- private Date commitDate;-- @ManyToOne- @JoinColumn(nullable=false)- private User user;-- @Column(nullable=false)- private Date visitDate = new Date();-- @Embedded- private CommentPosition position;-- public Repository getRepository() {- return repository;- }-- public void setRepository(Repository repository) {- this.repository = repository;- }-- public User getUser() {- return user;- }-- public void setUser(User user) {- this.user = user;- }-- public Date getVisitDate() {- return visitDate;- }-- public void setVisitDate(Date date) {- this.visitDate = date;- }-- public String getCommit() {- return commit;- }-- public void setCommit(String commit) {- this.commit = commit;- }-- public Date getCommitDate() {- return commitDate;- }-- public void setCommitDate(Date commitDate) {- this.commitDate = commitDate;- }-- @Nullable- public CommentPosition getPosition() {- return position;- }-- public void setPosition(@Nullable CommentPosition position) {- this.position = position;- }--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineComment.javadeleted file mode 100644index c2e6a3f0bb..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineComment.java+++ /dev/null@@ -1,139 +0,0 @@-package com.pmease.gitplex.core.model;--import java.util.ArrayList;-import java.util.Collection;-import java.util.Date;-import java.util.List;--import javax.persistence.CascadeType;-import javax.persistence.Column;-import javax.persistence.Entity;-import javax.persistence.JoinColumn;-import javax.persistence.Lob;-import javax.persistence.ManyToOne;-import javax.persistence.OneToMany;-import javax.persistence.Table;-import javax.persistence.UniqueConstraint;--import com.pmease.commons.hibernate.AbstractEntity;-import com.pmease.commons.util.diff.DiffLine;--@SuppressWarnings("serial")-@Entity-@Table(uniqueConstraints={- @UniqueConstraint(columnNames={"request", "commit", "file", "line"})-})-public class InlineComment extends AbstractEntity {-- @ManyToOne- @JoinColumn(nullable=false)- private PullRequest request;-- @ManyToOne- @JoinColumn(nullable=false)- private User user;-- @Column(nullable=false)- private String commit;-- @Column(nullable=false)- private String file;-- private int line;-- @Column(nullable=false)- @Lob- private List<DiffLine> context;-- @Column(nullable=false)- private String content;-- @Column(nullable=false)- private Date date;-- private boolean resolved;-- @OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)- private Collection<InlineCommentReply> replies = new ArrayList<>();-- public PullRequest getRequest() {- return request;- }-- public void setRequest(PullRequest request) {- this.request = request;- }-- public User getUser() {- return user;- }-- public void setUser(User user) {- this.user = user;- }-- public String getCommit() {- return commit;- }-- public void setCommit(String commit) {- this.commit = commit;- }-- public String getFile() {- return file;- }-- public void setFile(String file) {- this.file = file;- }-- public int getLine() {- return line;- }-- public void setLine(int line) {- this.line = line;- }-- public String getContent() {- return content;- }-- public void setContent(String content) {- this.content = content;- }-- public Date getDate() {- return date;- }-- public void setDate(Date date) {- this.date = date;- }-- public List<DiffLine> getContext() {- return context;- }-- public void setContext(List<DiffLine> context) {- this.context = context;- }-- public boolean isResolved() {- return resolved;- }-- public void setResolved(boolean resolved) {- this.resolved = resolved;- }-- public Collection<InlineCommentReply> getReplies() {- return replies;- }-- public void setReplies(Collection<InlineCommentReply> replies) {- this.replies = replies;- }--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.javanew file mode 100644index 0000000000..ee830618fb--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java@@ -0,0 +1,66 @@+package com.pmease.gitplex.core.model;++import java.io.Serializable;+import java.util.List;++import javax.persistence.Embeddable;+import javax.persistence.Lob;++import com.pmease.commons.util.diff.DiffLine;++@SuppressWarnings("serial")+@Embeddable+public class InlineInfo implements Serializable {++ private String commit;++ private String file;++ private Integer line;++ @Lob+ private List<DiffLine> context;++ private String compareCommit;++ public String getCommit() {+ return commit;+ }++ public void setCommit(String commit) {+ this.commit = commit;+ }++ public String getFile() {+ return file;+ }++ public void setFile(String file) {+ this.file = file;+ }++ public Integer getLine() {+ return line;+ }++ public void setLine(Integer line) {+ this.line = line;+ }++ public List<DiffLine> getContext() {+ return context;+ }++ public void setContext(List<DiffLine> context) {+ this.context = context;+ }++ public String getCompareCommit() {+ return compareCommit;+ }++ public void setCompareCommit(String compareCommit) {+ this.compareCommit = compareCommit;+ }++}\ No newline at end of filediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.javaindex 072ee320d6..101cbdf4b6 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java@@ -5,10 +5,8 @@ import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.Date;-import java.util.HashMap;import java.util.HashSet;import java.util.List;-import java.util.Map;import java.util.Set;import java.util.concurrent.Callable;@@ -31,16 +29,12 @@ import com.pmease.commons.git.Commit;import com.pmease.commons.git.Git;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.util.LockUtils;-import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.gatekeeper.checkresult.Approved;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Disapproved;import com.pmease.gitplex.core.gatekeeper.checkresult.Ignored;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;-import com.pmease.gitplex.core.manager.CommentVisitManager;-import com.pmease.gitplex.core.manager.CommitCommentManager;-import com.pmease.gitplex.core.manager.UserManager;@SuppressWarnings("serial")@Entity@@ -114,10 +108,7 @@ public class PullRequest extends AbstractEntity {private Collection<Verification> verifications = new ArrayList<>();@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)- private Collection<PullRequestComment> requestComments = new ArrayList<>();-- @OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)- private Collection<InlineComment> inlineComments = new ArrayList<>();+ private Collection<PullRequestComment> comments = new ArrayList<>();@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)private Collection<PullRequestAudit> audits = new ArrayList<>();@@ -130,12 +121,6 @@ public class PullRequest extends AbstractEntity {private transient Set<String> pendingCommits;- private transient Map<String, List<CommitComment>> commitComments;-- private transient Map<String, Map<CommentPosition, Date>> commentVisits;-- private transient List<String> commits;-/*** Get title of this merge request.*@@ -261,20 +246,12 @@ public class PullRequest extends AbstractEntity {this.verifications = verifications;}- public Collection<PullRequestComment> getRequestComments() {- return requestComments;- }-- public void setRequestComments(Collection<PullRequestComment> requestComments) {- this.requestComments = requestComments;+ public Collection<PullRequestComment> getComments() {+ return comments;}- public Collection<InlineComment> getInlineComments() {- return inlineComments;- }-- public void setInlineComments(Collection<InlineComment> inlineComments) {- this.inlineComments = inlineComments;+ public void setComments(Collection<PullRequestComment> comments) {+ this.comments = comments;}public Collection<PullRequestAudit> getAudits() {@@ -548,68 +525,4 @@ public class PullRequest extends AbstractEntity {&& getIntegrationInfo().getIntegrationHead() != null;}- public Map<String, List<CommitComment>> getCommitComments() {- if (commitComments == null) {- commitComments = new HashMap<>();- Map<String, Date> commits = new HashMap<>();- for (PullRequestUpdate update: updates) {- for (Commit commit: update.getCommits())- commits.put(commit.getHash(), commit.getCommitter().getWhen());- }- CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);- for (CommitComment comment: manager.findByCommitOrDates(getTarget().getRepository(),- getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {- if (comment.getCommit().equals(getBaseCommit()) || commits.containsKey(comment.getCommit())) {- List<CommitComment> comments = commitComments.get(comment.getCommit());- if (comments == null) {- comments = new ArrayList<>();- commitComments.put(comment.getCommit(), comments);- }- comments.add(comment);- }- }- }- return commitComments;- }-- public Map<String, Map<CommentPosition, Date>> getCommentVisits() {- if (commentVisits == null) {- commentVisits = new HashMap<>();-- User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();- if (currentUser != null) {- Map<String, Date> commits = new HashMap<>();- for (PullRequestUpdate update: updates) {- for (Commit commit: update.getCommits())- commits.put(commit.getHash(), commit.getCommitter().getWhen());- }- CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);- for (CommentVisit visit: manager.findByCommitOrDates(getTarget().getRepository(), currentUser,- getBaseCommit(), Collections.min(commits.values()), Collections.max(commits.values()))) {- if (visit.getCommit().equals(getBaseCommit()) || commits.containsKey(visit.getCommit())) {- Map<CommentPosition, Date> visits = commentVisits.get(visit.getCommit());- if (visits == null) {- visits = new HashMap<>();- commentVisits.put(visit.getCommit(), visits);- }- visits.put(visit.getPosition(), visit.getVisitDate());- }- }- }- }- return commentVisits;- }-- public List<String> getCommits() {- if (commits == null) {- commits = new ArrayList<>();- commits.add(getBaseCommit());- for (int i=getSortedUpdates().size()-1; i>=0; i--) {- for (Commit commit: getSortedUpdates().get(i).getCommits())- commits.add(commit.getHash());- }- }- return commits;- }-}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.javaindex 88b7195f66..8b883dcf19 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java@@ -1,17 +1,32 @@package com.pmease.gitplex.core.model;+import java.util.ArrayList;+import java.util.Collection;import java.util.Date;+import javax.persistence.CascadeType;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;+import javax.persistence.OneToMany;+import javax.persistence.Table;+import javax.persistence.UniqueConstraint;+import com.google.common.base.Preconditions;import com.pmease.commons.hibernate.AbstractEntity;+import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.comment.CommentReply;+import com.pmease.gitplex.core.comment.LineComment;+import com.pmease.gitplex.core.manager.UserManager;@SuppressWarnings("serial")@Entity-public class PullRequestComment extends AbstractEntity {+@Table(uniqueConstraints={+ @UniqueConstraint(columnNames={"commit", "file", "line"})+})+public class PullRequestComment extends AbstractEntity implements LineComment {@ManyToOne@JoinColumn(nullable=false)@@ -26,6 +41,11 @@ public class PullRequestComment extends AbstractEntity {@Column(nullable=false)private Date date = new Date();++ private InlineInfo inlineInfo;++ @OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)+ private Collection<PullRequestCommentReply> replies = new ArrayList<>();public PullRequest getRequest() {return request;@@ -58,5 +78,61 @@ public class PullRequestComment extends AbstractEntity {public void setDate(Date date) {this.date = date;}-++ public InlineInfo getInlineInfo() {+ return inlineInfo;+ }++ public void setInlineInfo(InlineInfo inlineInfo) {+ this.inlineInfo = inlineInfo;+ }++ @Override+ public Collection<PullRequestCommentReply> getReplies() {+ return replies;+ }++ public void setReplies(Collection<PullRequestCommentReply> replies) {+ this.replies = replies;+ }++ @Override+ public void saveContent(String content) {+ setContent(content);+ GitPlex.getInstance(Dao.class).persist(this);+ }++ @Override+ public Repository getRepository() {+ return request.getTarget().getRepository();+ }++ @Override+ public void delete() {+ GitPlex.getInstance(Dao.class).remove(this);+ }++ @Override+ public CommentReply addReply(String content) {+ User user = GitPlex.getInstance(UserManager.class).getCurrent();+ Preconditions.checkNotNull(user);+ PullRequestCommentReply reply = new PullRequestCommentReply();+ reply.setUser(user);+ reply.setDate(new Date());+ reply.setContent(content);+ reply.setComment(this);+ GitPlex.getInstance(Dao.class).persist(reply);+ return reply;+ }++ @Override+ public int getLine() {+ return Preconditions.checkNotNull(inlineInfo).getLine();+ }++ @Override+ public String getCommit() {+ return Preconditions.checkNotNull(inlineInfo).getCommit();+ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.javasimilarity index 53%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineCommentReply.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.javaindex a1f0b7b35d..a2a899dc51 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineCommentReply.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java@@ -2,31 +2,40 @@ package com.pmease.gitplex.core.model;import java.util.Date;-import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.JoinColumn;import javax.persistence.ManyToOne;import com.pmease.commons.hibernate.AbstractEntity;+import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.comment.CommentReply;@SuppressWarnings("serial")@Entity-public class InlineCommentReply extends AbstractEntity {+public class PullRequestCommentReply extends AbstractEntity implements CommentReply {@ManyToOne@JoinColumn(nullable=false)- private InlineComment comment;-+ private PullRequestComment comment;+@ManyToOne@JoinColumn(nullable=false)private User user;-- @Column(nullable=false)+private Date date;- @Column(nullable=false)private String content;+ @Override+ public PullRequestComment getComment() {+ return comment;+ }++ public void setComment(PullRequestComment comment) {+ this.comment = comment;+ }+public User getUser() {return user;}@@ -50,5 +59,16 @@ public class InlineCommentReply extends AbstractEntity {public void setContent(String content) {this.content = content;}++ @Override+ public void saveContent(String content) {+ setContent(content);+ GitPlex.getInstance(Dao.class).persist(this);+ }++ @Override+ public void delete() {+ GitPlex.getInstance(Dao.class).remove(this);+ }}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.javaindex c958fdd35f..4b4e3b3117 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java@@ -89,9 +89,6 @@ public class Repository extends AbstractEntity implements UserBelonging {@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)private Collection<CommitComment> commitComments = new ArrayList<>();- @OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)- private Collection<CommentVisit> threadVisits = new ArrayList<>();-@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)private Collection<Branch> branches = new ArrayList<>();@@ -193,14 +190,6 @@ public class Repository extends AbstractEntity implements UserBelonging {this.commitComments = commitComments;}- public Collection<CommentVisit> getThreadVisits() {- return threadVisits;- }-- public void setThreadVisits(Collection<CommentVisit> threadVisits) {- this.threadVisits = threadVisits;- }-public Repository getForkedFrom() {return forkedFrom;}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.javaindex 3665086ee6..4177388b7f 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java@@ -42,9 +42,6 @@ public class User extends AbstractUser implements ProtectedObject {@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)private Collection<CommitComment> commitComments = new ArrayList<>();- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)- private Collection<CommentVisit> commentVisits = new ArrayList<>();-@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)private Collection<Membership> memberships = new ArrayList<>();@@ -70,10 +67,7 @@ public class User extends AbstractUser implements ProtectedObject {private Collection<PullRequestComment> requestComments = new ArrayList<>();@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)- private Collection<InlineComment> inlineComments = new ArrayList<>();-- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)- private Collection<InlineCommentReply> commentReplies = new ArrayList<>();+ private Collection<PullRequestCommentReply> requestCommentReplies = new ArrayList<>();@Editable(order=100)@UserName@@ -135,14 +129,6 @@ public class User extends AbstractUser implements ProtectedObject {this.commitComments = commitComments;}- public Collection<CommentVisit> getCommentVisits() {- return commentVisits;- }-- public void setCommentVisits(Collection<CommentVisit> commentVisits) {- this.commentVisits = commentVisits;- }-public Collection<Membership> getMemberships() {return memberships;}@@ -213,20 +199,12 @@ public class User extends AbstractUser implements ProtectedObject {this.requestComments = requestComments;}- public Collection<InlineComment> getInlineComments() {- return inlineComments;- }-- public void setInlineComments(Collection<InlineComment> inlineComments) {- this.inlineComments = inlineComments;- }-- public Collection<InlineCommentReply> getCommentReplies() {- return commentReplies;+ public Collection<PullRequestCommentReply> getRequestCommentReplies() {+ return requestCommentReplies;}- public void setCommentReplies(Collection<InlineCommentReply> commentReplies) {- this.commentReplies = commentReplies;+ public void setCommentReplies(Collection<PullRequestCommentReply> requestCommentReplies) {+ this.requestCommentReplies = requestCommentReplies;}@Overridediff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.javadeleted file mode 100644index 046d3509fb..0000000000--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/CommentAwareChangeTest.java+++ /dev/null@@ -1,199 +0,0 @@-package com.pmease.gitplex.core.comment;--import static org.junit.Assert.assertEquals;--import java.io.ByteArrayInputStream;-import java.io.IOException;-import java.util.ArrayList;-import java.util.List;--import org.apache.commons.io.IOUtils;-import org.junit.Test;--import com.pmease.commons.git.AbstractGitTest;-import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.Change;-import com.pmease.commons.git.Commit;-import com.pmease.commons.git.RevAwareChange;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;--public class CommentAwareChangeTest extends AbstractGitTest {-- @Test- public void test() {- final List<String> fileRevs = new ArrayList<>();- fileRevs.add(""- + "11\n" //comment1- + "22\n"- + "33\n"- + "44\n"- + "55\n" //comment3, comment6- + "66\n"- + "77\n"- + "88\n" //comment4- + "99\n");- fileRevs.add(""- + "111\n"- + "222\n"- + "33\n"- + "44\n"- + "55\n"- + "66\n"- + "77\n"- + "88\n"- + "99\n");- fileRevs.add(""- + "111\n"- + "222\n"- + "33\n"- + "44\n"- + "55\n"- + "66\n"- + "77\n"- + "888\n"- + "999\n");- fileRevs.add(""- + "111\n"- + "222\n" //comment2- + "33\n"- + "44\n" //comment5- + "555\n"- + "66\n"- + "77\n"- + "8888\n"- + "999\n"); //comment8, comment9-- addFileAndCommit("file1", fileRevs.get(0), "add file1");-- addFileAndCommit("file1", fileRevs.get(1), "modify file1");-- addFileAndCommit("file1", fileRevs.get(2), "modify file1");-- addFileAndCommit("file1", fileRevs.get(3), "modify file1");-- final List<Commit> commits = new ArrayList<>();- commits.add(git.showRevision("master~3"));- commits.add(git.showRevision("master~2"));- commits.add(git.showRevision("master~1"));- commits.add(git.showRevision("master"));-- CommentLoader commentLoader = new CommentLoader() {-- @Override- public List<CommitComment> loadComments(String commit) {- List<CommitComment> comments = new ArrayList<>();-- List<String> commitHashes = new ArrayList<>();- for (Commit each: commits)- commitHashes.add(each.getHash());-- int index = commitHashes.indexOf(commit);- if (index == 0) {- CommitComment comment = new CommitComment();- comment.setId(1L);- comment.setCommit(commit);- comment.setContent("comment1");- comment.setPosition(new CommentPosition("file1", 0));- comments.add(comment);- } else if (index == 1) {- CommitComment comment = new CommitComment();- comment.setId(2L);- comment.setCommit(commit);- comment.setContent("comment2");- comment.setPosition(new CommentPosition("file1", 1));- comments.add(comment);-- comment = new CommitComment();- comment.setId(3L);- comment.setCommit(commit);- comment.setContent("comment3");- comment.setPosition(new CommentPosition("file1", 4));- comments.add(comment);-- comment = new CommitComment();- comment.setId(4L);- comment.setCommit(commit);- comment.setContent("comment4");- comment.setPosition(new CommentPosition("file1", 7));- comments.add(comment);- } else if (index == 2) {- CommitComment comment = new CommitComment();- comment.setId(5L);- comment.setCommit(commit);- comment.setContent("comment5");- comment.setPosition(new CommentPosition("file1", 3));- comments.add(comment);-- comment = new CommitComment();- comment.setId(6L);- comment.setCommit(commit);- comment.setContent("comment6");- comment.setPosition(new CommentPosition("file1", 4));- comments.add(comment);-- comment = new CommitComment();- comment.setId(7L);- comment.setCommit(commit);- comment.setContent("comment7");- comment.setPosition(new CommentPosition("file1", 7));- comments.add(comment);-- comment = new CommitComment();- comment.setId(8L);- comment.setCommit(commit);- comment.setContent("comment8");- comment.setPosition(new CommentPosition("file1", 8));- comments.add(comment);- } else if (index == 3) {- CommitComment comment = new CommitComment();- comment.setId(9L);- comment.setCommit(commit);- comment.setContent("comment9");- comment.setPosition(new CommentPosition("file1", 8));- comments.add(comment);- }- return comments;- }-- };-- BlobLoader fileLoader = new BlobLoader() {-- @Override- public List<String> loadBlob(BlobInfo blobInfo) {- List<String> commitHashes = new ArrayList<>();- for (Commit each: commits)- commitHashes.add(each.getHash());-- int index = commitHashes.indexOf(blobInfo.getRevision());- String content = fileRevs.get(index);- try {- return IOUtils.readLines(new ByteArrayInputStream(content.getBytes()));- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- };-- RevAwareChange change = new RevAwareChange(Change.Status.MODIFIED, "file1", "file1",- 0, 0, commits.get(0).getHash(), commits.get(3).getHash());-- List<String> commitHashes = new ArrayList<>();- for (Commit each: commits)- commitHashes.add(each.getHash());- CommentAwareChange commentAwareChange = new CommentAwareChange(change, commitHashes,- commentLoader, fileLoader, null);-- assertEquals("comment1", commentAwareChange.getOldComments().get(0).get(0).getContent());- assertEquals("comment2", commentAwareChange.getNewComments().get(1).get(0).getContent());- assertEquals("comment3", commentAwareChange.getOldComments().get(4).get(0).getContent());- assertEquals("comment4", commentAwareChange.getOldComments().get(7).get(0).getContent());- assertEquals("comment5", commentAwareChange.getNewComments().get(3).get(0).getContent());- assertEquals("comment6", commentAwareChange.getOldComments().get(4).get(1).getContent());- assertEquals("comment8", commentAwareChange.getNewComments().get(8).get(0).getContent());- assertEquals("comment9", commentAwareChange.getNewComments().get(8).get(1).getContent());- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.cssindex 96b31806f2..32591d5852 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css@@ -291,16 +291,6 @@ ul.f-dropdown { padding: 0; }#main>table>tbody>tr>td.sidebar .head > a { color: #666; font-weight:bold; line-height: 24px; }#main>table>tbody>tr>td.sidebar .head > a:hover { text-decoration: none; color: #09F; }--.head:before, .head:after {- display: table;- content: " ";-}--.head:after {- clear: both;-}-.content section > .head { border-style: solid; border-width: 1px 0; border-color: #ddd; margin-bottom: 0; position: relative; z-index: 10; overflow: visible; }section:first-child > .head { border-top: none; }section>.head h2, section>.head h3 { margin: 0; font-size: 18px; line-height: 24px; color: #6f6f6f; font-weight: 300; text-transform: uppercase; float: left; }@@ -796,23 +786,8 @@ h2.section-title { margin: 18px 0; font-size: 16px; }.table-diff .line.content:hover {background: #fea; }.table-diff .line.content:hover>td.line-no {background: #FBDE6D;}.table-diff table.content {width: 100%;}--.table-diff .line.comments>td {border-top: 1px solid #E5E5E5;- border-bottom: 1px solid #E5E5E5; padding: 12px 0;}-.table-diff .line.comments>td.summary {padding: 12px;}-.table-diff .line.comments>td.summary .fa-bookmark {margin-bottom: 12px; color: #3A88F6; font-size: 24px;}-.table-diff .line.comments>td.detail {padding: 12px;}-table.line-comments>tbody>tr>td {border-top: 1px dotted #BBB; padding-top: 12px;}-table.line-comments>tbody>tr:FIRST-CHILD>td {border-top: none; padding-top: 0;}-table.line-comments>tbody>tr>.avatar {width: 1%;}-table.line-comments>tbody>tr>.avatar img.avatar {width: 36px; height: 36px;}-table.line-comments>tbody>tr>.content {padding-left: 8px;}-table.line-comments>tbody>tr>.content>.head, table.line-comments>tbody>tr>.content>.head a {color: #888;}-table.line-comments>tbody>tr>.content>.head .pull-right {margin-left: 8px; font-size: 11px;}-table.line-comments>tbody>tr>.content>.head .pull-right i {font-size: 13px;}-table.line-comments>tbody>tr>.content>.head .name {font-weight: bold;}-table.line-comments>tbody>tr>.content>.body {margin: 12px 0 12px 0;}-.table-diff .concerned-comments {color: #E9CB43; font-size: 20px; margin-bottom: 12px;}+.table-diff .line.comments>td {padding: 0 12px 0 12px; border-top: 1px solid #DDD; border-bottom: 1px solid #DDD;}+.table-diff form.add-comment {margin: 8px;}.table-diff a.add-comment {position: absolute; left:0; margin-left: -20px;width: 20px; height: 20px; text-decoration: none;}@@ -843,11 +818,29 @@ ul.diff-alerts {padding-left: 12px;}.diff-stat .additions {color: #35c335; font-style: normal; }.diff-stat .deletions {color: #c33535; font-style: normal; }-/* COMMENT */+/* COMMENTS */.comment-input textarea {width: 100%; min-height: 80px;}.comment-input>.tab-pane {padding: 12px 0;}.comment-input>.tab-pane>.preview {display: none;}+div.comment>div.head, div.replies>table>tbody>tr>td.detail>div.head {color: #999; margin-bottom: 8px;}+div.comment>div.head a, div.replies>table>tbody>tr>td.detail>div.head a {color: #999;}+div.comment>div.head .fa, div.replies>table>tbody>tr>td.detail>div.head .fa {font-size: 13px;}+div.comment>div.head .actions, div.replies>table>tbody>tr>td.detail>div.head .actions {margin-left: 8px;}+div.comment>div.head .actions a, div.replies>table>tbody>tr>td.detail>div.head .actions a {margin-right: 4px;}+div.comment>div.head .actions a .fa-times,+div.replies>table>tbody>tr>td.detail>div.head .actions a .fa-times {font-size: 14px;}+div.comment>div.head .name a, div.replies>table>tbody>tr>td.detail>div.head .name a {color: #333; font-weight: bold;}+div.replies {padding-top: 8px;}+div.replies>table>tbody>tr>td {vertical-align: top; border-top: 1px dashed #CCC; padding: 8px 0 8px 0;}+div.replies>table>tbody>tr>td.avatar {width: 1px; padding: 10px 12px 0 0;}+div.replies>table>tbody>tr>td.avatar img {width: 26px; height: 26px;}+div.replies>table>tbody>tr.add-reply>td {padding-top: 12px;}+table.comments>tbody>tr>td.avatar {width: 1px; padding-right: 16px;}+table.comments>tbody>tr>td.avatar img {width: 36px; height: 36px;}+table.comments>tbody>tr>td {border-top: 1px solid #DDD; padding: 12px 0 12px 0;}+table.comments>tbody>tr:first-child>td {border-top: none;}+ul.threads li {border-left: 4px solid #E5E5E5; padding-left: 8px;}ul.threads li.unread {border-color: #70AEFA;}ul.threads li a {color: #444; cursor: pointer;}@@ -903,7 +896,7 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail>.head {font-size: 24px; font-weight: bold; padding: 0;}.request-detail>.head input[type="text"] {width: 600px;}-.request-detail .head .actions a {color: #999; font-size: 19px;}+.request-detail>.head>.actions a {color: #999; font-size: 19px;}.request-detail>.head>div {margin-right: 8px;}.request-detail>.head>.id {color: #999;}@@ -943,8 +936,6 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail .activities>tbody>tr.action>td>div>div:first-child .fa {margin-right: 4px; background: #fff;}.request-detail .activities>tbody>tr.action>td>div>.update .fa {margin-left: -21px; font-size: 20px;}.request-detail .activities>tbody>tr.action>td>div>.commits {margin-top: 12px; color: #999; margin-left: -20px;}-.request-detail .activities>tbody>tr.action>td>div>.commits tr:nth-child(odd) td.detail,-.request-detail .activities>tbody>tr.action>td>div>.commits tr:nth-child(odd) td.status {background: #F5F5F5;}.request-detail .activities>tbody>tr.action>td>div>.commits a {color: #666;}.request-detail .activities>tbody>tr.action>td>div>.commits td {padding-top: 4px; padding-bottom: 4px;}.request-detail .activities>tbody>tr.action>td>div>.commits td.detail,@@ -962,15 +953,14 @@ ul.status-help li:last-child .description {border-bottom: none;}.request-detail .updates>tbody>tr>td {padding: 12px 0; vertical-align: top;border-top: 1px solid #E5E5E5;}.request-detail .updates>tbody>tr:first-child>td {padding-top: 0; border-top: none;}-.request-detail .updates>tbody>tr>td.avatar {width: 1px; padding-right: 12px;}+.request-detail .updates>tbody>tr>td.avatar {width: 1px; padding-right: 20px;}.request-detail .updates>tbody>tr>td.avatar img {width: 48px; height: 48px;}.request-detail .updates>tbody>tr>td>.head {color: #999; margin-bottom: 12px;}.request-detail .updates>tbody>tr>td>.head a {font-weight: bold; color: #333;}.request-detail .updates>tbody>tr>td>.head .actions {margin-left: 8px;}.request-detail .updates>tbody>tr>td>.head .actions .fa {font-size: 16px;}-.request-detail .updates>tbody>tr>td>.commits tr:nth-child(odd) td {background: #F5F5F5;}-.request-detail .updates>tbody>tr>td>.commits td {padding-top: 4px; padding-bottom: 4px;- color: #999; border-top: 1px dotted #CCC;}+.request-detail .updates>tbody>tr>td>.commits td {padding-top: 8px; padding-bottom: 8px;+ color: #999; border-top: 1px dashed #CCC;}.request-detail .updates>tbody>tr>td>.commits td.avatar {width: 1px;}.request-detail .updates>tbody>tr>td>.commits td.avatar img {width: 36px; height: 36px;}.request-detail .updates>tbody>tr>td>.commits a {color: #666;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.htmlnew file mode 100644index 0000000000..562ef9ecdd--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.html@@ -0,0 +1,50 @@+<wicket:panel>+ <div class="comment">+ <div class="head">+ <span wicket:id="user" class="name"></span> commented <span wicket:id="age"></span>+ <span class="actions">+ <a wicket:id="edit" title="Edit comment"><span class="fa fa-pencil"></span></a>+ <a wicket:id="delete" title="Delete comment"><span class="fa fa-times"></span></a>+ </span>+ </div>+ <div wicket:id="content" class="body"></div>+ </div>+ <div class="replies">+ <table>+ <tr wicket:id="replies" class="reply">+ <td class="avatar"><span wicket:id="avatar"></span></td>+ <td class="detail">+ <div class="head">+ <span wicket:id="user" class="name"></span> replied <span wicket:id="age"></span>+ <span class="actions">+ <a wicket:id="edit" title="Edit reply"><span class="fa fa-pencil"></span></a>+ <a wicket:id="delete" title="Delete reply"><span class="fa fa-times"></span></a>+ </span>+ </div>+ <div wicket:id="content" class="body"></div>+ </td>+ </tr>+ <tr wicket:id="addReply" class="add-reply">+ <td colspan="2">+ <div wicket:id="content"></div>+ </td>+ </tr>+ </table>+ </div>+ <wicket:fragment wicket:id="viewFrag">+ <div wicket:id="comment"></div>+ </wicket:fragment>+ <wicket:fragment wicket:id="editFrag">+ <form wicket:id="form">+ <div wicket:id="input"></div>+ <div class="actions">+ <button wicket:id="save" class="btn btn-sm btn-primary">Save</button>+ + <button wicket:id="cancel" class="btn btn-sm btn-default">Cancel</button>+ </div>+ </form>+ </wicket:fragment>+ <wicket:fragment wicket:id="addFrag">+ <a wicket:id="addReply" class="btn btn-xs btn-default"><i class="fa fa-mail-reply"></i> Add reply</a>+ </wicket:fragment>+</wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.javanew file mode 100644index 0000000000..2279f1155e--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java@@ -0,0 +1,324 @@+package com.pmease.gitplex.web.component.comment;++import java.util.ArrayList;+import java.util.Collections;+import java.util.Comparator;+import java.util.List;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.markup.html.AjaxLink;+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;+import org.apache.wicket.event.Broadcast;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.form.Form;+import org.apache.wicket.markup.html.panel.Fragment;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.markup.repeater.RepeatingView;+import org.apache.wicket.model.IModel;+import org.apache.wicket.model.Model;++import com.pmease.commons.wicket.behavior.ConfirmBehavior;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.comment.Comment;+import com.pmease.gitplex.core.comment.CommentReply;+import com.pmease.gitplex.core.manager.AuthorizationManager;+import com.pmease.gitplex.web.component.comment.event.CommentRemoved;+import com.pmease.gitplex.web.component.comment.event.CommentReplied;+import com.pmease.gitplex.web.component.label.AgeLabel;+import com.pmease.gitplex.web.component.markdown.MarkdownPanel;+import com.pmease.gitplex.web.component.user.AvatarMode;+import com.pmease.gitplex.web.component.user.UserLink;+import com.pmease.gitplex.web.model.UserModel;++@SuppressWarnings("serial")+public class CommentPanel extends Panel {++ private RepeatingView repliesView;++ public CommentPanel(String id, IModel<? extends Comment> commentModel) {+ super(id, commentModel);+ }++ private Comment getComment() {+ return (Comment) getDefaultModelObject();+ }++ private Fragment renderForView(String content) {+ Fragment fragment = new Fragment("content", "viewFrag", this);+ fragment.add(new MarkdownPanel("comment", Model.of(content)));+ fragment.setOutputMarkupId(true);+ return fragment;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(new UserLink("user", new UserModel(getComment().getUser()), AvatarMode.NAME));+ add(new AgeLabel("age", Model.of(getComment().getDate())));++ add(new AjaxLink<Void>("edit") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = new Fragment("content", "editFrag", CommentPanel.this);++ Form<?> form = new Form<Void>("form");+ fragment.add(form);+ final CommentInput input = new CommentInput("input", Model.of(getComment().getContent()));+ input.setRequired(true);+ form.add(input);++ form.add(new AjaxSubmitLink("save") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ Comment comment = getComment();+ comment.saveContent(input.getModelObject());++ Fragment fragment = renderForView(comment.getContent());+ CommentPanel.this.replace(fragment);+ target.add(fragment);+ }++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }++ });++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = renderForView(getComment().getContent());+ CommentPanel.this.replace(fragment);+ target.add(fragment);+ }++ });++ fragment.setOutputMarkupId(true);+ CommentPanel.this.replace(fragment);+ target.add(fragment);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(getComment()));+ }++ });++ add(new AjaxLink<Void>("delete") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ getComment().delete();+ send(CommentPanel.this, Broadcast.BUBBLE, new CommentRemoved(target, getComment()));+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(getComment()));+ }++ }.add(new ConfirmBehavior("Deleting this comment will also delete all its replies. Do you really want to continue?")));++ add(renderForView(getComment().getContent()));++ add(repliesView = newRepliesView());++ add(newAddReplyRow());+ }++ private Component newAddReplyRow() {+ WebMarkupContainer row = new WebMarkupContainer("addReply");+ row.setOutputMarkupId(true);++ Fragment fragment = new Fragment("content", "addFrag", this);+ fragment.add(new AjaxLink<Void>("addReply") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ final WebMarkupContainer row = new WebMarkupContainer("addReply");++ row.setOutputMarkupId(true);++ Fragment fragment = new Fragment("content", "editFrag", CommentPanel.this);+ row.add(fragment);++ Form<?> form = new Form<Void>("form");+ fragment.add(form);+ final CommentInput input = new CommentInput("input", Model.of(""));+ input.setRequired(true);+ form.add(input);++ form.add(new AjaxSubmitLink("save") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ Component row = newAddReplyRow();+ CommentPanel.this.replace(row);+ target.add(row);++ CommentReply newReply = getComment().addReply(input.getModelObject());+ send(CommentPanel.this, Broadcast.BUBBLE, new CommentReplied(target, newReply));++ Component newReplyRow = newReplyRow(repliesView.newChildId(), newReply);+ repliesView.add(newReplyRow);+ String script = String.format("$(\"<tr id='%s' class='reply'></tr>\").insertBefore('#%s');",+ newReplyRow.getMarkupId(), row.getMarkupId());+ target.prependJavaScript(script);+ target.add(newReplyRow);+ }++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }++ });++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Component row = newAddReplyRow();+ CommentPanel.this.replace(row);+ target.add(row);+ }++ });++ CommentPanel.this.replace(row);+ target.add(row);+ }++ });+ row.add(fragment);++ return row;+ }++ private RepeatingView newRepliesView() {+ RepeatingView repliesView = new RepeatingView("replies");++ List<CommentReply> replies = new ArrayList<>(getComment().getReplies());+ Collections.sort(replies, new Comparator<CommentReply>() {++ @Override+ public int compare(CommentReply reply1, CommentReply reply2) {+ return reply1.getDate().compareTo(reply2.getDate());+ }++ });+ for (CommentReply reply: replies)+ repliesView.add(newReplyRow(repliesView.newChildId(), reply));++ return repliesView;+ }++ @Override+ protected void onBeforeRender() {+ replace(repliesView = newRepliesView());++ super.onBeforeRender();+ }++ private Component newReplyRow(String id, final CommentReply reply) {+ final WebMarkupContainer row = new WebMarkupContainer(id);+ row.setOutputMarkupId(true);++ row.add(new UserLink("avatar", new UserModel(reply.getUser()), AvatarMode.AVATAR));+ row.add(new UserLink("user", new UserModel(reply.getUser()), AvatarMode.NAME));+ row.add(new AgeLabel("age", Model.of(reply.getDate())));++ row.add(new AjaxLink<Void>("edit") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = new Fragment("content", "editFrag", CommentPanel.this);++ Form<?> form = new Form<Void>("form");+ fragment.add(form);+ final CommentInput input = new CommentInput("input", Model.of(reply.getContent()));+ input.setRequired(true);+ form.add(input);++ form.add(new AjaxSubmitLink("save") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ reply.saveContent(input.getModelObject());++ Fragment fragment = renderForView(reply.getContent());+ row.replace(fragment);+ target.add(fragment);+ }++ @Override+ protected void onError(AjaxRequestTarget target, Form<?> form) {+ super.onError(target, form);+ target.add(form);+ }++ });++ form.add(new AjaxLink<Void>("cancel") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ Fragment fragment = renderForView(reply.getContent());+ row.replace(fragment);+ target.add(fragment);+ }++ });++ fragment.setOutputMarkupId(true);+ row.replace(fragment);+ target.add(fragment);+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(getComment()));+ }++ });++ row.add(new AjaxLink<Void>("delete") {++ @Override+ public void onClick(AjaxRequestTarget target) {+ reply.delete();+ row.remove();+ target.appendJavaScript(String.format("$('#%s').remove();", row.getMarkupId()));+ }++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(getComment()));+ }++ }.add(new ConfirmBehavior("Do you really want to delete this reply?")));++ row.add(renderForView(reply.getContent()));++ return row;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentRemoved.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentRemoved.javanew file mode 100644index 0000000000..dc03a74723--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentRemoved.java@@ -0,0 +1,22 @@+package com.pmease.gitplex.web.component.comment.event;++import org.apache.wicket.ajax.AjaxRequestTarget;++import com.pmease.gitplex.core.comment.Comment;+import com.pmease.gitplex.web.common.wicket.event.AjaxEvent;++public class CommentRemoved extends AjaxEvent {++ private final Comment comment;++ public CommentRemoved(AjaxRequestTarget target, Comment comment) {+ super(target);++ this.comment = comment;+ }++ public Comment getComment() {+ return comment;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.javanew file mode 100644index 0000000000..a95e9fdb07--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.java@@ -0,0 +1,22 @@+package com.pmease.gitplex.web.component.comment.event;++import org.apache.wicket.ajax.AjaxRequestTarget;++import com.pmease.gitplex.core.comment.CommentReply;+import com.pmease.gitplex.web.common.wicket.event.AjaxEvent;++public class CommentReplied extends AjaxEvent {++ private final CommentReply reply;++ public CommentReplied(AjaxRequestTarget target, CommentReply reply) {+ super(target);++ this.reply = reply;+ }++ public CommentReply getReply() {+ return reply;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.javaindex fd98ce3b1b..768f9689f9 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java@@ -2,6 +2,8 @@ package com.pmease.gitplex.web.component.diff;import static com.pmease.commons.git.Change.Status.UNCHANGED;+import java.util.List;+import org.apache.tika.mime.MediaType;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;@@ -12,9 +14,12 @@ import org.eclipse.jgit.lib.FileMode;import com.pmease.commons.git.BlobInfo;import com.pmease.commons.git.BlobText;+import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.util.MediaTypes;+import com.pmease.commons.util.diff.DiffLine;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.CommentAwareChange;+import com.pmease.gitplex.core.comment.LineComment;+import com.pmease.gitplex.core.comment.LineCommentContext;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.component.gitlink.GitLink;import com.pmease.gitplex.web.component.symbollink.SymbolLink;@@ -27,19 +32,19 @@ public class BlobDiffPanel extends Panel {private final IModel<Repository> repoModel;- private final CommentAwareChange change;+ private final RevAwareChange change;++ private final LineCommentContext commentContext;- public BlobDiffPanel(String id, IModel<Repository> repoModel, CommentAwareChange change) {+ public BlobDiffPanel(String id, IModel<Repository> repoModel, RevAwareChange change,+ LineCommentContext commentContext) {super(id);this.repoModel = repoModel;this.change = change;+ this.commentContext = commentContext;}- public CommentAwareChange getChange() {- return change;- }-@Overrideprotected void onInitialize() {super.onInitialize();@@ -108,9 +113,9 @@ public class BlobDiffPanel extends Panel {BlobText newText = repoModel.getObject().getBlobText(change.getNewBlobInfo());if (oldText != null) {if (newText != null) {- add(new TextDiffPanel("blobContent", repoModel, oldText, newText, change));+ add(new TextDiffPanel("blobContent", repoModel, oldText, newText, change, commentContext));} else if (newContent.length == 0) {- add(new TextDiffPanel("blobContent", repoModel, oldText, new BlobText(), change));+ add(new TextDiffPanel("blobContent", repoModel, oldText, new BlobText(), change, commentContext));} else {Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);fragment.add(new FileDiffTitle("summary", change));@@ -118,7 +123,7 @@ public class BlobDiffPanel extends Panel {}} else if (newText != null) {if (oldContent.length == 0) {- add(new TextDiffPanel("blobContent", repoModel, new BlobText(), newText, change));+ add(new TextDiffPanel("blobContent", repoModel, new BlobText(), newText, change, commentContext));} else {Fragment fragment = new Fragment("blobContent", "binaryFileFrag", this);fragment.add(new FileDiffTitle("summary", change));@@ -168,6 +173,10 @@ public class BlobDiffPanel extends Panel {}+ public List<DiffLine> getLineContext(LineComment comment) {+ return null;+ }+protected void onDetach() {repoModel.detach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.htmlindex 12c9656c8c..7d1005ff67 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html@@ -36,51 +36,25 @@<td class="text"><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td></tr><tr wicket:id="commentsRow" class="line comments">- <td colspan="2" class="summary">- <div><i wicket:id="concernedFlag" class="fa fa-flag concerned-comments" title="Concerned comments"></i></div>- <div><i class="fa fa-comment"></i> <span wicket:id="commentCount"></span></div>- </td>- <td class="detail">- <table class="line-comments">+ <td colspan="3">+ <table class="comments"><tr wicket:id="comments"><td class="avatar"><span wicket:id="avatar"></span></td>- <td class="content">- <div class="clearfix head">- <span wicket:id="name" class="pull-left"></span>- <a wicket:id="edit" class="pull-right" title="Edit this comment"><i class="fa fa-pencil"></i></a>- <a wicket:id="delete" class="pull-right" title="Delete this comment"><i class="fa fa-times"></i></a>- <a wicket:id="reply" class="pull-right" title="Reply this comment"><i class="fa fa-mail-reply"></i></a>- <span wicket:id="age" class="pull-right"></span>- </div>- <div wicket:id="content" class="body"></div>+ <td class="comment">+ <div wicket:id="comment"></div></td></tr></table>- <wicket:enclosure child="addComment">- <div class="add-comment">- <a wicket:id="addComment">Add a comment</a>- </div>- </wicket:enclosure>- <div wicket:id="newComment"></div>+ <div wicket:id="addComment"></div></td></tr></wicket:container></table></div>- <wicket:fragment wicket:id="editCommentFrag">- <form wicket:id="form">- <div wicket:id="input"></div>- <div class="actions">- <button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Update comment</button>- - <button wicket:id="cancel" class="btn btn-sm btn-default">Close form</button>- </div>- </form>- </wicket:fragment>- <wicket:fragment wicket:id="newCommentFrag">- <form wicket:id="form">+ <wicket:fragment wicket:id="addCommentFrag">+ <form wicket:id="form" class="add-comment"><div wicket:id="input"></div><div class="actions"><button wicket:id="save" class="btn btn-sm btn-primary dirty-aware">Comment on this line</button>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.javaindex 185abdaadf..bee4e273a1 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java@@ -5,19 +5,16 @@ import static com.pmease.commons.util.diff.DiffLine.Action.DELETE;import static com.pmease.commons.util.diff.DiffLine.Action.EQUAL;import java.util.ArrayList;-import java.util.Collections;-import java.util.Date;import java.util.List;-import java.util.Map;-import jersey.repackaged.com.google.common.base.Splitter;+import javax.annotation.Nullable;import org.apache.shiro.SecurityUtils;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.event.Broadcast;+import org.apache.wicket.event.IEvent;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;@@ -34,12 +31,11 @@ import org.apache.wicket.model.Model;import com.google.common.base.Preconditions;import com.pmease.commons.git.BlobText;-import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.git.RevAwareChange;import com.pmease.commons.util.diff.DiffLine;import com.pmease.commons.util.diff.DiffUtils;import com.pmease.commons.util.diff.Partial;import com.pmease.commons.util.diff.WordSplitter;-import com.pmease.commons.wicket.behavior.ConfirmBehavior;import com.pmease.commons.wicket.behavior.ScrollBehavior;import com.pmease.commons.wicket.behavior.StickyBehavior;import com.pmease.commons.wicket.behavior.menu.CheckMenuItem;@@ -47,21 +43,17 @@ import com.pmease.commons.wicket.behavior.menu.MenuBehavior;import com.pmease.commons.wicket.behavior.menu.MenuItem;import com.pmease.commons.wicket.behavior.menu.MenuPanel;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.CommentAwareChange;-import com.pmease.gitplex.core.manager.AuthorizationManager;-import com.pmease.gitplex.core.manager.CommentVisitManager;+import com.pmease.gitplex.core.comment.LineComment;+import com.pmease.gitplex.core.comment.LineCommentContext;import com.pmease.gitplex.core.manager.UserManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.permission.ObjectPermission;import com.pmease.gitplex.web.component.comment.CommentInput;-import com.pmease.gitplex.web.component.label.AgeLabel;-import com.pmease.gitplex.web.component.markdown.MarkdownPanel;+import com.pmease.gitplex.web.component.comment.CommentPanel;+import com.pmease.gitplex.web.component.comment.event.CommentRemoved;import com.pmease.gitplex.web.component.user.AvatarMode;import com.pmease.gitplex.web.component.user.UserLink;-import com.pmease.gitplex.web.event.CommitCommentRemoved;import com.pmease.gitplex.web.model.UserModel;@SuppressWarnings("serial")@@ -77,7 +69,7 @@ public class TextDiffPanel extends Panel {private static final String COMMENT_ACTIONS_ID = "commentActions";- private static final String NEW_COMMENT_ID = "newComment";+ private static final String ADD_COMMENT_ID = "addComment";private static final String HEAD_ID = "head";@@ -87,7 +79,9 @@ public class TextDiffPanel extends Panel {private final BlobText newText;- private final CommentAwareChange change;+ private final RevAwareChange change;++ private final LineCommentContext commentContext;private final IModel<Boolean> allowToAddCommentModel;@@ -103,34 +97,6 @@ public class TextDiffPanel extends Panel {private String autoScrollScript;- public TextDiffPanel(String id, final IModel<Repository> repoModel,- BlobText oldText, BlobText newText, CommentAwareChange change) {- super(id);-- this.repoModel = repoModel;-- Preconditions.checkArgument(!change.getOldRevision().equals(change.getNewRevision()));-- this.change = change;-- this.oldText = oldText;- this.newText = newText;-- // cache add comment permission check in model to avoid recalculation for every line- allowToAddCommentModel = new LoadableDetachableModel<Boolean>() {-- @Override- protected Boolean load() {- User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();- ObjectPermission readPermission = ObjectPermission.ofRepositoryRead(repoModel.getObject());- return currentUser != null && SecurityUtils.getSubject().isPermitted(readPermission);- }-- };-- onDiffOptionChanged();- }-private void onDiffOptionChanged() {if (diffOption == DiffOption.IGNORE_EOL) {effectiveOldText = oldText.ignoreEOL();@@ -157,6 +123,36 @@ public class TextDiffPanel extends Panel {return true;}+ public TextDiffPanel(String id, final IModel<Repository> repoModel,+ BlobText oldText, BlobText newText, RevAwareChange change,+ @Nullable LineCommentContext commentContext) {+ super(id);++ this.repoModel = repoModel;++ Preconditions.checkArgument(!change.getOldRevision().equals(change.getNewRevision()));++ this.change = change;+ this.commentContext = commentContext;++ this.oldText = oldText;+ this.newText = newText;++ // cache add comment permission check in model to avoid recalculation for every line+ allowToAddCommentModel = new LoadableDetachableModel<Boolean>() {++ @Override+ protected Boolean load() {+ User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();+ ObjectPermission readPermission = ObjectPermission.ofRepositoryRead(repoModel.getObject());+ return currentUser != null && SecurityUtils.getSubject().isPermitted(readPermission);+ }++ };++ onDiffOptionChanged();+ }+@Overrideprotected void onInitialize() {super.onInitialize();@@ -237,7 +233,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible(commentContext != null && showComments);}}.add(new ScrollBehavior(".comments.line", 50, false)));@@ -247,7 +243,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible(commentContext != null && showComments);}}.add(new ScrollBehavior(".comments.line", 50, true)));@@ -262,7 +258,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && !showComments);+ setVisible(commentContext != null && !showComments);}});@@ -276,7 +272,7 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible((getOldComments() != null || getNewComments() != null) && showComments);+ setVisible(commentContext != null && showComments);}});@@ -426,16 +422,15 @@ public class TextDiffPanel extends Panel {protected void populateItem(final ListItem<DiffLine> lineItem) {final DiffLine diffLine = lineItem.getModelObject();final WebMarkupContainer contentRow = new WebMarkupContainer(CONTENT_ROW_ID);-- final IModel<List<CommitComment>> lineCommentsModel = new LoadableDetachableModel<List<CommitComment>>() {++ final IModel<List<LineComment>> lineCommentsModel = new LoadableDetachableModel<List<LineComment>>() {@Override- protected List<CommitComment> load() {+ protected List<LineComment> load() {return getLineComments(diffLine);}};-final WebMarkupContainer commentsRow = new WebMarkupContainer(COMMENTS_ROW_ID) {@Override@@ -451,158 +446,36 @@ public class TextDiffPanel extends Panel {setVisible(false);}}-- };-- commentsRow.setOutputMarkupId(true);- commentsRow.add(new Label("commentCount", new AbstractReadOnlyModel<Integer> () {@Override- public Integer getObject() {- return lineCommentsModel.getObject().size();- }-- }));- commentsRow.add(new WebMarkupContainer("concernedFlag") {-- @Override- protected void onConfigure() {- super.onConfigure();+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);- setVisible(lineCommentsModel.getObject().contains(change.getConcernedComment()));+ if (event.getPayload() instanceof CommentRemoved) {+ CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();+ lineCommentsModel.getObject().remove(commentRemoved.getComment());+ commentRemoved.getTarget().add(this);+ }}- });+ };+ commentsRow.setOutputMarkupId(true);- commentsRow.add(new ListView<CommitComment>("comments", lineCommentsModel) {+ commentsRow.add(new ListView<LineComment>("comments", lineCommentsModel) {@Override- protected void populateItem(final ListItem<CommitComment> commentItem) {- final CommitComment comment = commentItem.getModelObject();- commentItem.add(new UserLink("avatar", new UserModel(comment.getUser()), AvatarMode.AVATAR));- commentItem.add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));-- commentItem.add(new AgeLabel("age", new AbstractReadOnlyModel<Date>() {-- @Override- public Date getObject() {- return commentItem.getModelObject().getCommentDate();- }-- }));-- commentItem.add(new AddCommentLink("reply", lineItem, comment));-- commentItem.add(new AjaxLink<Void>("edit") {-- @Override- public void onClick(AjaxRequestTarget target) {- Fragment fragment = new Fragment("content", "editCommentFrag", TextDiffPanel.this);- fragment.setOutputMarkupId(true);- Form<?> form = new Form<Void>("form");- form.setOutputMarkupId(true);- final CommentInput input;- form.add(input = new CommentInput("input", Model.of(commentItem.getModelObject().getContent())));- form.add(new AjaxLink<Void>("cancel") {-- @Override- public void onClick(AjaxRequestTarget target) {- target.add(commentsRow);- }-- });- form.add(new AjaxSubmitLink("save") {-- @Override- protected void onError(AjaxRequestTarget target, Form<?> form) {- super.onError(target, form);- target.add(form);- }-- @Override- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {- super.onSubmit(target, form);-- CommitComment comment = commentItem.getModelObject();- comment.setCommentDate(new Date());- comment.setContent(input.getModelObject());-- GitPlex.getInstance(Dao.class).persist(comment);- target.add(commentsRow);- }-- });- fragment.add(form);- commentItem.replace(fragment);-- target.add(fragment);- }-- @Override- protected void onConfigure() {- super.onConfigure();-- AuthorizationManager manager = GitPlex.getInstance(AuthorizationManager.class);- setVisible(manager.canModify(commentItem.getModelObject()));- }-- });- commentItem.add(new AjaxLink<Void>("delete") {-- @Override- public void onClick(AjaxRequestTarget target) {- GitPlex.getInstance(Dao.class).remove(comment);- if (getOldComments() != null) {- List<CommitComment> lineComments = getOldComments().get(diffLine.getOldLineNo());- if (lineComments != null) {- lineComments.remove(comment);- if (lineComments.isEmpty())- getOldComments().remove(diffLine.getOldLineNo());- }- }- if (getNewComments() != null) {- List<CommitComment> lineComments = getNewComments().get(diffLine.getNewLineNo());- if (lineComments != null) {- lineComments.remove(comment);- if (lineComments.isEmpty())- getOldComments().remove(diffLine.getNewLineNo());- }- }- target.add(commentsRow);- send(getPage(), Broadcast.BUBBLE, new CommitCommentRemoved(target, comment));- }-- @Override- protected void onConfigure() {- super.onConfigure();-- setVisible(GitPlex.getInstance(AuthorizationManager.class).canModify(commentItem.getModelObject()));- }-- }.add(new ConfirmBehavior("Do you really want to delete this comment?")));-- commentItem.add(new MarkdownPanel("content", Model.of(comment.getContent())));+ protected void populateItem(final ListItem<LineComment> item) {+ item.add(new UserLink("avatar", new UserModel(item.getModelObject().getUser()), AvatarMode.AVATAR));+ item.add(new CommentPanel("comment", item.getModel()).setOutputMarkupId(true));}});- commentsRow.add(new AddCommentLink("addComment", lineItem, null) {-- @Override- protected void onConfigure() {- super.onConfigure();-- if (isVisible() && isAddingComment(commentsRow))- setVisible(false);- }-- });-- commentsRow.add(new WebMarkupContainer(NEW_COMMENT_ID));+ commentsRow.add(new WebMarkupContainer(ADD_COMMENT_ID));lineItem.add(commentsRow);- contentRow.add(new AddCommentLink("addComment", lineItem, null));+ contentRow.add(new AddCommentLink("addComment", lineItem));if (diffLine.getAction() == ADD) {if (lineItem.getIndex() == 0 || diffs.get(lineItem.getIndex()-1).getAction() == EQUAL)@@ -646,14 +519,13 @@ public class TextDiffPanel extends Panel {});- String cssClass;- if (change.contains(change.getConcernedComment()))- cssClass = ".concerned-comments";- else- cssClass = ".diff-block:first";- autoScrollScript = String.format("pmease.commons.scroll.next('%s', %d);", cssClass, SCROLL_MARGIN);+ autoScrollScript = String.format(""+ + "if ($('.concerned-comment').length != 0) "+ + " pmease.commons.scroll.next('.concerned-comment', %d);"+ + "else"+ + " pmease.commons.scroll.next('.diff-block:first', %d);", SCROLL_MARGIN, SCROLL_MARGIN);}-+private void showComments(AjaxRequestTarget target) {showComments = true;target.add(get(HEAD_ID).get(COMMENT_ACTIONS_ID));@@ -669,22 +541,21 @@ public class TextDiffPanel extends Panel {}private boolean isAddingComment(WebMarkupContainer commentsRow) {- return commentsRow.get(NEW_COMMENT_ID) instanceof Fragment;+ return commentsRow.get(ADD_COMMENT_ID) instanceof Fragment;}- private List<CommitComment> getLineComments(DiffLine line) {- List<CommitComment> lineComments = new ArrayList<>();- if (getOldComments() != null- && getOldComments().containsKey(line.getOldLineNo())+ private List<LineComment> getLineComments(DiffLine line) {+ List<LineComment> lineComments = new ArrayList<>();+ if (commentContext != null+ && commentContext.getOldComments().containsKey(line.getOldLineNo())&& line.getAction() != ADD) {- lineComments.addAll(getOldComments().get(line.getOldLineNo()));+ lineComments.add(commentContext.getOldComments().get(line.getOldLineNo()));}- if (getNewComments() != null- && getNewComments().containsKey(line.getNewLineNo())+ if (commentContext != null+ && commentContext.getNewComments().containsKey(line.getNewLineNo())&& line.getAction() != DELETE) {- lineComments.addAll(getNewComments().get(line.getNewLineNo()));+ lineComments.add(commentContext.getNewComments().get(line.getNewLineNo()));}- Collections.sort(lineComments);return lineComments;}@@ -692,12 +563,9 @@ public class TextDiffPanel extends Panel {private final ListItem<DiffLine> item;- private final CommitComment replyComment;-- public AddCommentLink(String id, ListItem<DiffLine> item, CommitComment replyComment) {+ public AddCommentLink(String id, ListItem<DiffLine> item) {super(id);this.item = item;- this.replyComment = replyComment;}@Override@@ -705,18 +573,12 @@ public class TextDiffPanel extends Panel {if (!showComments)showComments(target);- Fragment frag = new Fragment(NEW_COMMENT_ID, "newCommentFrag", TextDiffPanel.this);+ Fragment frag = new Fragment(ADD_COMMENT_ID, "addCommentFrag", TextDiffPanel.this);Form<?> form = new Form<Void>("form");form.setOutputMarkupId(true);- String content = "";- if (replyComment != null) {- for (String line: Splitter.on('\n').split(replyComment.getContent()))- content += "> " + line + "\n";- }-final CommentInput input;- form.add(input = new CommentInput("input", Model.of(content)));+ form.add(input = new CommentInput("input", Model.of("")));final WebMarkupContainer contentRow = (WebMarkupContainer) item.get(CONTENT_ROW_ID);final WebMarkupContainer commentsRow = (WebMarkupContainer) item.get(COMMENTS_ROW_ID);@@ -726,7 +588,7 @@ public class TextDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {- commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));+ commentsRow.replace(new WebMarkupContainer(ADD_COMMENT_ID));target.add(commentsRow);}@@ -742,49 +604,26 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);- CommitComment comment = new CommitComment();- comment.setRepository(repoModel.getObject());- User currentUser = Preconditions.checkNotNull(GitPlex.getInstance(UserManager.class).getCurrent());- comment.setUser(currentUser);+String commit;- CommentPosition position;- if (replyComment != null) {- commit = replyComment.getCommit();- position = replyComment.getPosition();- } else {- List<CommitComment> comments = getLineComments(diffLine);- if (!comments.isEmpty()) {- CommitComment lastComment = comments.get(comments.size()-1);- commit = lastComment.getCommit();- position = lastComment.getPosition();- } else if (diffLine.getAction() == DELETE) {- commit = change.getOldRevision();- position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());- } else if (diffLine.getAction() == ADD) {- commit = change.getNewRevision();- position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());- } else if (getNewComments() != null) {- commit = change.getNewRevision();- position = new CommentPosition(change.getNewPath(), diffLine.getNewLineNo());- } else {- commit = change.getOldRevision();- position = new CommentPosition(change.getOldPath(), diffLine.getOldLineNo());- }- }+ String filePath;+ int lineNo;- comment.setCommit(commit);- comment.setPosition(position);- comment.setContent(input.getModelObject());- comment.setCommentDate(new Date());- comment.setCommitDate(repoModel.getObject().getCommit(commit).getCommitter().getWhen());+ if (diffLine.getAction() == DELETE) {+ commit = change.getOldRevision();+ filePath = change.getOldPath();+ lineNo = diffLine.getOldLineNo();+ } else {+ commit = change.getNewRevision();+ filePath = change.getNewPath();+ lineNo = diffLine.getNewLineNo();+ }- change.saveComment(comment);-- GitPlex.getInstance(CommentVisitManager.class).visitComment(repoModel.getObject(),- currentUser, comment);+ commentContext.addComment(commit, filePath, lineNo, input.getModelObject());- commentsRow.replace(new WebMarkupContainer(NEW_COMMENT_ID));+ commentsRow.replace(new WebMarkupContainer(ADD_COMMENT_ID));target.add(commentsRow);+ target.add(contentRow);}});@@ -802,17 +641,17 @@ public class TextDiffPanel extends Panel {@Overrideprotected void onConfigure() {super.onConfigure();-- if (!allowToAddCommentModel.getObject()) {++ if (!allowToAddCommentModel.getObject() || commentContext == null) {setVisible(false);} else {- DiffLine.Action action = item.getModelObject().getAction();- if (action == DELETE)- setVisible(getOldComments() != null);- else if (action == ADD)- setVisible(getNewComments() != null);- else- setVisible(getOldComments() != null || getNewComments() != null);+ WebMarkupContainer commentsRow = (WebMarkupContainer) item.get(COMMENTS_ROW_ID);+ if (isAddingComment(commentsRow)) {+ setVisible(false);+ } else {+ DiffLine diffLine = item.getModelObject();+ setVisible(getLineComments(diffLine).isEmpty());+ }}}@@ -830,14 +669,6 @@ public class TextDiffPanel extends Panel {autoScrollScript = null;}}-- private Map<Integer, List<CommitComment>> getOldComments() {- return change.getOldComments();- }-- private Map<Integer, List<CommitComment>> getNewComments() {- return change.getNewComments();- }@Overrideprotected void onDetach() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.javadeleted file mode 100644index 1dcd8f2211..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/event/CommitCommentRemoved.java+++ /dev/null@@ -1,22 +0,0 @@-package com.pmease.gitplex.web.event;--import org.apache.wicket.ajax.AjaxRequestTarget;--import com.pmease.gitplex.core.model.CommitComment;-import com.pmease.gitplex.web.common.wicket.event.AjaxEvent;--public class CommitCommentRemoved extends AjaxEvent {-- private final CommitComment comment;-- public CommitCommentRemoved(AjaxRequestTarget target, CommitComment comment) {- super(target);-- this.comment = comment;- }-- public CommitComment getComment() {- return comment;- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.htmldeleted file mode 100644index dda3243eab..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.html+++ /dev/null@@ -1,21 +0,0 @@-<wicket:panel>- <ul class="threads list-unstyled">- <li wicket:id="threads">- <a wicket:id="link">- <span wicket:id="userAvatar" class="avatar"></span>- <span wicket:id="userName"></span>- commented on <em wicket:id="position"></em>- <span wicket:id="age"></span>,- <span wicket:id="stats"></span>- <i class="fa fa-arrow-slim-right"></i>- </a>- <div wicket:id="lastComment"></div>- </li>- </ul>- <wicket:fragment wicket:id="guestStatsFrag">- <span wicket:id="total"></span> total- </wicket:fragment>- <wicket:fragment wicket:id="userStatsFrag">- <span wicket:id="unread"></span> unread / <span wicket:id="total"></span> total- </wicket:fragment>-</wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.javadeleted file mode 100644index 40f94384b5..0000000000--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/CommentThreadPanel.java+++ /dev/null@@ -1,145 +0,0 @@-package com.pmease.gitplex.web.page.repository.info.pullrequest;--import java.util.Date;-import java.util.List;-import java.util.Map;--import org.apache.wicket.behavior.AttributeAppender;-import org.apache.wicket.markup.html.basic.Label;-import org.apache.wicket.markup.html.link.Link;-import org.apache.wicket.markup.html.list.ListItem;-import org.apache.wicket.markup.html.list.ListView;-import org.apache.wicket.markup.html.panel.Fragment;-import org.apache.wicket.markup.html.panel.Panel;-import org.apache.wicket.model.IModel;-import org.apache.wicket.model.Model;-import org.apache.wicket.request.mapper.parameter.PageParameters;--import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.CommentThread;-import com.pmease.gitplex.core.manager.CommentVisitManager;-import com.pmease.gitplex.core.manager.UserManager;-import com.pmease.gitplex.core.model.CommentPosition;-import com.pmease.gitplex.core.model.CommitComment;-import com.pmease.gitplex.core.model.PullRequest;-import com.pmease.gitplex.core.model.Repository;-import com.pmease.gitplex.core.model.User;-import com.pmease.gitplex.web.component.label.AgeLabel;-import com.pmease.gitplex.web.component.markdown.MarkdownPanel;-import com.pmease.gitplex.web.component.user.AvatarByUser;-import com.pmease.gitplex.web.model.UserModel;--@SuppressWarnings("serial")-public class CommentThreadPanel extends Panel {-- private final IModel<PullRequest> requestModel;-- private final IModel<List<CommentThread>> threadsModel;-- private final IModel<Map<CommentPosition, Date>> visitsModel;-- public CommentThreadPanel(String id, final IModel<PullRequest> requestModel,- final IModel<List<CommentThread>> threadsModel,- final IModel<Map<CommentPosition, Date>> visitsModel) {- super(id);-- this.requestModel = requestModel;- this.visitsModel = visitsModel;- this.threadsModel = threadsModel;- }-- @Override- protected void onInitialize() {- super.onInitialize();-- final boolean isGuest = GitPlex.getInstance(UserManager.class).getCurrent() == null;-- add(new ListView<CommentThread>("threads", threadsModel) {-- @Override- protected void populateItem(final ListItem<CommentThread> item) {- CommentThread thread = item.getModelObject();-- Link<Void> link = new Link<Void>("link") {-- @Override- public void onClick() {- CommentThread thread = item.getModelObject();- User currentUser = GitPlex.getInstance(UserManager.class).getCurrent();- if (currentUser != null) {- Repository repo = requestModel.getObject().getTarget().getRepository();- CommentVisitManager manager = GitPlex.getInstance(CommentVisitManager.class);- manager.visitComment(repo, currentUser, thread.getLastComment());- }- if (thread.getPosition() == null) {- // TODO: navigate to commit comments page- } else if (thread.getPosition().getLineNo() == null) {- // TODO: navigate to commit file comments page- } else {- PageParameters params = RequestComparePage.paramsOf(- requestModel.getObject(),- null, null, null, thread.getLastComment());- setResponsePage(RequestComparePage.class, params);- }- }-- };-- link.add(new AvatarByUser("userAvatar", new UserModel(thread.getLastComment().getUser())));- link.add(new Label("userName", thread.getLastComment().getUser().getDisplayName()));-- if (thread.getPosition() == null) {- link.add(new Label("position", "whole commit"));- } else if (thread.getPosition().getLineNo() == null) {- link.add(new Label("position", "file " + thread.getPosition().getFilePath()));- } else {- link.add(new Label("position", "line " + (thread.getPosition().getLineNo()+1)- + " of file " + thread.getPosition().getFilePath()));- }-- link.add(new AgeLabel("age", Model.of(thread.getLastComment().getCommentDate())));-- if (!isGuest) {- Fragment fragment = new Fragment("stats", "userStatsFrag", CommentThreadPanel.this);- int unread = 0;- for (CommitComment comment: thread.getComments()) {- Date lastVisit = visitsModel.getObject().get(thread.getPosition());- if (lastVisit == null || comment.getCommentDate().after(lastVisit))- unread++;- }- fragment.add(new Label("unread", unread));- fragment.add(new Label("total", thread.getComments().size()));- link.add(fragment);-- if (unread != 0)- item.add(AttributeAppender.append("class", " unread"));- } else {- Fragment fragment = new Fragment("stats", "guestStatsFrag", CommentThreadPanel.this);- fragment.add(new Label("total", thread.getComments().size()));- link.add(fragment);- }-- item.add(link);-- item.add(new MarkdownPanel("lastComment", Model.of(thread.getLastComment().getContent())));- }-- });- }-- @Override- protected void onConfigure() {- super.onConfigure();- setVisible(!threadsModel.getObject().isEmpty());- }-- @Override- protected void onDetach() {- requestModel.detach();- threadsModel.detach();- visitsModel.detach();-- super.onDetach();- }--}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.javaindex 366ee896a6..e7af3b01f5 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java@@ -4,6 +4,9 @@ import static com.pmease.commons.git.Change.Status.UNCHANGED;import java.io.Serializable;import java.util.ArrayList;+import java.util.Collection;+import java.util.Date;+import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;@@ -32,11 +35,8 @@ import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.model.Model;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.eclipse.jgit.lib.FileMode;-import org.hibernate.Hibernate;import com.google.common.base.Preconditions;-import com.pmease.commons.git.BlobInfo;-import com.pmease.commons.git.BlobText;import com.pmease.commons.git.Change;import com.pmease.commons.git.Commit;import com.pmease.commons.git.GitUtils;@@ -51,19 +51,21 @@ import com.pmease.commons.wicket.behavior.menu.MenuBehavior;import com.pmease.commons.wicket.behavior.menu.MenuItem;import com.pmease.commons.wicket.behavior.menu.MenuPanel;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.comment.BlobLoader;-import com.pmease.gitplex.core.comment.CommentAwareChange;-import com.pmease.gitplex.core.comment.CommentLoader;+import com.pmease.gitplex.core.comment.LineComment;+import com.pmease.gitplex.core.comment.LineCommentContext;+import com.pmease.gitplex.core.manager.PullRequestCommentManager;import com.pmease.gitplex.core.manager.UserManager;-import com.pmease.gitplex.core.model.CommitComment;+import com.pmease.gitplex.core.model.InlineInfo;import com.pmease.gitplex.core.model.IntegrationInfo;import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.PullRequestComment;import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.User;+import com.pmease.gitplex.web.component.comment.event.CommentRemoved;+import com.pmease.gitplex.web.component.comment.event.CommentReplied;import com.pmease.gitplex.web.component.diff.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.ChangedFilesPanel;import com.pmease.gitplex.web.component.diff.DiffTreePanel;-import com.pmease.gitplex.web.event.CommitCommentRemoved;import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.ActivitiesModel;import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.PullRequestActivity;import com.pmease.gitplex.web.page.repository.info.pullrequest.activity.UpdatePullRequest;@@ -72,7 +74,7 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfigimport de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;@SuppressWarnings("serial")-public class RequestComparePage extends RequestDetailPage {+public class RequestComparePage extends RequestDetailPage implements LineCommentContext {private static final String HEAD_ID = "compareHead";@@ -89,14 +91,16 @@ public class RequestComparePage extends RequestDetailPage {private static final String CHANGES_ID = "changes";private static final String BLOB_DIFF_ID = "blobDiff";++ private String file;private String oldCommit;private String newCommit;- private String filePath;+ private RevAwareChange change;- private final IModel<CommitComment> concernedCommentModel;+ private final IModel<PullRequestComment> concernedCommentModel;private final ActivitiesModel activitiesModel = new ActivitiesModel() {@@ -116,7 +120,7 @@ public class RequestComparePage extends RequestDetailPage {String name = "Base of Pull Request";CommitDescription description = new CommitDescription(name,- getRepository().git().showRevision(request.getBaseCommit()).getSubject());+ getRepository().getCommit(request.getBaseCommit()).getSubject());choices.put(request.getBaseCommit(), description);for (int i=request.getSortedUpdates().size()-1; i>=0; i--) {@@ -138,7 +142,7 @@ public class RequestComparePage extends RequestDetailPage {String targetHead = request.getTarget().getHeadCommit();if (!choices.containsKey(targetHead)) {description = new CommitDescription("Head of Target Branch",- getRepository().git().showRevision(targetHead).getSubject());+ getRepository().getCommit(targetHead).getSubject());choices.put(targetHead, description);}@@ -147,7 +151,8 @@ public class RequestComparePage extends RequestDetailPage {&& integrationInfo.getIntegrationHead() != null&& !integrationInfo.getIntegrationHead().equals(integrationInfo.getRequestHead())&& integrationInfo.hasChanges()) {- Commit commit = getRepository().git().showRevision(request.getIntegrationInfo().getIntegrationHead());+ Commit commit = getRepository().getCommit(+ request.getIntegrationInfo().getIntegrationHead());choices.put(request.getIntegrationInfo().getIntegrationHead(),new CommitDescription("Integration Preview", commit.getSubject()));}@@ -157,23 +162,62 @@ public class RequestComparePage extends RequestDetailPage {};+ private final IModel<Collection<PullRequestComment>> changeCommentsModel =+ new LoadableDetachableModel<Collection<PullRequestComment>>() {++ @Override+ protected Collection<PullRequestComment> load() {+ Preconditions.checkNotNull(change);+ PullRequestCommentManager manager =+ GitPlex.getInstance(PullRequestCommentManager.class);+ return manager.findByChange(getPullRequest(), change);+ }+ };++ private final IModel<Map<Integer, LineComment>> oldCommentsModel =+ new LoadableDetachableModel<Map<Integer, LineComment>>() {++ @Override+ protected Map<Integer, LineComment> load() {+ Map<Integer, LineComment> oldComments = new HashMap<>();+ for (LineComment comment: changeCommentsModel.getObject()) {+ if (comment.getCommit().equals(change.getOldRevision()))+ oldComments.put(comment.getLine(), comment);+ }+ return oldComments;+ }++ };++ private final IModel<Map<Integer, LineComment>> newCommentsModel =+ new LoadableDetachableModel<Map<Integer, LineComment>>() {++ @Override+ protected Map<Integer, LineComment> load() {+ Map<Integer, LineComment> newComments = new HashMap<>();+ for (LineComment comment: changeCommentsModel.getObject()) {+ if (comment.getCommit().equals(change.getNewRevision()))+ newComments.put(comment.getLine(), comment);+ }+ return newComments;+ }++ };+public RequestComparePage(PageParameters params) {super(params);- filePath = params.get("path").toString();+ file = params.get("path").toString();final Long concernedCommentId = params.get("comment").toOptionalLong();- concernedCommentModel = new LoadableDetachableModel<CommitComment>() {+ concernedCommentModel = new LoadableDetachableModel<PullRequestComment>() {@Override- protected CommitComment load() {- if (concernedCommentId != null) {- CommitComment comment = GitPlex.getInstance(Dao.class).load(CommitComment.class, concernedCommentId);- Hibernate.initialize(comment);- return comment;- } else {+ protected PullRequestComment load() {+ if (concernedCommentId != null)+ return GitPlex.getInstance(Dao.class).load(PullRequestComment.class, concernedCommentId);+ elsereturn null;- }}};@@ -194,8 +238,49 @@ public class RequestComparePage extends RequestDetailPage {throw new IllegalArgumentException("Commit '" + newCommit + "' is not relevant to current pull request.");}- if (filePath != null && oldCommit == null)+ if (file != null && oldCommit == null)throw new IllegalArgumentException("Param 'path' can only be used together with param 'original' and 'revised'.");++ PullRequestComment comment = getConcernedComment();+ if (oldCommit != null) {+ if (file != null) {+ change = resolveChange();+ } else if (comment != null) {+ file = comment.getInlineInfo().getFile();+ change = resolveChange();+ }+ } else if (comment == null) {+ User user = GitPlex.getInstance(UserManager.class).getCurrent();+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ if (user == null) {+ oldCommit = getPullRequest().getBaseCommit();+ } else {+ List<PullRequestActivity> activities = activitiesModel.getObject();+ boolean found = false;+ for (int i=activities.size()-1; i>=0; i--) {+ PullRequestActivity activity = activities.get(i);+ if (found) {+ if (activity instanceof UpdatePullRequest) {+ oldCommit = ((UpdatePullRequest) activity).getUpdate().getHeadCommit();+ break;+ }+ } else if (activity.getUser().equals(user)) {+ found = true;+ }+ }+ if (oldCommit == null || oldCommit.equals(newCommit))+ oldCommit = getPullRequest().getBaseCommit();+ }+ } else {+ file = comment.getInlineInfo().getFile();+ oldCommit = comment.getInlineInfo().getCommit();+ newCommit = getPullRequest().getLatestUpdate().getHeadCommit();+ change = resolveChange();+ }+ if (change == null && !getChanges().isEmpty()) {+ file = getChanges().get(0).getPath();+ change = resolveChange();+ }}@Override@@ -216,9 +301,9 @@ public class RequestComparePage extends RequestDetailPage {CommitDescription description = commitsModel.getObject().get(oldCommit);Preconditions.checkNotNull(description);if (description.getName() != null)- return GitUtils.abbreviateSHA(oldCommit, 7) + " - " + description.getName();+ return GitUtils.abbreviateSHA(oldCommit) + " - " + description.getName();else- return GitUtils.abbreviateSHA(oldCommit, 7);+ return GitUtils.abbreviateSHA(oldCommit);}}).add(new TooltipBehavior(new LoadableDetachableModel<String>() {@@ -249,20 +334,20 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(newCommit);+ CommitDescription description = commitsModel.getObject().get(change.getNewRevision());Preconditions.checkNotNull(description);if (description.getName() != null)- return GitUtils.abbreviateSHA(newCommit, 7) + " - " + description.getName();+ return GitUtils.abbreviateSHA(change.getNewRevision()) + " - " + description.getName();else- return GitUtils.abbreviateSHA(newCommit, 7);+ return GitUtils.abbreviateSHA(change.getNewRevision());}}).add(new TooltipBehavior(new LoadableDetachableModel<String>() {@Overrideprotected String load() {- CommitDescription description = commitsModel.getObject().get(newCommit);+ CommitDescription description = commitsModel.getObject().get(change.getNewRevision());Preconditions.checkNotNull(description);return description.getSubject();}@@ -292,7 +377,7 @@ public class RequestComparePage extends RequestDetailPage {PageParameters params = paramsOf(getPullRequest(),getPullRequest().getBaseCommit(),getPullRequest().getLatestUpdate().getHeadCommit(),- filePath, getConcernedComment());+ change.getPath(), getConcernedComment());setResponsePage(RequestComparePage.class, params);}@@ -310,7 +395,7 @@ public class RequestComparePage extends RequestDetailPage {PageParameters params = paramsOf(getPullRequest(),getPullRequest().getLatestUpdate().getHeadCommit(),integrationInfo.getIntegrationHead(),- filePath, getConcernedComment());+ change.getPath(), getConcernedComment());setResponsePage(RequestComparePage.class, params);}@@ -332,8 +417,8 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected void onSelect() {- PageParameters params = paramsOf(getPullRequest(),- baseCommit, headCommit, filePath, getConcernedComment());+ PageParameters params = paramsOf(getPullRequest(), baseCommit, headCommit,+ change.getPath(), getConcernedComment());setResponsePage(RequestComparePage.class, params);}@@ -356,7 +441,6 @@ public class RequestComparePage extends RequestDetailPage {protected Component newContent(String id) {final Fragment fragment = new Fragment(id, "changesFrag", RequestComparePage.this);- Change change = getActiveChange();boolean changesOnly = (change == null || change.getStatus() != UNCHANGED);fragment.add(new CheckBox("changesOnly", Model.of(changesOnly)).add(new OnChangeAjaxBehavior() {@@ -383,7 +467,7 @@ public class RequestComparePage extends RequestDetailPage {@Overrideprotected String load() {- int index = getChangedFiles().indexOf(filePath);+ int index = getChangedFiles().indexOf(file);if (index == -1)return String.valueOf(getChanges().size());else@@ -397,7 +481,7 @@ public class RequestComparePage extends RequestDetailPage {@Overridepublic void onClick(AjaxRequestTarget target) {- int index = getChangedFiles().indexOf(filePath) - 1;+ int index = getChangedFiles().indexOf(file) - 1;onChangeSelected(target, getChanges().get(index));}@@ -405,7 +489,7 @@ public class RequestComparePage extends RequestDetailPage {protected void onComponentTag(ComponentTag tag) {super.onComponentTag(tag);- if (getChangedFiles().indexOf(filePath) <= 0)+ if (getChangedFiles().indexOf(file) <= 0)tag.put("disabled", "disabled");}@@ -415,7 +499,7 @@ public class RequestComparePage extends RequestDetailPage {@Overridepublic void onClick(AjaxRequestTarget target) {- int index = getChangedFiles().indexOf(filePath) + 1;+ int index = getChangedFiles().indexOf(file) + 1;onChangeSelected(target, getChanges().get(index));}@@ -424,15 +508,14 @@ public class RequestComparePage extends RequestDetailPage {super.onComponentTag(tag);List<String> changedFiles = getChangedFiles();- if (changedFiles.isEmpty() || changedFiles.indexOf(filePath) >= changedFiles.size()-1)+ if (changedFiles.isEmpty() || changedFiles.indexOf(file) >= changedFiles.size()-1)tag.put("disabled", "disabled");}}.setOutputMarkupId(true));- CommentAwareChange change = resolveChange();if (change != null) {- BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change);+ BlobDiffPanel blobDiffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, change, this);blobDiffPanel.setOutputMarkupId(true);add(blobDiffPanel);} else {@@ -452,73 +535,16 @@ public class RequestComparePage extends RequestDetailPage {return files;}- private CommentAwareChange resolveChange() {- CommentAwareChange change = null;- CommitComment comment = getConcernedComment();- if (oldCommit != null) {- if (filePath != null) {- change = resolveChange(filePath);- } else if (comment != null) {- filePath = comment.getPosition().getFilePath();- change = resolveChange(filePath);- }- } else if (comment == null) {- User user = GitPlex.getInstance(UserManager.class).getCurrent();- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();- if (user == null) {- oldCommit = getPullRequest().getBaseCommit();- } else {- List<PullRequestActivity> activities = activitiesModel.getObject();- boolean found = false;- for (int i=activities.size()-1; i>=0; i--) {- PullRequestActivity activity = activities.get(i);- if (found) {- if (activity instanceof UpdatePullRequest) {- oldCommit = ((UpdatePullRequest) activity).getUpdate().getHeadCommit();- break;- }- } else if (activity.getUser().equals(user)) {- found = true;- }- }- if (oldCommit == null || oldCommit.equals(newCommit))- oldCommit = getPullRequest().getBaseCommit();- }- } else {- filePath = comment.getPosition().getFilePath();- oldCommit = getPullRequest().getBaseCommit();- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();- change = resolveChange(filePath);- if (change == null || !change.contains(comment)) {- if (!comment.getCommit().equals(getPullRequest().getLatestUpdate().getHeadCommit())) {- oldCommit = comment.getCommit();- newCommit = getPullRequest().getLatestUpdate().getHeadCommit();- } else {- oldCommit = getPullRequest().getBaseCommit();- newCommit = comment.getCommit();- }- change = resolveChange(filePath);- }- }- if (change == null && !getChanges().isEmpty()) {- filePath = getChanges().get(0).getPath();- change = resolveChange(filePath);- Preconditions.checkNotNull(change);- }-- return change;- }-- private CommentAwareChange resolveChange(String filePath) {+ private RevAwareChange resolveChange() {for (Change each: getChanges()) {- if (filePath.equals(each.getPath()))- return loadComments(new RevAwareChange(each, oldCommit, newCommit));+ if (file.equals(each.getPath()))+ return new RevAwareChange(each, oldCommit, newCommit);}- List<TreeNode> result = getRepository().git().listTree(newCommit, filePath);+ List<TreeNode> result = getRepository().git().listTree(newCommit, file);if (!result.isEmpty() && result.get(0).getMode() != FileMode.TYPE_TREE) {TreeNode blobNode = result.get(0);- return loadComments(new RevAwareChange(UNCHANGED, filePath, filePath,- blobNode.getMode(), blobNode.getMode(), oldCommit, newCommit));+ return new RevAwareChange(UNCHANGED, file, file,+ blobNode.getMode(), blobNode.getMode(), oldCommit, newCommit);} else {return null;}@@ -546,9 +572,8 @@ public class RequestComparePage extends RequestDetailPage {protected void onInitialize() {super.onInitialize();- RevAwareChange activeChange = getActiveChange();- if (activeChange != null)- reveal(activeChange);+ if (change != null)+ reveal(change);}};@@ -557,26 +582,21 @@ public class RequestComparePage extends RequestDetailPage {return changeLister;}- @Nullable- private CommentAwareChange getActiveChange() {- Component panel = getPage().get(BLOB_DIFF_ID);- if (panel instanceof BlobDiffPanel)- return ((BlobDiffPanel) panel).getChange();- else- return null;- }-@Overridepublic void onDetach() {commitsModel.detach();concernedCommentModel.detach();activitiesModel.detach();+ changeCommentsModel.detach();+ oldCommentsModel.detach();+ newCommentsModel.detach();super.onDetach();}public static PageParameters paramsOf(PullRequest request, @Nullable String oldCommit,- @Nullable String newCommit, @Nullable String filePath, @Nullable CommitComment concernedComment) {+ @Nullable String newCommit, @Nullable String filePath,+ @Nullable PullRequestComment concernedComment) {PageParameters params = RequestDetailPage.paramsOf(request);if (oldCommit != null)@@ -591,52 +611,30 @@ public class RequestComparePage extends RequestDetailPage {return params;}- private CommentAwareChange loadComments(RevAwareChange change) {- BlobLoader blobLoader = new BlobLoader() {-- @Override- public List<String> loadBlob(BlobInfo blobInfo) {- BlobText blobText = repoModel.getObject().getBlobText(blobInfo);- return blobText!=null?blobText.getLines():null;- }-- };- CommentLoader commentLoader = new CommentLoader() {-- @Override- public List<CommitComment> loadComments(String commit) {- List<CommitComment> comments = getPullRequest().getCommitComments().get(commit);- if (comments == null)- return new ArrayList<>();- else- return comments;- }-- };-- return new CommentAwareChange(change, getPullRequest().getCommits(),- commentLoader, blobLoader, getConcernedComment());- }-@Overridepublic void onEvent(IEvent<?> event) {super.onEvent(event);- if (event.getPayload() instanceof CommitCommentRemoved) {- CommitCommentRemoved commitCommentRemoved = (CommitCommentRemoved) event.getPayload();- CommitComment comment = commitCommentRemoved.getComment();+ if (event.getPayload() instanceof CommentRemoved) {+ CommentRemoved commentRemoved = (CommentRemoved) event.getPayload();+ PullRequestComment comment = (PullRequestComment) commentRemoved.getComment();if (comment.equals(getConcernedComment())) {PageParameters params = paramsOf(getPullRequest(), oldCommit, newCommit,- comment.getPosition().getFilePath(), null);+ comment.getInlineInfo().getFile(), null);setResponsePage(RequestComparePage.class, params);}+ } else if (event.getPayload() instanceof CommentReplied) {+ CommentReplied commentReplied = (CommentReplied) event.getPayload();+ PullRequestComment comment = (PullRequestComment) commentReplied.getReply().getComment();+ if (oldCommit.equals(comment.getCommit()))+ comment.getInlineInfo().setCompareCommit(newCommit);+ else+ comment.getInlineInfo().setCompareCommit(oldCommit);+ comment.getInlineInfo().setContext(getBlobDiffPanel().getLineContext(comment));+ GitPlex.getInstance(Dao.class).persist(comment);}}- private CommitComment getConcernedComment() {- return concernedCommentModel.getObject();- }-private static class CommitDescription implements Serializable {private final String name;@@ -695,10 +693,10 @@ public class RequestComparePage extends RequestDetailPage {Map.Entry<String, CommitDescription> entry = item.getModelObject();if (forBase) {setResponsePage(RequestComparePage.class,- paramsOf(getPullRequest(), entry.getKey(), newCommit, filePath, getConcernedComment()));+ paramsOf(getPullRequest(), entry.getKey(), newCommit, file, getConcernedComment()));} else {setResponsePage(RequestComparePage.class,- paramsOf(getPullRequest(), oldCommit, entry.getKey(), filePath, getConcernedComment()));+ paramsOf(getPullRequest(), oldCommit, entry.getKey(), file, getConcernedComment()));}}@@ -745,10 +743,9 @@ public class RequestComparePage extends RequestDetailPage {protected void onComponentTag(ComponentTag tag) {super.onComponentTag(tag);- Change activeChange = getActiveChange();- if (activeChange != null- && Objects.equals(change.getOldPath(), activeChange.getOldPath())- && Objects.equals(change.getNewPath(), activeChange.getNewPath())) {+ if (change != null+ && Objects.equals(change.getOldPath(), change.getOldPath())+ && Objects.equals(change.getNewPath(), change.getNewPath())) {tag.put("class", "active");}}@@ -761,9 +758,9 @@ public class RequestComparePage extends RequestDetailPage {}private void onChangeSelected(AjaxRequestTarget target, Change change) {- filePath = change.getPath();- BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel,- loadComments(new RevAwareChange(change, oldCommit, newCommit)));+ file = change.getPath();+ this.change = new RevAwareChange(change, oldCommit, newCommit);+ BlobDiffPanel diffPanel = new BlobDiffPanel(BLOB_DIFF_ID, repoModel, this.change, this);getPage().replace(diffPanel);target.add(diffPanel);@@ -811,4 +808,46 @@ public class RequestComparePage extends RequestDetailPage {return fragment;}}++ @Override+ public Map<Integer, LineComment> getOldComments() {+ return oldCommentsModel.getObject();+ }++ @Override+ public Map<Integer, LineComment> getNewComments() {+ return newCommentsModel.getObject();+ }++ @Override+ public LineComment addComment(String commit, String file, int line, String content) {+ User user = GitPlex.getInstance(UserManager.class).getCurrent();+ Preconditions.checkNotNull(user);+ PullRequestComment comment = new PullRequestComment();+ comment.setUser(user);+ comment.setDate(new Date());+ comment.setContent(content);+ comment.setRequest(getPullRequest());+ InlineInfo inlineInfo = new InlineInfo();+ inlineInfo.setCommit(commit);+ inlineInfo.setFile(file);+ inlineInfo.setLine(line);+ if (commit.equals(oldCommit))+ inlineInfo.setCompareCommit(newCommit);+ else+ inlineInfo.setCompareCommit(oldCommit);+ inlineInfo.setContext(getBlobDiffPanel().getLineContext(comment));+ comment.setInlineInfo(inlineInfo);+ GitPlex.getInstance(Dao.class).persist(comment);+ return comment;+ }++ private BlobDiffPanel getBlobDiffPanel() {+ return (BlobDiffPanel) getPage().get(BLOB_DIFF_ID);+ }++ @Override+ public PullRequestComment getConcernedComment() {+ return concernedCommentModel.getObject();+ }}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.htmlindex 63991f2da3..3c6fca76e6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.html@@ -31,6 +31,7 @@</td></tr></table>+ <wicket:enclosure child="votes"><div class="votes clearfix"><wicket:container wicket:id="votes"><div class="vote pull-left">@@ -42,6 +43,7 @@</div></wicket:container></div>+ </wicket:enclosure></td></tr></table>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.javaindex 6bbed42617..8ec25c599d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java@@ -108,6 +108,13 @@ public class RequestUpdatesPage extends RequestDetailPage {elsevoteSpan.add(AttributeModifier.append("class", " disapproved"));}++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(!updateItem.getModelObject().getVotes().isEmpty());+ }});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/ActivitiesModel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/ActivitiesModel.javaindex 56ac673edc..a1e61dbcc6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/ActivitiesModel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/activity/ActivitiesModel.java@@ -29,7 +29,7 @@ public abstract class ActivitiesModel extends LoadableDetachableModel<List<PullRfor (PullRequestUpdate update: request.getUpdates())activities.add(new UpdatePullRequest(update));- for (PullRequestComment comment: request.getRequestComments())+ for (PullRequestComment comment: request.getComments())activities.add(new CommentPullRequest(comment));for (PullRequestAudit audit: request.getAudits()) {