StarredChangesUtil: Add isIgnored(ChangeResource) method

Add a new method that checks if the given change is ignored by the
calling user in the ChangeResource. This simplifies the usage from
the Ignore and Unignore endpoints which no longer need to explicitly
pass the "self" parameter.

Change-Id: I659eea1bc2cd5e54c74279187090b76b9e30be9e
This commit is contained in:
David Pursehouse
2017-09-16 16:33:10 +09:00
parent f710cbf25c
commit 247e36b4fe
3 changed files with 8 additions and 12 deletions

View File

@@ -319,6 +319,10 @@ public class StarredChangesUtil {
return getLabels(accountId, changeId).contains(IGNORE_LABEL);
}
public boolean isIgnored(ChangeResource rsrc) throws OrmException {
return isIgnoredBy(rsrc.getChange().getId(), rsrc.getUser().asIdentifiedUser().getAccountId());
}
private static String getMuteLabel(Change change) {
return MUTE_LABEL + "/" + change.currentPatchSetId().get();
}

View File

@@ -18,11 +18,9 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,12 +32,10 @@ public class Ignore
public static class Input {}
private final Provider<IdentifiedUser> self;
private final StarredChangesUtil stars;
@Inject
Ignore(Provider<IdentifiedUser> self, StarredChangesUtil stars) {
this.self = self;
Ignore(StarredChangesUtil stars) {
this.stars = stars;
}
@@ -70,7 +66,7 @@ public class Ignore
private boolean isIgnored(ChangeResource rsrc) {
try {
return stars.isIgnoredBy(rsrc.getChange().getId(), self.get().getAccountId());
return stars.isIgnored(rsrc);
} catch (OrmException e) {
log.error("failed to check ignored star", e);
}

View File

@@ -18,11 +18,9 @@ import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,12 +32,10 @@ public class Unignore
public static class Input {}
private final Provider<IdentifiedUser> self;
private final StarredChangesUtil stars;
@Inject
Unignore(Provider<IdentifiedUser> self, StarredChangesUtil stars) {
this.self = self;
Unignore(StarredChangesUtil stars) {
this.stars = stars;
}
@@ -70,7 +66,7 @@ public class Unignore
private boolean isIgnored(ChangeResource rsrc) {
try {
return stars.isIgnoredBy(rsrc.getChange().getId(), self.get().getAccountId());
return stars.isIgnored(rsrc);
} catch (OrmException e) {
log.error("failed to check ignored star", e);
}