Skip to content

Commit

Permalink
♻️ refactor to check for enabled plugins #58
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Apr 18, 2024
1 parent 5f28ebe commit 05c31c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ public final class ConferenceService {
private static final Duration UPDATE_FREQUENCY = Duration.ofMinutes(5);
private static final Logger LOGGER = LoggerFactory.getLogger(ConferenceService.class);

private final Configuration configuration;
private final ConferencePlugin conferencePlugin;
private final ScheduledFuture<?> updateScheduler;
private Map<Room, List<Session>> roomsWithSessions = new TreeMap<>();

public ConferenceService(@NotNull final TaskScheduler taskScheduler,
@NotNull final Configuration configuration) {
this.configuration = configuration;
updateSessions();
updateScheduler = taskScheduler.scheduleAtFixedRate(this::updateSessions, UPDATE_FREQUENCY);
conferencePlugin = new DoagPlugin(configuration);
if (conferencePlugin.isEnabled()) {
updateSessions();
updateScheduler = taskScheduler.scheduleAtFixedRate(this::updateSessions, UPDATE_FREQUENCY);
} else {
LOGGER.warn("No conference plugin is enabled. No agenda will be displayed.");
updateScheduler = null;
}
}

@PreDestroy
Expand All @@ -61,7 +66,7 @@ public void stopUpdateScheduler() {

private void updateSessions() {
try {
final var sessions = new DoagPlugin(configuration).getSessions().stream()
final var sessions = conferencePlugin.getSessions().stream()
.sorted()
.toList();

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/swiss/fihlon/apus/plugin/social/SocialService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class SocialService {
private static final Logger LOGGER = LoggerFactory.getLogger(SocialService.class);

private final ScheduledFuture<?> updateScheduler;
private final MastodonPlugin mastodonPlugin;
private final SocialPlugin socialPlugin;
private final int filterLength;
private final boolean filterReplies;
private final boolean filterSensitive;
Expand All @@ -60,7 +60,7 @@ public final class SocialService {

public SocialService(@NotNull final TaskScheduler taskScheduler,
@NotNull final Configuration configuration) {
mastodonPlugin = new MastodonPlugin(configuration);
socialPlugin = new MastodonPlugin(configuration);
filterLength = configuration.getFilter().length();
filterReplies = configuration.getFilter().replies();
filterSensitive = configuration.getFilter().sensitive();
Expand All @@ -69,8 +69,13 @@ public SocialService(@NotNull final TaskScheduler taskScheduler,
.toList();
loadHiddenMessageIds();
loadBlockedProfiles();
updateMessages();
updateScheduler = taskScheduler.scheduleAtFixedRate(this::updateMessages, UPDATE_FREQUENCY);
if (socialPlugin.isEnabled()) {
updateMessages();
updateScheduler = taskScheduler.scheduleAtFixedRate(this::updateMessages, UPDATE_FREQUENCY);
} else {
LOGGER.warn("No social plugin is enabled. No posts will be displayed.");
updateScheduler = null;
}
}

@PreDestroy
Expand All @@ -79,7 +84,7 @@ public void stopUpdateScheduler() {
}

private void updateMessages() {
final var newMessages = mastodonPlugin.getMessages().stream()
final var newMessages = socialPlugin.getMessages().stream()
.filter(message -> !hiddenMessages.contains(message.id()))
.filter(message -> !blockedProfiles.contains(message.profile()))
.filter(message -> !filterSensitive || !message.isSensitive())
Expand Down

0 comments on commit 05c31c1

Please sign in to comment.