From 4b1cf42dd5126b32ce5da7be668250ab5b63d067 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Tue, 9 Apr 2024 23:40:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20`hide=20profile?= =?UTF-8?q?`=20to=20`block=20profile`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- .../fihlon/apus/service/SocialService.java | 48 +++++++++---------- .../swiss/fihlon/apus/ui/view/SocialView.java | 4 +- .../vaadin-i18n/translations.properties | 4 +- .../vaadin-i18n/translations_de.properties | 4 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/swiss/fihlon/apus/service/SocialService.java b/src/main/java/swiss/fihlon/apus/service/SocialService.java index fdf4bb0..6f9cde9 100644 --- a/src/main/java/swiss/fihlon/apus/service/SocialService.java +++ b/src/main/java/swiss/fihlon/apus/service/SocialService.java @@ -52,8 +52,8 @@ public final class SocialService { private final boolean filterReplies; private final boolean filterSensitive; private final List filterWords; - private final Set manuallyHiddenId = new HashSet<>(); - private final Set manuallyHiddenProfile = new HashSet<>(); + private final Set hiddenMessages = new HashSet<>(); + private final Set blockedProfiles = new HashSet<>(); private List messages = List.of(); public SocialService(@NotNull final TaskScheduler taskScheduler, @@ -65,7 +65,7 @@ public SocialService(@NotNull final TaskScheduler taskScheduler, .map(filterWord -> filterWord.toLowerCase(DEFAULT_LOCALE).trim()) .toList(); loadHiddenMessageIds(); - loadHiddenProfiles(); + loadBlockedProfiles(); updateMessages(); updateScheduler = taskScheduler.scheduleAtFixedRate(this::updateMessages, UPDATE_FREQUENCY); } @@ -77,8 +77,8 @@ public void stopUpdateScheduler() { private void updateMessages() { final var newMessages = mastodonAPI.getMessages().stream() - .filter(message -> !manuallyHiddenId.contains(message.id())) - .filter(message -> !manuallyHiddenProfile.contains(message.profile())) + .filter(message -> !hiddenMessages.contains(message.id())) + .filter(message -> !blockedProfiles.contains(message.profile())) .filter(message -> !filterSensitive || !message.isSensitive()) .filter(message -> !filterReplies || !message.isReply()) .filter(this::checkWordFilter) @@ -112,7 +112,7 @@ public void hideMessage(@NotNull final Message message) { LOGGER.warn("Hiding message (id={}, profile={}, author={})", message.id(), message.profile(), message.author()); messages.remove(message); - manuallyHiddenId.add(message.id()); + hiddenMessages.add(message.id()); saveHiddenMessageIds(); } @@ -120,8 +120,8 @@ public void hideProfile(@NotNull final Message message) { LOGGER.warn("Hide profile (id={}, profile={}, author={})", message.id(), message.profile(), message.author()); messages.remove(message); - manuallyHiddenProfile.add(message.profile()); - saveHiddenProfiles(); + blockedProfiles.add(message.profile()); + saveBlockedProfiles(); } private Path getConfigDir() { @@ -137,46 +137,46 @@ private Path getConfigDir() { } private void saveHiddenMessageIds() { - final var filePath = getConfigDir().resolve("hiddenMessageIds"); + final var filePath = getConfigDir().resolve("hiddenMessages"); try { - Files.writeString(filePath, String.join("\n", manuallyHiddenId)); + Files.writeString(filePath, String.join("\n", hiddenMessages)); } catch (final IOException e) { - LOGGER.error("Unable to save hidden message IDs to file '{}': {}", filePath, e.getMessage()); + LOGGER.error("Unable to save hidden messages to file '{}': {}", filePath, e.getMessage()); } } - private void saveHiddenProfiles() { - final var filePath = getConfigDir().resolve("hiddenProfiles"); + private void saveBlockedProfiles() { + final var filePath = getConfigDir().resolve("blockedProfiles"); try { - Files.writeString(filePath, String.join("\n", manuallyHiddenProfile)); + Files.writeString(filePath, String.join("\n", blockedProfiles)); } catch (final IOException e) { - LOGGER.error("Unable to save hidden profiles to file '{}': {}", filePath, e.getMessage()); + LOGGER.error("Unable to save blocked profiles to file '{}': {}", filePath, e.getMessage()); } } private void loadHiddenMessageIds() { - final var filePath = getConfigDir().resolve("hiddenMessageIds"); + final var filePath = getConfigDir().resolve("hiddenMessages"); if (filePath.toFile().exists()) { try { - manuallyHiddenId.addAll(Files.readAllLines(filePath)); + hiddenMessages.addAll(Files.readAllLines(filePath)); } catch (IOException e) { - LOGGER.error("Unable to load hidden message IDs from file '{}': {}", filePath, e.getMessage()); + LOGGER.error("Unable to load hidden messages from file '{}': {}", filePath, e.getMessage()); } } else { - LOGGER.info("No previously saved hidden message IDs found."); + LOGGER.info("No previously saved hidden messages found."); } } - private void loadHiddenProfiles() { - final var filePath = getConfigDir().resolve("hiddenProfiles"); + private void loadBlockedProfiles() { + final var filePath = getConfigDir().resolve("blockedProfiles"); if (filePath.toFile().exists()) { try { - manuallyHiddenProfile.addAll(Files.readAllLines(filePath)); + blockedProfiles.addAll(Files.readAllLines(filePath)); } catch (IOException e) { - LOGGER.error("Unable to load hidden profiles from file '{}': {}", filePath, e.getMessage()); + LOGGER.error("Unable to load blocked profiles from file '{}': {}", filePath, e.getMessage()); } } else { - LOGGER.info("No previously saved hidden profiles found."); + LOGGER.info("No previously saved blocked profiles found."); } } } diff --git a/src/main/java/swiss/fihlon/apus/ui/view/SocialView.java b/src/main/java/swiss/fihlon/apus/ui/view/SocialView.java index a2637d3..949a639 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/SocialView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/SocialView.java @@ -133,7 +133,7 @@ private void updateMessages() { if (adminModeEnabled) { final var messageMenu = new ContextMenu(); messageMenu.addItem(getTranslation("social.message.contextmenu.hide.message"), event -> hideMessage(message)); - messageMenu.addItem(getTranslation("social.message.contextmenu.hide.profile"), event -> blockProfile(message)); + messageMenu.addItem(getTranslation("social.message.contextmenu.block.profile"), event -> blockProfile(message)); messageMenu.setTarget(messageView); } messageContainer.add(messageView); @@ -148,7 +148,7 @@ private void hideMessage(@NotNull final Message message) { private void blockProfile(@NotNull final Message message) { socialService.hideProfile(message); - Notification.show(getTranslation("social.message.contextmenu.hide.profile.done")); + Notification.show(getTranslation("social.message.contextmenu.block.profile.done")); updateMessages(); } } diff --git a/src/main/resources/vaadin-i18n/translations.properties b/src/main/resources/vaadin-i18n/translations.properties index 3bae801..79147b9 100644 --- a/src/main/resources/vaadin-i18n/translations.properties +++ b/src/main/resources/vaadin-i18n/translations.properties @@ -15,7 +15,7 @@ social.admin.login.rejected=Your authentication was not successful! social.admin.login.successful=You have administrative rights. social.admin.login.title=Authentification social.heading=Posts with #{0} on Mastodon +social.message.contextmenu.block.profile.done=All messages from this profile have been hidden. +social.message.contextmenu.block.profile=Hide this profile social.message.contextmenu.hide.message.done=The message was hidden as requested. social.message.contextmenu.hide.message=Hide this message -social.message.contextmenu.hide.profile.done=All messages from this profile have been hidden. -social.message.contextmenu.hide.profile=Hide this profile diff --git a/src/main/resources/vaadin-i18n/translations_de.properties b/src/main/resources/vaadin-i18n/translations_de.properties index 37bc7b3..706226d 100644 --- a/src/main/resources/vaadin-i18n/translations_de.properties +++ b/src/main/resources/vaadin-i18n/translations_de.properties @@ -15,7 +15,7 @@ social.admin.login.rejected=Du hast dich nicht erfolgreich authentifiziert! social.admin.login.successful=Du hast jetzt Administrationsrechte. social.admin.login.title=Authentifizierung social.heading=Schreibe einen Beitrag mit #{0} auf Mastodon +social.message.contextmenu.block.profile.done=Alle Beiträge dieses Profils wurden wie gewünscht blockiert. +social.message.contextmenu.block.profile=Dieses Profil blockieren social.message.contextmenu.hide.message.done=Der Beitrag wurde wie gewünscht ausgeblendet. social.message.contextmenu.hide.message=Diesen Beitrag ausblenden -social.message.contextmenu.hide.profile.done=Alle Beiträge dieses Profils wurden wie gewünscht ausgeblendet. -social.message.contextmenu.hide.profile=Dieses Profil ausblenden