ChangeScreen2: Respect comment visibility strategy
Bug: Issue 2456 Change-Id: I71f9ae2664a8f8c7f4eb8e019696764982781f58
This commit is contained in:
		
				
					committed by
					
						
						David Pursehouse
					
				
			
			
				
	
			
			
			
						parent
						
							9c8791c8a5
						
					
				
				
					commit
					fc5a2b8ef4
				
			@@ -747,7 +747,7 @@ public class ChangeScreen2 extends Screen {
 | 
				
			|||||||
    related.set(info, revision);
 | 
					    related.set(info, revision);
 | 
				
			||||||
    reviewers.set(info);
 | 
					    reviewers.set(info);
 | 
				
			||||||
    quickApprove.set(info, revision);
 | 
					    quickApprove.set(info, revision);
 | 
				
			||||||
    history.set(commentLinkProcessor, changeId, info);
 | 
					    history.set(commentLinkProcessor, changeId, info, expandAll, collapseAll);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (Gerrit.isSignedIn()) {
 | 
					    if (Gerrit.isSignedIn()) {
 | 
				
			||||||
      initEditMessageAction(info, revision);
 | 
					      initEditMessageAction(info, revision);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.client.change;
 | 
					package com.google.gerrit.client.change;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy.COLLAPSE_ALL;
 | 
				
			||||||
 | 
					import static com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy.EXPAND_ALL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gerrit.client.Gerrit;
 | 
				
			||||||
import com.google.gerrit.client.account.AccountInfo;
 | 
					import com.google.gerrit.client.account.AccountInfo;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeApi;
 | 
					import com.google.gerrit.client.changes.ChangeApi;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo;
 | 
					import com.google.gerrit.client.changes.ChangeInfo;
 | 
				
			||||||
@@ -22,10 +26,12 @@ import com.google.gerrit.client.changes.CommentInfo;
 | 
				
			|||||||
import com.google.gerrit.client.rpc.NativeMap;
 | 
					import com.google.gerrit.client.rpc.NativeMap;
 | 
				
			||||||
import com.google.gerrit.client.rpc.Natives;
 | 
					import com.google.gerrit.client.rpc.Natives;
 | 
				
			||||||
import com.google.gerrit.client.ui.CommentLinkProcessor;
 | 
					import com.google.gerrit.client.ui.CommentLinkProcessor;
 | 
				
			||||||
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.CommentVisibilityStrategy;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.Change;
 | 
					import com.google.gerrit.reviewdb.client.Change;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.PatchSet;
 | 
					import com.google.gerrit.reviewdb.client.PatchSet;
 | 
				
			||||||
import com.google.gwt.core.client.JsArray;
 | 
					import com.google.gwt.core.client.JsArray;
 | 
				
			||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
					import com.google.gwt.user.client.rpc.AsyncCallback;
 | 
				
			||||||
 | 
					import com.google.gwt.user.client.ui.Button;
 | 
				
			||||||
import com.google.gwt.user.client.ui.FlowPanel;
 | 
					import com.google.gwt.user.client.ui.FlowPanel;
 | 
				
			||||||
import com.google.gwt.user.client.ui.Widget;
 | 
					import com.google.gwt.user.client.ui.Widget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,6 +45,10 @@ import java.util.Map;
 | 
				
			|||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class History extends FlowPanel {
 | 
					class History extends FlowPanel {
 | 
				
			||||||
 | 
					  // This basically means 7 days in milliseconds and could be rewritten as
 | 
				
			||||||
 | 
					  // TimeUnit.DAYS.toMillis(7)
 | 
				
			||||||
 | 
					  // in plain Java, but unfortunately it isn't available in GWT
 | 
				
			||||||
 | 
					  private final static long AGE = 7 * 24 * 60 * 60 * 1000L;
 | 
				
			||||||
  private CommentLinkProcessor clp;
 | 
					  private CommentLinkProcessor clp;
 | 
				
			||||||
  private Change.Id changeId;
 | 
					  private Change.Id changeId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,7 +56,8 @@ class History extends FlowPanel {
 | 
				
			|||||||
  private final Map<AuthorRevision, List<CommentInfo>> byAuthor =
 | 
					  private final Map<AuthorRevision, List<CommentInfo>> byAuthor =
 | 
				
			||||||
      new HashMap<AuthorRevision, List<CommentInfo>>();
 | 
					      new HashMap<AuthorRevision, List<CommentInfo>>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void set(CommentLinkProcessor clp, Change.Id id, ChangeInfo info) {
 | 
					  void set(CommentLinkProcessor clp, Change.Id id, ChangeInfo info,
 | 
				
			||||||
 | 
					      Button expandAll, Button collapseAll) {
 | 
				
			||||||
    this.clp = clp;
 | 
					    this.clp = clp;
 | 
				
			||||||
    this.changeId = id;
 | 
					    this.changeId = id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -60,6 +71,7 @@ class History extends FlowPanel {
 | 
				
			|||||||
        add(ui);
 | 
					        add(ui);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    initCommentVisibilityStrategy(expandAll, collapseAll);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CommentLinkProcessor getCommentLinkProcessor() {
 | 
					  CommentLinkProcessor getCommentLinkProcessor() {
 | 
				
			||||||
@@ -149,6 +161,51 @@ class History extends FlowPanel {
 | 
				
			|||||||
    return match;
 | 
					    return match;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private void initCommentVisibilityStrategy(Button expandAll, Button collapseAll) {
 | 
				
			||||||
 | 
					    CommentVisibilityStrategy commentVisibilityStrategy =
 | 
				
			||||||
 | 
					        CommentVisibilityStrategy.EXPAND_RECENT;
 | 
				
			||||||
 | 
					    if (Gerrit.isSignedIn()) {
 | 
				
			||||||
 | 
					      commentVisibilityStrategy = Gerrit.getUserAccount()
 | 
				
			||||||
 | 
					          .getGeneralPreferences().getCommentVisibilityStrategy();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Timestamp aged = new Timestamp(System.currentTimeMillis() - AGE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int n = getWidgetCount();
 | 
				
			||||||
 | 
					    for (int i = 0; i < n; i++) {
 | 
				
			||||||
 | 
					      Message msg = (Message) getWidget(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      boolean isRecent = (i == n - 1)
 | 
				
			||||||
 | 
					          ? true
 | 
				
			||||||
 | 
					          : msg.getMessageInfo().date().after(aged);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      boolean isOpen = false;
 | 
				
			||||||
 | 
					      switch (commentVisibilityStrategy) {
 | 
				
			||||||
 | 
					        case COLLAPSE_ALL:
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case EXPAND_ALL:
 | 
				
			||||||
 | 
					          isOpen = true;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case EXPAND_MOST_RECENT:
 | 
				
			||||||
 | 
					          isOpen = i == n - 1;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case EXPAND_RECENT:
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					          isOpen = isRecent;
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      msg.setOpen(isOpen);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (commentVisibilityStrategy == COLLAPSE_ALL) {
 | 
				
			||||||
 | 
					      expandAll.setVisible(true);
 | 
				
			||||||
 | 
					      collapseAll.setVisible(false);
 | 
				
			||||||
 | 
					    } else if (commentVisibilityStrategy == EXPAND_ALL) {
 | 
				
			||||||
 | 
					      expandAll.setVisible(false);
 | 
				
			||||||
 | 
					      collapseAll.setVisible(true);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static final class AuthorRevision {
 | 
					  private static final class AuthorRevision {
 | 
				
			||||||
    final int author;
 | 
					    final int author;
 | 
				
			||||||
    final int revision;
 | 
					    final int revision;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user