Skip to content

Commit

Permalink
XWIKI-19751: Move the "watch" button for a page to the page content menu
Browse files Browse the repository at this point in the history
  * Fix checkstyle
  • Loading branch information
surli committed May 22, 2024
1 parent d5d126e commit 33d607e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@
<suppressions>
<suppress checks="CyclomaticComplexity" files="ScopeNotificationFilterPreferencesGetter.java"/>
<suppress checks="CyclomaticComplexity" files="DefaultNotificationFilterManager.java"/>

<!-- FIXME -->
<suppress checks="CyclomaticComplexity" files="ScopeNotificationFilter.java"/>
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public FilterPolicy filterEvent(Event event, DocumentReference user,
final EntityReference eventEntity = getEventEntity(event);
FilterPolicy result = FilterPolicy.NO_EFFECT;
if (eventEntity != null) {

// We don't check the inclusive filters if the target is specified since it means the notification already
// targets an user. We still check the exclusive one in case the user would want to avoid spam.
boolean checkInclusiveFilters = event.getTarget() == null || event.getTarget().isEmpty();
Expand All @@ -88,27 +87,35 @@ public FilterPolicy filterEvent(Event event, DocumentReference user,
WatchedLocationState state = stateComputer.isLocationWatched(filterPreferences, eventEntity,
event.getType(), format, false, checkInclusiveFilters, false);

switch (state.getState()) {
case BLOCKED, BLOCKED_BY_ANCESTOR, BLOCKED_WITH_CHILDREN -> {
if (state.getStartingDate() != null && state.getStartingDate().before(event.getDate())) {
result = FilterPolicy.FILTER;
}
result = getFilterPolicy(event, user, state, checkInclusiveFilters);
}
return result;
}

private FilterPolicy getFilterPolicy(Event event, DocumentReference user, WatchedLocationState state,
boolean checkInclusiveFilters)
{
FilterPolicy result = FilterPolicy.NO_EFFECT;
switch (state.getState()) {
case BLOCKED, BLOCKED_BY_ANCESTOR, BLOCKED_WITH_CHILDREN -> {
if (state.getStartingDate() != null && state.getStartingDate().before(event.getDate())) {
result = FilterPolicy.FILTER;
}
}

case WATCHED, WATCHED_BY_ANCESTOR, WATCHED_WITH_CHILDREN -> {
if (state.getStartingDate() != null && state.getStartingDate().after(event.getDate())) {
result = FilterPolicy.FILTER;
}
case WATCHED, WATCHED_BY_ANCESTOR, WATCHED_WITH_CHILDREN -> {
if (state.getStartingDate() != null && state.getStartingDate().after(event.getDate())) {
result = FilterPolicy.FILTER;
}
}

case CUSTOM ->
this.logger.error("Filtering of event should never return custom. Event: [{}]. User: [{}] ",
event, user);
case CUSTOM ->
this.logger.error("Filtering of event should never return custom. Event: [{}]. User: [{}] ",
event, user);

default -> {
if (checkInclusiveFilters) {
result = FilterPolicy.FILTER;
}
default -> {
if (checkInclusiveFilters) {
result = FilterPolicy.FILTER;
}
}
}
Expand Down

0 comments on commit 33d607e

Please sign in to comment.