diff --git a/README.md b/README.md index 3af8105..5e33b0f 100644 --- a/README.md +++ b/README.md @@ -89,17 +89,18 @@ You can now also attach breakpoints in code for debugging purposes, by clicking *Apus* can be started without any specific configuration. All configuration options have working default values. To modify these default values just specify environment variables with the following names: -| Variable | Default | Description | -|----------------------|------------------------------------|-----------------------------------------------------------------| -| ADMIN_PASSWORD | | The password to get admin access (empty = disabled). | -| DOAG_EVENT_ID | 0 | The ID of the DOAG event to read the conference agenda. | -| FILTER_REPLIES | true | Hide social media messages which are replies. | -| FILTER_SENSITIVE | true | Hide social media messages which contain sensitive information. | -| FILTER_WORDS | fuck you, motherfucker, cocksucker | Hide social media messages which contain these words. | -| MASTODON_INSTANCE | mastodon.social | The Mastodon instance used to read the posts from. | -| MASTODON_HASHTAG | java | The hashtag for the mastodon wall. | -| MASTODON_IMAGE_LIMIT | 1 | Limit number of images per post. | -| TZ | UTC | The timezone used for date and time calculations. | +| Variable | Default | Description | +|-------------------------|------------------------------------|-----------------------------------------------------------------| +| ADMIN_PASSWORD | | The password to get admin access (empty = disabled). | +| DOAG_EVENT_ID | 0 | The ID of the DOAG event to read the conference agenda. | +| FILTER_REPLIES | true | Hide social media messages which are replies. | +| FILTER_SENSITIVE | true | Hide social media messages which contain sensitive information. | +| FILTER_WORDS | fuck you, motherfucker, cocksucker | Hide social media messages which contain these words. | +| MASTODON_INSTANCE | mastodon.social | The Mastodon instance used to read the posts from. | +| MASTODON_HASHTAG | java | The hashtag for the mastodon wall. | +| MASTODON_IMAGES_ENABLED | true | Enable or disable images in mastodon posts. | +| MASTODON_IMAGE_LIMIT | 1 | Limit number of images per post. | +| TZ | UTC | The timezone used for date and time calculations. | The environment variables will override the default values. diff --git a/src/main/java/swiss/fihlon/apus/configuration/Mastodon.java b/src/main/java/swiss/fihlon/apus/configuration/Mastodon.java index e436b85..becb55e 100644 --- a/src/main/java/swiss/fihlon/apus/configuration/Mastodon.java +++ b/src/main/java/swiss/fihlon/apus/configuration/Mastodon.java @@ -17,4 +17,4 @@ */ package swiss.fihlon.apus.configuration; -public record Mastodon(String instance, String hashtag, int imageLimit) { } +public record Mastodon(String instance, String hashtag, boolean imagesEnabled, int imageLimit) { } diff --git a/src/main/java/swiss/fihlon/apus/social/mastodon/MastodonAPI.java b/src/main/java/swiss/fihlon/apus/social/mastodon/MastodonAPI.java index dc53da0..d7e2971 100644 --- a/src/main/java/swiss/fihlon/apus/social/mastodon/MastodonAPI.java +++ b/src/main/java/swiss/fihlon/apus/social/mastodon/MastodonAPI.java @@ -43,12 +43,14 @@ public final class MastodonAPI { private final String instance; private final String hashtag; + private final boolean imagesEnabled; private final int imageLimit; public MastodonAPI(@NotNull final Configuration configuration) { final var mastodonConfig = configuration.getMastodon(); this.instance = mastodonConfig.instance(); this.hashtag = mastodonConfig.hashtag(); + this.imagesEnabled = mastodonConfig.imagesEnabled(); this.imageLimit = mastodonConfig.imageLimit(); } @@ -81,7 +83,7 @@ private Message convertToMessage(@NotNull final Status status) { final String avatar = account == null ? "" : account.getAvatar(); final String profile = account == null ? "" : getProfile(account); final String html = status.getContent(); - final List images = getImages(status.getMediaAttachments()); + final List images = imagesEnabled ? getImages(status.getMediaAttachments()) : List.of(); final String inReplyToId = status.getInReplyToId(); final boolean isReply = inReplyToId != null && !inReplyToId.isBlank(); final boolean isSensitive = status.isSensitive(); diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 97ce02c..059acc0 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -15,6 +15,11 @@ "type": "java.lang.String", "description": "The hashtag for the Mastodon wall." }, + { + "name": "apus.mastodon.imagesEnabled", + "type": "java.lang.Boolean", + "description": "Enable or disable images in mastodon posts." + }, { "name": "apus.mastodon.imageLimit", "type": "java.lang.Integer", diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 728227f..9bd5c9f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,6 +13,7 @@ apus.admin.password=${ADMIN_PASSWORD:} apus.doag.eventId=${DOAG_EVENT_ID:0} apus.mastodon.instance=${MASTODON_INSTANCE:mastodon.social} apus.mastodon.hashtag=${MASTODON_HASHTAG:java} +apus.mastodon.imagesEnabled=${MASTODON_IMAGES_ENABLED:true} apus.mastodon.imageLimit=${MASTODON_IMAGE_LIMIT:1} apus.filter.replies=${FILTER_REPLIES:true} apus.filter.sensitive=${FILTER_SENSITIVE:true}