From 05c31c1d9569486a21f299fa800dc544835fc756 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Thu, 18 Apr 2024 08:35:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20to=20check=20fo?= =?UTF-8?q?r=20enabled=20plugins=20#58?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apus/plugin/conference/ConferenceService.java | 15 ++++++++++----- .../fihlon/apus/plugin/social/SocialService.java | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/swiss/fihlon/apus/plugin/conference/ConferenceService.java b/src/main/java/swiss/fihlon/apus/plugin/conference/ConferenceService.java index 7ebfc1e..629e19f 100644 --- a/src/main/java/swiss/fihlon/apus/plugin/conference/ConferenceService.java +++ b/src/main/java/swiss/fihlon/apus/plugin/conference/ConferenceService.java @@ -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> 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 @@ -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(); diff --git a/src/main/java/swiss/fihlon/apus/plugin/social/SocialService.java b/src/main/java/swiss/fihlon/apus/plugin/social/SocialService.java index 7628f49..952d80c 100644 --- a/src/main/java/swiss/fihlon/apus/plugin/social/SocialService.java +++ b/src/main/java/swiss/fihlon/apus/plugin/social/SocialService.java @@ -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; @@ -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(); @@ -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 @@ -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())